Changeset 6316 for trunk/daemon/remote.c


Ignore:
Timestamp:
Jul 10, 2008, 8:59:15 PM (14 years ago)
Author:
charles
Message:

(daemon) let file download flags and priorities be set by transmission-remote. Add examples to the man page and --help.
(libT) minor tweaks to tr-getopt
(gtk) tweak the preference dialog's "port forwarding" text for clarity as suggested in the forums

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r6315 r6316  
    1111 */
    1212
     13#include <errno.h>
    1314#include <stdio.h>
    1415#include <stdlib.h>
     
    3738getUsage( void )
    3839{
    39     return "Transmission "LONG_VERSION_STRING"  http://www.transmissionbt.com/\n"
    40            "A fast and easy BitTorrent client\n"
    41            "\n"
    42            "Usage: "MY_NAME" [host] [options]\n"
    43            "       "MY_NAME" [port] [options]\n"
    44            "       "MY_NAME" [host:port] [options]";
     40    return
     41"Transmission "LONG_VERSION_STRING"  http://www.transmissionbt.com/\n"
     42"A fast and easy BitTorrent client\n"
     43"\n"
     44"Usage: "MY_NAME" [host] [options]\n"
     45"       "MY_NAME" [port] [options]\n"
     46"       "MY_NAME" [host:port] [options]\n"
     47"\n"
     48"Notes:\n"
     49"  <files> can be 'all', a single index, or a comma-separated list.\n"
     50"  <torrents> can be 'all', a torrent id or hash string, or a comma-separated list of ids and hash strings.\n"
     51"\n"
     52"Examples:\n"
     53"  \""MY_NAME" -l\" (list all torrents)\n"
     54"  \""MY_NAME" -tall --start\" (start all torrents)\n"
     55"  \""MY_NAME" --add ~/Desktop/*torrent\" (add all the torrent files in $HOME/Desktop)\n"
     56"  \""MY_NAME" -t1 -i\" (get detailed information on the torrent whose id is '1')\n"
     57"  \""MY_NAME" -t1 -Gall -g2,4,6\" (same torrent; only download the second, fourth, and sixth files)\n"
     58"  \""MY_NAME" -tall -ph1,2\" (set all torrent's first two files' priorities to high)\n"
     59"  \""MY_NAME" -tall -pnall\" (set all torrent's files' priorities to normal)";
    4560}
    4661
     
    4863{
    4964    { 'a', "add",          "Add torrent files", "a", 0, NULL },
     65    { 'b', "debug",        "Print debugging information", "b", 0, NULL },
    5066    { 'd', "downlimit",    "Set the maximum download speed in KB/s", "d", 1, "<number>" },
    5167    { 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL },
    5268    { 'e', "encryption",   "Set encryption mode [required, preferred, tolerated]", "e", 1, "<mode>" },
    5369    { 'f', "files",        "Get a file list for the current torrent(s)", "f", 0, NULL },
    54     { 'g', "debug",        "Print debugging information", "g", 0, NULL },
     70    { 'g', "get",          "Mark files for download", "g", 1, "<files>" },
     71    { 'G', "no-get",       "Mark files for not downloading", "G", 1, "<files>" },
    5572    { 'h', "help",         "Show this help page and exit", "h", 0, NULL },
    5673    { 'i', "info",         "Show details of the current torrent(s)", "i", 0, NULL },
     
    6077    { 'n', "auth",         "Set username for authentication", "n", 1, "<user>:<pass>" },
    6178    { 'p', "port",         "Port to listen for incoming peers", "p", 1, "<port>" },
     79    { 900, "priority-high", "Set one or more files' priority as high", "ph", 1, "<files>" },
     80    { 901, "priority-normal", "Set one or more files' priority as normal", "pn", 1, "<files>" },
     81    { 902, "priority-normal", "Set one or more files' priority as low", "pl", 1, "<files>" },
    6282    { 'r', "remove",       "Remove the current torrent(s)", "r", 0, NULL },
    6383    { 's', "start",        "Start the current torrent(s)", "s", 0, NULL },
    6484    { 'S', "stop",         "Stop the current torrent(s)", "S", 0, NULL },
    65     { 't', "torrent",      "Set the current torrent(s)", "t", 1, "<id|hash|all>" },
     85    { 't', "torrent",      "Set the current torrent(s)", "t", 1, "<torrents>" },
    6686    { 'u', "uplimit",      "Set the maximum upload speed in KB/s", "u", 1, "<number>" },
    6787    { 'U', "no-uplimit",   "Don't limit the upload speed", "U", 0, NULL },
     
    126146        fprintf( stderr, "No torrent specified!  Please use the -t option first.\n" );
    127147        id = "-1"; /* no torrent will have this ID, so should be a no-op */
    128     } else if( strcmp( id, "all" ) ) {
     148    }
     149    if( strcmp( id, "all" ) ) {
    129150        tr_rpc_parse_list_str( tr_bencDictAdd( args, "ids" ), id, strlen(id) );
     151    }
     152}
     153
     154static void
     155addFiles( tr_benc * args, const char * key, const char * arg )
     156{
     157    tr_benc * files = tr_bencDictAddList( args, key, 100 );
     158
     159    if( !*arg )
     160    {
     161        fprintf( stderr, "No files specified!\n" );
     162        arg = "-1"; /* no file will have this index, so should be a no-op */
     163    }
     164    if( strcmp( arg, "all" ) )
     165    {
     166        const char * walk = arg;
     167        while( *walk ) {
     168            char * p;
     169            unsigned long l;
     170            errno = 0;
     171            l = strtol( walk, &p, 10 );
     172            if( errno )
     173                break;
     174            tr_bencListAddInt( files, l - 1 );
     175            if( *p != ',' )
     176                break;
     177            walk = p + 1;
     178        }
    130179    }
    131180}
     
    166215                      addArg = FALSE;
    167216                      break;
     217            case 'b': debug = 1;
     218                      addArg = FALSE;
     219                      break;
    168220            case 'd': tr_bencDictAddStr( &top, "method", "session-set" );
    169221                      tr_bencDictAddInt( args, "speed-limit-down", numarg( optarg ) );
     
    184236                      tr_bencDictAddInt( args, "fields", fields );
    185237                      break;
    186             case 'g': debug = 1;
    187                       addArg = FALSE;
     238            case 'g': tr_bencDictAddStr( &top, "method", "torrent-set" );
     239                      addIdArg( args, id );
     240                      addFiles( args, "files-wanted", optarg );
     241                      break;
     242            case 'G': tr_bencDictAddStr( &top, "method", "torrent-set" );
     243                      addIdArg( args, id );
     244                      addFiles( args, "files-unwanted", optarg );
    188245                      break;
    189246            case 'i': tr_bencDictAddStr( &top, "method", "torrent-get" );
     
    252309            case 'X': tr_bencDictAddStr( &top, "method", "session-set" );
    253310                      tr_bencDictAddInt( args, "pex-allowed", 0 );
     311                      break;
     312            case 900: tr_bencDictAddStr( &top, "method", "torrent-set" );
     313                      addIdArg( args, id );
     314                      addFiles( args, "priority-high", optarg );
     315                      break;
     316            case 901: tr_bencDictAddStr( &top, "method", "torrent-set" );
     317                      addIdArg( args, id );
     318                      addFiles( args, "priority-normal", optarg );
     319                      break;
     320            case 902: tr_bencDictAddStr( &top, "method", "torrent-set" );
     321                      addIdArg( args, id );
     322                      addFiles( args, "priority-low", optarg );
    254323                      break;
    255324            default:  fprintf( stderr, "got opt [%d]\n", (int)c );
Note: See TracChangeset for help on using the changeset viewer.