Changeset 6213


Ignore:
Timestamp:
Jun 17, 2008, 4:25:13 PM (13 years ago)
Author:
charles
Message:

(rpc) fix sorting. simplify the spec, folding similar functions together

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r6203 r6213  
    195195                      tr_bencDictAddStr( args, "download-dir", absolutify(buf,sizeof(buf),optarg) );
    196196                      break;
    197             case 'l': tr_bencDictAddStr( &top, "method", "torrent-info" );
     197            case 'l': tr_bencDictAddStr( &top, "method", "torrent-get" );
    198198                      tr_bencDictAddInt( &top, "tag", TAG_LIST );
    199199                      fields = TR_RPC_TORRENT_FIELD_ID
    200                              | TR_RPC_TORRENT_FIELD_ACTIVITY
    201                              | TR_RPC_TORRENT_FIELD_SIZE;
     200                             | TR_RPC_TORRENT_FIELD_ACTIVITY;
    202201                      tr_bencDictAddInt( args, "fields", fields );
    203                       tr_bencDictAddStr( args, "sort", "name" );
     202                      /*tr_bencDictAddStr( args, "sort", "name" );*/
    204203                      break;
    205204            case 'm': tr_bencDictAddStr( &top, "method", "session-set" );
     
    313312        if( ( tag == TAG_LIST ) &&
    314313            ( tr_bencDictFindDict( &top, "arguments", &args ) ) &&
    315             ( tr_bencDictFindList( args, "torrent-info", &list ) ) )
     314            ( tr_bencDictFindList( args, "torrents", &list ) ) )
    316315        {
    317316            int i, n;
  • trunk/doc/rpc-spec.txt

    r6210 r6213  
    1313
    1414   Messages are formatted in a subset of JSON easily represented
    15    as bencoded data -- arrays, objects, strings, and numbers.
     15   as bencoded data -- arrays, objects, strings, and whole numbers.
    1616   Booleans are represented as numbers where 0 is false and 1 is true.
     17   Floating-point numbers are represented as strings.
    1718
    1819   Messages are formatted as objects.  There are two types:
     
    2526   (1) A required "method" string telling the name of the method to invoke
    2627   (2) An optional "arguments" object of key/value pairs
    27    (3) An optional "tag" integer used by clients to track responses.
     28   (3) An optional "tag" number used by clients to track responses.
    2829       If provided by a request, the response MUST include the same tag.
    2930
     
    3536       or an error string on failure.
    3637   (2) An optional "arguments" object of key/value pairs
    37    (3) An optional "tag" integer as described in 2.1.
     38   (3) An optional "tag" number as described in 2.1.
    3839
    39402.3.  Transport Mechanism
    4041
    41    POSTing a JSON-encoded request is the preferred way of communicating
    42    with the Transmission server; however, a simple notation also exists
     42   HTTP POSTing a JSON-encoded request is the preferred way of communicating
     43   with a Transmission RPC server; however, a simple notation also exists
    4344   for sending requests in the query portion of a URL.
    4445
     
    6566   "torrent-verify"    | tr_torrentVerify
    6667
    67    Request arguments: "ids", a list of torrent id integers, sha1 hash strings,
     68   Request arguments: "ids", a list of torrent id numbers, sha1 hash strings,
    6869                      or both.  These are the torrents that the request will
    6970                      be applied to.  If "ids" is ommitted, the request is
     
    7273   Response arguments: none
    7374
    74 3.2.  Torrent Information Requests
    75 
    76    Method name: "torrent-info".
    77 
    78    The request supports four arguments:
    79 
    80    (1) An optional "ids" array as described in section 3.1.
    81    (2) A required "fields" number as described in the table below.
    82    (3) An optional "sort" string whose value should be one of
    83        "activity", "age", "id", "name", "progress", "ratio", "state", "tracker".
    84        The default value is "id".
    85    (4) An optional "sort-ascending" 'boolean'.
    86        This is only used if "sort-method" is supplied.
    87        Its default value is 'true'.
    88    (5) An optional "filter" string whose value may be one of
    89        "active", "all", "downloading", "paused", "seeding".
    90        The default value is "all".
    91 
    92    The respons supports two arguments:
    93 
    94    (1) A required "fields" number identical to the request's
    95    (2) A "torrent-info" list of objects, each of which contains the
    96        response names described in the table below.
    97 
    98    field and          | response | response               | source
    99    numeric value      | type     | name                   |
     753.2.  Torrent Mutator
     76
     77   Method name: "torrent-set"
     78
     79   Request arguments:
     80
     81   string                     | value type & description
     82   ---------------------------+-------------------------------------------------
     83   "files-wanted"             | array      indices of one or more file to download
     84   "files-unwanted"           | array      indices of one or more file to not download
     85   "ids"                      | array      which torrent(s) to set, described in 3.1
     86   "peer-limit"               | number     maximum number of peers
     87   "priority-high"            | array      indices of one or more high-priority files
     88   "priority-low"             | array      indices of one or more low-priority files
     89   "priority-normal"          | array      indices of one or more normal-priority files
     90   "speed-limit-down"         | number     maximum download speed (in KiB/s)
     91   "speed-limit-down-enabled" | 'boolean'  true if the download speed is limited
     92   "speed-limit-up"           | number     maximum upload speed (in KiB/s)
     93   "speed-limit-up-enabled"   | 'boolean'  true if the upload speed is limited
     94
     95   Response arguments: none
     96
     973.3.  Torrent Accessors
     98
     99   Method name: "torrent-get".
     100
     101   Request arguments:
     102
     103   string       | required? | default | value type & description
     104   -------------+-----------+---------+---------------------------------------
     105   "ids"        | no        | all     | array     described in 3.1
     106   "fields"     | yes       | n/a     | number    bitwise-or'ed field
     107                |           |         |           values from the table below
     108   "sort"       | no        | "id"    | string    "activity", "age", "id",
     109                |           |         |           "name", "progress", "ratio",
     110                |           |         |           "state", or "tracker".
     111   "ascending"  | no        | 'true'  | 'boolean' true if sorting ascending
     112   "filter"     | no        | "all"   | string    "active", "all", "paused",
     113                |           |         |           "downloading", or "seeding".
     114
     115   The response contains two arguments:
     116
     117   (1) A "fields" number identical to the request's
     118   (2) A "torrents" array of objects, each of which contains the
     119       key/value fields that match the "fields" argument.
     120       See the table below for a complete list.
     121
     122   "fields" value     | response | response               | source
     123                      | value    | key                    |
    100124   -------------------+----------+------------------------+-------------
    101125   activity, 1        | number   | desiredAvailable       | tr_stat
     
    114138   announce, 2        | string   | announceResponse       | tr_stat
    115139                      | string   | announceURL            | tr_stat
    116                       | string   | lastAnnounceTime       | tr_stat
    117                       | string   | manualAnnounceTime     | tr_stat
    118                       | string   | nextAnnounceTime       | tr_stat
     140                      | number   | lastAnnounceTime       | tr_stat
     141                      | number   | manualAnnounceTime     | tr_stat
     142                      | number   | nextAnnounceTime       | tr_stat
    119143   -------------------+----------+------------------------+-------------
    120144   error, 4           | number   | error                  | tr_stat
    121                       | number   | errorString            | tr_Stat
     145                      | number   | errorString            | tr_stat
    122146   -------------------+----------+------------------------+-------------
    123147   files, 8           | array    | files
     
    157181                      | number   | fromTracker            | tr_stat
    158182   -------------------+----------+------------------------+-------------
    159    scrape, 512        | number   | lastScrapeTime         | tr_stat
     183   priorities, 512    | array    | priorities             | tr_info
     184                      | array    | wanted                 | tr_info
     185                      +----------+--------------------------------------
     186                      | priorities is an array of tr_info.fileCount
     187                      | numbers.  Each is the tr_priority_t mode for
     188                      | the corresponding file.
     189                      +-------------------------------------------------
     190                      | wanted is an array of tr_info.fileCount
     191                      | 'booleans' true if the corresponding file
     192                      | is to be downloaded.
     193   -------------------+----------+------------------------+-------------
     194   scrape, 1024       | number   | lastScrapeTime         | tr_stat
    160195                      | number   | nextScrapeTime         | tr_stat
    161196                      | string   | scrapeResponse         | tr_stat
    162197                      | string   | scrapeURL              | tr_stat
    163198   -------------------+----------+------------------------+-------------
    164    size, 1024         | number   | haveUnchecked          | tr_stat
     199   size, 2048         | number   | haveUnchecked          | tr_stat
    165200                      | number   | haveValid              | tr_stat
    166201                      | number   | leftUntilDone          | tr_stat
     
    169204   -------------------+----------+------------------------+-------------
    170205   tracker stats,     | number   | leechers               | tr_stat
    171    2048               | number   | peersKnown             | tr_stat
     206   4096               | number   | peersKnown             | tr_stat
    172207                      | number   | seeders                | tr_stat
    173208                      | number   | timesCompleted         | tr_stat
    174209   -------------------+----------+--------------------------------------
    175    trackers, 4096     | array    | trackers
     210   trackers, 8192     | array    | trackers
    176211                      +----------+--------------------------------------
    177212                      | trackers is an array of objects that contain:
     
    181216                      | number   | tier                   | tr_info
    182217   -------------------+----------+------------------------+-------------
    183    webseeds, 8192     | object   | webseeds
     218   webseeds, 16384    | array    | webseeds
    184219                      +----------+--------------------------------------
    185                       | webseeds contains:
     220                      | webseeds is an array of strings:
    186221                      +----------+------------------------+-------------
    187                       | an array of weseed URL strings    | tr_info
    188    -------------------+----------+------------------------+-------------
    189 
     222                      | string   | webseed URL            | tr_info
     223   -------------------+----------+------------------------+-------------
    190224
    191225   Example:
    192226
    193    Say we want to get the name and total size torrents 7 and 10.
    194    name is in the "id" section (32) and total size is in "size" (1024),
    195    so the "fields" argument will be 32 + 1024 == 1056.
     227   Say we want to get the name and total size of torrents #7 and #10.
     228   name is in the "id" section (32) and total size is in "size" (2048),
     229   so the "fields" argument will be 32 + 2048 == 2080.
    196230
    197231   Request:
     
    199233      {
    200234         "arguments": {
    201              "fields": 1056,
     235             "fields": 2080,
    202236             "ids": [ 7, 10 ],
    203237             "sort-method": "name"
    204238         }
    205          "method": "torrent-info",
     239         "method": "torrent-get",
    206240         "tag": 39693
    207241      }
     
    212246      {
    213247         "arguments": {
    214             "fields": 1056,
    215             "torrent-info": [
     248            "fields": 2080,
     249            "torrents": [
    216250               {
    217251                   "hashString": "sijioejisoefjiosejfioi",
     
    240274      }
    241275
    242 3.3.  Adding a Torrent
     2763.2.  Adding a Torrent
    243277
    244278   Method name: "torrent-add"
     
    248282   key                | value type & description
    249283   -------------------+-------------------------------------------------
    250    "download-dir"     | string    path to download the torrent to
    251    "filename"         | string    location of the .torrent file
    252    "metainfo"         | string    base64-encoded .torrent content
    253    "paused"           | boolean   if true, don't start the torrent
    254    "peer-limit"       | int       maximum number of peers
     284   "download-dir"     | string      path to download the torrent to
     285   "filename"         | string      location of the .torrent file
     286   "metainfo"         | string      base64-encoded .torrent content
     287   "paused"           | 'boolean'   if true, don't start the torrent
     288   "peer-limit"       | number      maximum number of peers
    255289
    256290   Either "filename" OR "metainfo" must be included.
     
    261295                       fields for id, name, and hashString.
    262296
    263 3.4.  Other Torrent Settings
    264 
    265    Common arguments:
     2974.   Session Status Requests
     298
     2994.1.  Session Arguments
    266300
    267301   string                     | value type & description
    268302   ---------------------------+-------------------------------------------------
    269    "peer-limit"               | int       maximum number of peers
    270    "speed-limit-down"         | int       maximum download speed (in KiB/s)
    271    "speed-limit-down-enabled" | boolean   true if the download speed is limited
    272    "speed-limit-up"           | int       maximum upload speed (in KiB/s)
    273    "speed-limit-up-enabled"   | boolean   true if the upload speed is limited
    274 
    275 3.4.1.  Mutators
    276 
    277    Method name: "torrent-set"
    278    Request arguments: 3.1's "ids", plus one or more of 3.6's arguments
    279    Response arguments: none
    280                      
    281 
    282 3.5  File Priorities
    283 
    284    Common arguments:
    285 
    286    string             | value type & description
    287    -------------------+-------------------------------------------------
    288    "files-wanted"     | array     indices of one or more file to download
    289    "files-unwanted"   | array     indices of one or more file to not download
    290    "priority-high"    | array     indices of one or more high-priority files
    291    "priority-low"     | array     indices of one or more low-priority files
    292    "priority-normal"  | array     indices of one or more normal-priority files
    293 
    294 3.5.1.  Mutators
    295 
    296     Method name: "torrent-set-priorities"
    297     Request arguments: 3.1's "ids", plus one or more of 3.7's arguments
    298     Response arguments: none
    299 
    300 3.5.2.  Accessors
    301 
    302     Method name: "torrent-get-priorities"
    303     Request arguments: none
    304     Response arguments: A "torrents" list of objects containing all
    305                         of 3.7's arguments plus the torrent's "id" int.
    306    
    307 4.   Session Status Requests
    308 
    309 4.1.  Session Arguments
    310 
    311    string                     | value type & description
    312    ---------------------------+-------------------------------------------------
    313    "encryption"               | string   "required", "preferred", "tolerated"
    314    "download-dir"             | string   default path to download torrents
    315    "peer-limit"               | int      maximum global number of peers
    316    "pex-allowed"              | boolean  true means allow pex in public torrents
    317    "port"                     | int      port number
    318    "port-forwarding-enabled"  | boolean  true means enabled
    319    "speed-limit-down"         | int      max global download speed (in KiB/s)
    320    "speed-limit-down-enabled" | boolean  true means enabled
    321    "speed-limit-up"           | int      max global upload speed (in KiB/s)
    322    "speed-limit-up-enabled"   | boolean  true means enabled
     303   "encryption"               | string     "required", "preferred", "tolerated"
     304   "download-dir"             | string     default path to download torrents
     305   "peer-limit"               | number     maximum global number of peers
     306   "pex-allowed"              | 'boolean'  true means allow pex in public torrents
     307   "port"                     | number     port number
     308   "port-forwarding-enabled"  | 'boolean'  true means enabled
     309   "speed-limit-down"         | number     max global download speed (in KiB/s)
     310   "speed-limit-down-enabled" | 'boolean'  true means enabled
     311   "speed-limit-up"           | number     max global upload speed (in KiB/s)
     312   "speed-limit-up-enabled"   | 'boolean'  true means enabled
    323313
    3243144.2.  Mutators
  • trunk/libtransmission/rpc-utils.c

    r6203 r6213  
    2626compareTorrentsByActivity( const void * a, const void * b )
    2727{
    28     const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
    29     const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
     28    const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
     29    const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
    3030    int i;
    3131    if(( i = tr_compareDouble( sa->rateUpload + sa->rateDownload,
     
    4040compareTorrentsByAge( const void * a, const void * b )
    4141{
    42     return tr_compareTime( tr_torrentStatCached( (tr_torrent*)a )->addedDate,
    43                            tr_torrentStatCached( (tr_torrent*)b )->addedDate );
     42    const tr_torrent * ta = * (tr_torrent **) a;
     43    const tr_torrent * tb = * (tr_torrent **) b;
     44    return tr_compareTime( tr_torrentStatCached( ta )->addedDate,
     45                           tr_torrentStatCached( tb )->addedDate );
    4446}
    4547
     
    4749compareTorrentsByID( const void * a, const void * b )
    4850{
    49     return ((tr_torrent*)a)->uniqueId - ((tr_torrent*)b)->uniqueId;
     51    const tr_torrent * ta = * (tr_torrent **) a;
     52    const tr_torrent * tb = * (tr_torrent **) b;
     53    return ta->uniqueId - tb->uniqueId;
    5054}
    5155
     
    5357compareTorrentsByName( const void * a, const void * b )
    5458{
    55     const tr_torrent * ta = a;
    56     const tr_torrent * tb = b;
     59    const tr_torrent * ta = * (tr_torrent **) a;
     60    const tr_torrent * tb = * (tr_torrent **) b;
    5761    return tr_strcasecmp( ta->info.name, tb->info.name );
    5862}
     
    7074compareTorrentsByProgress( const void * a, const void * b )
    7175{
    72     const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
    73     const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
     76    const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
     77    const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
    7478    int ret = tr_compareDouble( sa->percentDone, sb->percentDone );
    7579    if( !ret )
     
    8185compareTorrentsByRatio( const void * a, const void * b )
    8286{
    83     const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
    84     const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
     87    const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
     88    const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
    8589    return compareRatio( sa->ratio, sb->ratio );
    8690}
     
    8993compareTorrentsByState( const void * a, const void * b )
    9094{
    91     const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
    92     const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
     95    const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
     96    const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
    9397    int ret = sa->status - sb->status;
    9498    if( !ret )
     
    100104compareTorrentsByTracker( const void * a, const void * b )
    101105{
    102     const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
    103     const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
     106    const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
     107    const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
    104108    return tr_strcmp( sa->announceURL, sb->announceURL );
    105109}
  • trunk/libtransmission/rpc.c

    r6210 r6213  
    116116    method = TR_SORT_ID;
    117117    sortAscending = 1;
    118     tr_bencDictFindInt( args, "sort-ascending", &sortAscending );
     118    tr_bencDictFindInt( args, "ascending", &sortAscending );
    119119    if( tr_bencDictFindStr( args, "sort", &str ) ) {
    120120             if( !strcmp( str, "activity" ) ) method = TR_SORT_ACTIVITY;
     
    314314    }
    315315
     316    if( fields & TR_RPC_TORRENT_FIELD_PRIORITIES ) {
     317        tr_file_index_t i;
     318        tr_benc * p = tr_bencDictAddList( d, "priorities", inf->fileCount );
     319        tr_benc * w = tr_bencDictAddList( d, "wanted", inf->fileCount );
     320        for( i=0; i<inf->fileCount; ++i ) {
     321            tr_bencListAddInt( p, inf->files[i].priority );
     322            tr_bencListAddInt( w, inf->files[i].dnd ? 0 : 1 );
     323        }
     324    }
     325
    316326    if( fields & TR_RPC_TORRENT_FIELD_SCRAPE ) {
    317327        tr_bencDictAddInt( d, "lastScrapeTime", st->lastScrapeTime );
     
    344354
    345355static const char*
    346 torrentInfo( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
     356torrentGet( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
    347357{
    348358    int i, torrentCount;
    349359    tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount );
    350     tr_benc * list = tr_bencDictAddList( args_out, "torrent-info", torrentCount );
     360    tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount );
    351361    int64_t fields = 0;
    352362
     
    366376***/
    367377
     378static void
     379setFilePriorities( tr_torrent * tor, int priority, tr_benc * list )
     380{
     381    int i;
     382    int64_t tmp;
     383    int fileCount = 0;
     384    const int n = tr_bencListSize( list );
     385    tr_file_index_t * files = tr_new0( tr_file_index_t, n );
     386
     387    for( i=0; i<n; ++i )
     388        if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
     389            files[fileCount++] = tmp;
     390
     391    if( fileCount )
     392        tr_torrentSetFilePriorities( tor, files, fileCount, priority );
     393
     394    tr_free( files );
     395}
     396
     397static void
     398setFileDLs( tr_torrent * tor, int do_download, tr_benc * list )
     399{
     400    int i;
     401    int64_t tmp;
     402    int fileCount = 0;
     403    const int n = tr_bencListSize( list );
     404    tr_file_index_t * files = tr_new0( tr_file_index_t, n );
     405
     406    for( i=0; i<n; ++i )
     407        if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
     408            files[fileCount++] = tmp;
     409
     410    if( fileCount )
     411        tr_torrentSetFileDLs( tor, files, fileCount, do_download );
     412
     413    tr_free( files );
     414}
     415
    368416static const char*
    369417torrentSet( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
     
    375423    {
    376424        int64_t tmp;
     425        tr_benc * files;
    377426        tr_torrent * tor = torrents[i];
     427
     428        if( tr_bencDictFindList( args_in, "files-unwanted", &files ) )
     429            setFileDLs( tor, FALSE, files );
     430        if( tr_bencDictFindList( args_in, "files-wanted", &files ) )
     431            setFileDLs( tor, TRUE, files );
    378432        if( tr_bencDictFindInt( args_in, "peer-limit", &tmp ) )
    379433            tr_torrentSetPeerLimit( tor, tmp );
     434        if( tr_bencDictFindList( args_in, "priority-high", &files ) )
     435            setFilePriorities( tor, TR_PRI_HIGH, files );
     436        if( tr_bencDictFindList( args_in, "priority-low", &files ) )
     437            setFilePriorities( tor, TR_PRI_LOW, files );
     438        if( tr_bencDictFindList( args_in, "priority-normal", &files ) )
     439            setFilePriorities( tor, TR_PRI_NORMAL, files );
    380440        if( tr_bencDictFindInt( args_in, "speed-limit-down", &tmp ) )
    381441            tr_torrentSetSpeedLimit( tor, TR_DOWN, tmp );
     
    388448            tr_torrentSetSpeedMode( tor, TR_UP, tmp ? TR_SPEEDLIMIT_SINGLE
    389449                                                    : TR_SPEEDLIMIT_GLOBAL );
    390         notify( h, TR_RPC_TORRENT_CHANGED, tor );
    391     }
    392 
    393     tr_free( torrents );
    394     return NULL;
    395 }
    396 
    397 typedef int( *fileTestFunc )( const tr_torrent * tor, int i );
    398 
    399 static int
    400 testFileHigh( const tr_torrent * tor, int i )
    401 {
    402     return tor->info.files[i].priority == TR_PRI_HIGH;
    403 }
    404 static int
    405 testFileLow( const tr_torrent * tor, int i )
    406 {
    407     return tor->info.files[i].priority == TR_PRI_LOW;
    408 }
    409 static int
    410 testFileNormal( const tr_torrent * tor, int i )
    411 {
    412     return tor->info.files[i].priority == TR_PRI_NORMAL;
    413 }
    414 static int
    415 testFileDND( const tr_torrent * tor, int i )
    416 {
    417     return tor->info.files[i].dnd != 0;
    418 }
    419 static int
    420 testFileDownload( const tr_torrent * tor, int i )
    421 {
    422     return tor->info.files[i].dnd == 0;
    423 }
    424 
    425 static void
    426 buildFileList( const tr_torrent * tor, tr_benc * dict,
    427                const char * key, fileTestFunc func )
    428 {
    429     int i;
    430     const int n = tor->info.fileCount;
    431     tr_benc * list;
    432     int * files = tr_new0( int, n );
    433     int fileCount = 0;
    434    
    435     for( i=0; i<n; ++i )
    436         if( func( tor, i ) )
    437             files[fileCount++] = i;
    438 
    439     list = tr_bencDictAddList( dict, key, fileCount );
    440 
    441     for( i=0; i<fileCount; ++i )
    442         tr_bencListAddInt( list, files[i] );
    443 
    444     tr_free( files );
    445 }
    446 
    447 static const char*
    448 torrentGetPriorities( tr_handle * handle,
    449                       tr_benc * args_in, tr_benc * args_out )
    450 {
    451     int i, torrentCount;
    452     tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount );
    453     tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount );
    454 
    455     for( i=0; i<torrentCount; ++i )
    456     {
    457         const tr_torrent * tor = torrents[i];
    458         tr_benc * d = tr_bencListAddDict( list, 6 );
    459         tr_bencDictAddInt( d, "id", tr_torrentId( tor ) );
    460         buildFileList( tor, d, "files-unwanted", testFileDND );
    461         buildFileList( tor, d, "files-wanted", testFileDownload );
    462         buildFileList( tor, d, "priority-low", testFileLow );
    463         buildFileList( tor, d, "priority-normal", testFileNormal );
    464         buildFileList( tor, d, "priority-high", testFileHigh );
    465     }
    466 
    467     tr_free( torrents );
    468     return NULL;
    469 }
    470 
    471 static void
    472 setFilePriorities( tr_torrent * tor, int priority, tr_benc * list )
    473 {
    474     int i;
    475     int64_t tmp;
    476     int fileCount = 0;
    477     const int n = tr_bencListSize( list );
    478     tr_file_index_t * files = tr_new0( tr_file_index_t, n );
    479 
    480     for( i=0; i<n; ++i )
    481         if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
    482             files[fileCount++] = tmp;
    483 
    484     if( fileCount )
    485         tr_torrentSetFilePriorities( tor, files, fileCount, priority );
    486 
    487     tr_free( files );
    488 }
    489 
    490 static void
    491 setFileDLs( tr_torrent * tor, int do_download, tr_benc * list )
    492 {
    493     int i;
    494     int64_t tmp;
    495     int fileCount = 0;
    496     const int n = tr_bencListSize( list );
    497     tr_file_index_t * files = tr_new0( tr_file_index_t, n );
    498 
    499     for( i=0; i<n; ++i )
    500         if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
    501             files[fileCount++] = tmp;
    502 
    503     if( fileCount )
    504         tr_torrentSetFileDLs( tor, files, fileCount, do_download );
    505 
    506     tr_free( files );
    507 }
    508 
    509 static const char*
    510 torrentSetPriorities( tr_handle * h,
    511                       tr_benc * args_in, tr_benc * args_out UNUSED )
    512 {
    513     int i, torrentCount;
    514     tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount );
    515 
    516     for( i=0; i<torrentCount; ++i )
    517     {
    518         tr_benc * files;
    519         tr_torrent * tor = torrents[i];
    520 
    521         if( tr_bencDictFindList( args_in, "files-unwanted", &files ) )
    522             setFileDLs( tor, FALSE, files );
    523         if( tr_bencDictFindList( args_in, "files-wanted", &files ) )
    524             setFileDLs( tor, TRUE, files );
    525         if( tr_bencDictFindList( args_in, "priority-high", &files ) )
    526             setFilePriorities( tor, TR_PRI_HIGH, files );
    527         if( tr_bencDictFindList( args_in, "priority-low", &files ) )
    528             setFilePriorities( tor, TR_PRI_LOW, files );
    529         if( tr_bencDictFindList( args_in, "priority-normal", &files ) )
    530             setFilePriorities( tor, TR_PRI_NORMAL, files );
    531450
    532451        notify( h, TR_RPC_TORRENT_CHANGED, tor );
     
    685604    { "session-set", sessionSet },
    686605    { "torrent-add", torrentAdd },
    687     { "torrent-get-priorities", torrentGetPriorities },
    688     { "torrent-info", torrentInfo },
     606    { "torrent-get", torrentGet },
    689607    { "torrent-remove", torrentRemove },
    690     { "torrent-set-priorities", torrentSetPriorities },
    691608    { "torrent-set", torrentSet },
    692609    { "torrent-start", torrentStart },
  • trunk/libtransmission/rpc.h

    r6199 r6213  
    2929    TR_RPC_TORRENT_FIELD_LIMITS          = (1<<7),
    3030    TR_RPC_TORRENT_FIELD_PEERS           = (1<<8),
    31     TR_RPC_TORRENT_FIELD_SCRAPE          = (1<<9),
    32     TR_RPC_TORRENT_FIELD_SIZE            = (1<<10),
    33     TR_RPC_TORRENT_FIELD_TRACKER_STATS   = (1<<11),
    34     TR_RPC_TORRENT_FIELD_TRACKERS        = (1<<12),
    35     TR_RPC_TORRENT_FIELD_WEBSEEDS        = (1<<13)
     31    TR_RPC_TORRENT_FIELD_PRIORITIES      = (1<<9),
     32    TR_RPC_TORRENT_FIELD_SCRAPE          = (1<<10),
     33    TR_RPC_TORRENT_FIELD_SIZE            = (1<<11),
     34    TR_RPC_TORRENT_FIELD_TRACKER_STATS   = (1<<12),
     35    TR_RPC_TORRENT_FIELD_TRACKERS        = (1<<13),
     36    TR_RPC_TORRENT_FIELD_WEBSEEDS        = (1<<14)
    3637};
    3738
Note: See TracChangeset for help on using the changeset viewer.