]> granicus.if.org Git - transmission/commitdiff
add more rpc unit tests. man page cleanups.
authorCharles Kerr <charles@transmissionbt.com>
Mon, 21 Jul 2008 16:11:47 +0000 (16:11 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 21 Jul 2008 16:11:47 +0000 (16:11 +0000)
daemon/transmission-daemon.1
daemon/transmission-remote.1
gtk/transmission.1
libtransmission/rpc-test.c
libtransmission/rpc.c

index 61a384654c2a81d59d5dc7f7e396983276fc0108..edfb955ccc9c4b93eaa290182d26cbbf03cf3c49 100644 (file)
@@ -1,4 +1,4 @@
-.Dd May 19, 2008
+.Dd July 21, 2008
 .Dt TRANSMISSION-DAEMON 1
 
 .Sh NAME
 .Fl h
 .Nm
 .Op Fl a Ar (+|-)x.x.x.x[/x],...
-.Op Fl b
-.Op Fl B
+.Op Fl b | B
 .Op Fl f
 .Op Fl g Ar directory
 .Op Fl h
 .Op Fl p Ar port
-.Op Fl t
-.Op Fl T
+.Op Fl t | T
 .Op Fl u Ar username
 .Op Fl v Ar password
 .Op Fl w Ar download-dir
 .Sh DESCRIPTION
 .Nm
 is a daemon-based Transmission session that can be controlled
-via RPC commands from
-.Xr transmission-remote 1
-or
-.Xr Clutch 1 .
-.Pp
-The options are as follows:
+via RPC commands from transmission's web interface or
+.Xr transmission-remote 1 .
+
+.Sh OPTIONS
 .Bl -tag -width Ds
 
 .It Fl a Fl -acl Ar (+|-)x.x.x.x[/x],...
index ecbdbfe1c8ed4bc57ca06a7e72fe5b926294ef14..a8183bff5f82d4f4e2510466a92a805d03ae8582 100644 (file)
@@ -1,4 +1,4 @@
-.Dd May 20, 2008
+.Dd July 21, 2008
 .Dt TRANSMISSION-REMOTE 1
 .Os
 .Sh NAME
@@ -13,34 +13,27 @@ and
 .Op Ar host:port | host | port
 .Op Fl a Ar torrent-files
 .Op Fl b
-.Op Fl d Ar number
-.Op Fl D
-.Op Fl er
-.Op Fl ep
-.Op Fl et
+.Op Fl d Ar number | Fl D
+.Op Fl er | ep | et
 .Op Fl f
 .Op Fl g Ar files
 .Op Fl G Ar files
 .Op Fl h
 .Op Fl i
 .Op Fl l
-.Op Fl m
-.Op Fl M
+.Op Fl m | M
 .Op Fl n Ar user:pass
 .Op Fl p Ar port
 .Op Fl ph Ar files
 .Op Fl pl Ar files
 .Op Fl pn Ar files
 .Op Fl r
-.Op Fl s
-.Op Fl S
+.Op Fl s | S
 .Op Fl t Ar all | Ar id | Ar hash
-.Op Fl u Ar number
-.Op Fl U
+.Op Fl u Ar number | Fl U
 .Op Fl v
 .Op Fl w Ar download-dir
-.Op Fl x
-.Op Fl X
+.Op Fl x | X
 .Ek
 .Sh DESCRIPTION
 .Nm
@@ -53,12 +46,13 @@ By default,
 .Nm
 connects to the transmission session at localhost:9091.
 Other sessions can be controlled by specifying a different host and/or port.
-.Pp
-The options are as follows:
+
+.Sh OPTIONS
 .Bl -tag -width Ds
-.It Fl a Fl -add Ar torrent-file
-Add metainfo
-.Ar torrent-file(s) .
+.It Fl a Fl -add Ar torrent-file(s)
+Add
+.Ar torrent-file(s)
+into transmission.
 
 .It Fl b Fl -debug
 Enable debugging mode.
@@ -81,15 +75,18 @@ Prefer unencrypted peer connections.
 .It Fl f Fl -files
 Get a file list for the current torrent(s)
 
-.It Fl g Fl -get Ar files
+.It Fl g Fl -get Ar all | file-index | files
 Mark file(s) for download.
-.Ar files
-can be a file index, or a comma-separated list of file indices, or the literal
 .Ar all
-for all files in the torrent.
+marks all all of the torrent's files for downloading,
+.Ar file-index
+adds a single file to the download list, and
+.Ar files
+adds multiple files to the download list,
+such as "-g1,3-5" to add files #1, #3, #4, and #5 to the download list.
 
-.It Fl g Fl -no-get Ar files
-Mark file(s) for not downloading
+.It Fl G Fl -no-get Ar all | file-index | files
+Mark file(s) for not downloading.
 
 .It Fl h Fl -help
 Print command-line option descriptions.
@@ -117,24 +114,21 @@ Set the
 .Ar port
 for use when listening for incoming peer connections
 
-.It Fl ph Fl -priority-high Ar files
-Mark 
-.Ar files
-as high priority.
-.Ar files
-can be a file index, or a comma-separated list of file indices, or the literal
+.It Fl pn Fl -priority-normal Ar all | file-index | files
+Mark file(s) as normal priority.
 .Ar all
-for all files in the torrent.
-
-.It Fl pl Fl -priority-low Ar files
-Mark 
+marks all of the torrent's files as normal priority,
+.Ar file-index
+sets a single file's priority as normal, and
 .Ar files
-as low priority
+sets multiple files' priorities as normal,
+such as "-pn1,3-5" to normalize files #1, #3, #4, and #5.
 
-.It Fl pn Fl -priority-normal Ar files
-Mark 
-.Ar files
-as normal priority
+.It Fl ph Fl -priority-high Ar all | file-index | files
+Mark file(s) as high priority.
+
+.It Fl pl Fl -priority-low Ar all | file-index | files
+Mark file(s) as low priority.
 
 .It Fl r Fl -remove
 Remove the current torrent(s).  This does not delete the downloaded data.
@@ -152,8 +146,8 @@ will apply following requests to all torrents, while specific torrents can be ch
 .Ar id
 or
 .Ar hash .
-To set more than one current torrent, joined their ids or hashes together in a comma-delimited list,
-such as "-t1,2,3"
+To set more than one current torrent, join their ids or hashes together in a list,
+such as "-t2,4,6-8" to operate on the torrents whose IDs are 2, 4, 6, 7, and 8.
 
 .It Fl u Fl -uplimit Ar limit
 Limit the upload speed to
@@ -178,6 +172,12 @@ Disable peer exchange (PEX).
 .El
 .Sh EXAMPLES
 
+Set download and upload limits to 100 KiB/sec and 20 KiB/sec:
+.Bd -literal -offset indent
+$ transmission-remote -d100 -u20
+$ transmission-remote --downlimit=100 --uplimit=20
+.Ed
+
 List all torrents' IDs and states:
 .Bd -literal -offset indent
 $ transmission-remote -l
@@ -208,6 +208,11 @@ Get detailed information on the torrent whose ID is '1':
 $ transmission-remote -t1 -i"
 .Ed
 
+Get a list of a torrent's files:
+.Bd -literal -offset indent
+$ transmission-remote -t1 -l"
+.Ed
+
 Download only its second and fourth files:
 .Bd -literal -offset indent
 $ transmission-remote -t1 -Gall -g2,4"
@@ -223,12 +228,6 @@ Set all torrents' files' priorities to normal:
 $ transmission-remote -tall -pnall"
 .Ed
 
-Set download and upload limits to 100 KiB/sec and 20 KiB/sec:
-.Bd -literal -offset indent
-$ transmission-remote -d100 -u20
-$ transmission-remote --downlimit=100 --uplimit=20
-.Bd -literal -offset indent
-
 .Sh AUTHORS
 .An -nosplit
 .An Charles Kerr ,
index 626eebe81f0d1a9ebc562dd6bf6c252f5380dd4a..87a50c3250f79f8f6fabcca226642d9f967f8d04 100644 (file)
@@ -40,8 +40,7 @@ BitTorrent is a peer-to-peer file transfer protocol which uses a
 metainfo file (usually with the .torrent file extension) and a central
 tracker to distribute file data amongst a group of peers.  For more
 information on the BitTorrent protocol see http://www.bittorrent.org/
-.Pp
-The options are as follows:
+.Sh OPTIONS
 .Bl -tag -width Ds
 .It Fl ? Fl -help
 Show help options
index 55899f75df5fccaa4c72c3cafa215cb0de12e76b..0ef8afdcf7ad9cd587f273732d14708490d78e50 100644 (file)
@@ -1,6 +1,8 @@
 #include <stdio.h> /* fprintf */
 #include <string.h> /* strcmp */
 #include "transmission.h"
+#include "bencode.h"
+#include "rpc.h"
 #include "utils.h"
 
 #define VERBOSE 0
@@ -30,7 +32,7 @@ testWildcard( const char * in, const char * expected )
 {
     int ok;
     char * str = cidrize( in );
-/* fprintf( stderr, "in [%s] out [%s] should be [%s]\n", in, str, expected ); */
+/* fprintf( stderr, "in [%s] out [%s] expected [%s]\n", in, str, expected ); */
     ok = expected ? !strcmp( expected, str ) : !str;
     tr_free( str );
     return ok;
@@ -46,7 +48,8 @@ test_acl( void )
     check( testWildcard( "192.64.*.*", "192.64.0.0/16" ) );
     check( testWildcard( "192.64.0.*", "192.64.0.0/24" ) );
     check( testWildcard( "192.64.0.1", "192.64.0.1/32" ) );
-    check( testWildcard( "+192.*.*.*,-192.64.*.*", "+192.0.0.0/8,-192.64.0.0/16" ) );
+    check( testWildcard( "+192.*.*.*,-192.64.*.*",
+                         "+192.0.0.0/8,-192.64.0.0/16" ) );
 
     err = tr_rpcTestACL( NULL, "+192.*.*.*", &errmsg );
     check( !err );
@@ -63,6 +66,56 @@ test_acl( void )
     return 0;
 }
 
+static int
+test_list( void )
+{
+    int64_t i;
+    const char * str;
+    tr_benc top;
+
+    tr_rpc_parse_list_str( &top, "12", -1 );
+    check( tr_bencIsInt( &top ) );
+    check( tr_bencGetInt( &top, &i ) );
+    check( i == 12 );
+    tr_bencFree( &top );
+
+    tr_rpc_parse_list_str( &top, "12", 1 );
+    check( tr_bencIsInt( &top ) );
+    check( tr_bencGetInt( &top, &i ) );
+    check( i == 1 );
+    tr_bencFree( &top );
+
+    tr_rpc_parse_list_str( &top, "6,7", -1 );
+    check( tr_bencIsList( &top ) );
+    check( tr_bencListSize( &top ) == 2 );
+    check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) );
+    check( i == 6 );
+    check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) );
+    check( i == 7 );
+    tr_bencFree( &top );
+
+    tr_rpc_parse_list_str( &top, "asdf", -1 );
+    check( tr_bencIsString( &top ) );
+    check( tr_bencGetStr( &top, &str ) );
+    check( !strcmp( str, "asdf" ) );
+    tr_bencFree( &top );
+
+    tr_rpc_parse_list_str( &top, "1,3-5", -1 );
+    check( tr_bencIsList( &top ) );
+    check( tr_bencListSize( &top ) == 4 );
+    check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) );
+    check( i == 1 );
+    check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) );
+    check( i == 3 );
+    check( tr_bencGetInt( tr_bencListChild( &top, 2 ), &i ) );
+    check( i == 4 );
+    check( tr_bencGetInt( tr_bencListChild( &top, 3 ), &i ) );
+    check( i == 5 );
+    tr_bencFree( &top );
+
+    return 0;
+}
+
 int
 main( void )
 {
@@ -70,6 +123,8 @@ main( void )
 
     if(( i = test_acl( )))
         return i;
+    if(( i = test_list( )))
+        return i;
 
     return 0;
 }
index 5d5ab311d8b717f53da7dc4d774fcc92aa31ce8a..9a9b603dc2dca0631a3088e6ce1c5b2f9b703c9f 100644 (file)
@@ -673,6 +673,24 @@ tr_rpc_request_exec_json( struct tr_handle  * handle,
     return ret;
 }
 
+static void
+addToken( tr_benc * list, const char * token, size_t len )
+{
+    char * p;
+    const char * end = token + len;
+    const long a = strtol( token, &p, 10 );
+    if( p == end )
+        tr_bencListAddInt( list, a );
+    else if( *p == '-' && isdigit(p[1]) ) {
+        const long b = strtol( p+1, &p, 10 );
+        if( ( p == end ) && ( b > a ) ) {
+            long i;
+            for( i=a; i<=b; ++i )
+                tr_bencListAddInt( list, i );
+        }
+    }
+}
+
 /**
  * Munge the URI into a usable form.
  *
@@ -712,8 +730,10 @@ tr_rpc_parse_list_str( tr_benc     * setme,
         tr_bencInitList( setme, commaCount + 1 );
         walk = str;
         while( *walk ) {
-            char * p;
-            tr_bencListAddInt( setme, strtol( walk, &p, 10 ) );
+            const char * p = strchr( walk, ',' );
+            if( !p )
+                p = walk + strlen( walk );
+            addToken( setme, walk, p-walk );
             if( *p!=',' )
                 break;
             walk = p + 1;