mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
(rpc) fix sorting. simplify the spec, folding similar functions together
This commit is contained in:
parent
81b510bfd1
commit
75cb355579
5 changed files with 152 additions and 241 deletions
|
@ -194,13 +194,12 @@ readargs( int argc, char ** argv )
|
|||
case 'f': tr_bencDictAddStr( &top, "method", "session-set" );
|
||||
tr_bencDictAddStr( args, "download-dir", absolutify(buf,sizeof(buf),optarg) );
|
||||
break;
|
||||
case 'l': tr_bencDictAddStr( &top, "method", "torrent-info" );
|
||||
case 'l': tr_bencDictAddStr( &top, "method", "torrent-get" );
|
||||
tr_bencDictAddInt( &top, "tag", TAG_LIST );
|
||||
fields = TR_RPC_TORRENT_FIELD_ID
|
||||
| TR_RPC_TORRENT_FIELD_ACTIVITY
|
||||
| TR_RPC_TORRENT_FIELD_SIZE;
|
||||
| TR_RPC_TORRENT_FIELD_ACTIVITY;
|
||||
tr_bencDictAddInt( args, "fields", fields );
|
||||
tr_bencDictAddStr( args, "sort", "name" );
|
||||
/*tr_bencDictAddStr( args, "sort", "name" );*/
|
||||
break;
|
||||
case 'm': tr_bencDictAddStr( &top, "method", "session-set" );
|
||||
tr_bencDictAddInt( args, "port-forwarding-enabled", 1 );
|
||||
|
@ -312,7 +311,7 @@ processResponse( const char * host, int port,
|
|||
|
||||
if( ( tag == TAG_LIST ) &&
|
||||
( tr_bencDictFindDict( &top, "arguments", &args ) ) &&
|
||||
( tr_bencDictFindList( args, "torrent-info", &list ) ) )
|
||||
( tr_bencDictFindList( args, "torrents", &list ) ) )
|
||||
{
|
||||
int i, n;
|
||||
for( i=0, n=tr_bencListSize( list ); i<n; ++i )
|
||||
|
|
200
doc/rpc-spec.txt
200
doc/rpc-spec.txt
|
@ -12,8 +12,9 @@
|
|||
2. Message Format
|
||||
|
||||
Messages are formatted in a subset of JSON easily represented
|
||||
as bencoded data -- arrays, objects, strings, and numbers.
|
||||
as bencoded data -- arrays, objects, strings, and whole numbers.
|
||||
Booleans are represented as numbers where 0 is false and 1 is true.
|
||||
Floating-point numbers are represented as strings.
|
||||
|
||||
Messages are formatted as objects. There are two types:
|
||||
requests (described in 2.1) and responses (described in 2.2).
|
||||
|
@ -24,7 +25,7 @@
|
|||
|
||||
(1) A required "method" string telling the name of the method to invoke
|
||||
(2) An optional "arguments" object of key/value pairs
|
||||
(3) An optional "tag" integer used by clients to track responses.
|
||||
(3) An optional "tag" number used by clients to track responses.
|
||||
If provided by a request, the response MUST include the same tag.
|
||||
|
||||
2.2. Responses
|
||||
|
@ -34,12 +35,12 @@
|
|||
(1) A required "result" string whose value must be "success" on success,
|
||||
or an error string on failure.
|
||||
(2) An optional "arguments" object of key/value pairs
|
||||
(3) An optional "tag" integer as described in 2.1.
|
||||
(3) An optional "tag" number as described in 2.1.
|
||||
|
||||
2.3. Transport Mechanism
|
||||
|
||||
POSTing a JSON-encoded request is the preferred way of communicating
|
||||
with the Transmission server; however, a simple notation also exists
|
||||
HTTP POSTing a JSON-encoded request is the preferred way of communicating
|
||||
with a Transmission RPC server; however, a simple notation also exists
|
||||
for sending requests in the query portion of a URL.
|
||||
|
||||
The URL notation works as follows:
|
||||
|
@ -64,39 +65,62 @@
|
|||
"torrent-stop" | tr_torrentStop
|
||||
"torrent-verify" | tr_torrentVerify
|
||||
|
||||
Request arguments: "ids", a list of torrent id integers, sha1 hash strings,
|
||||
Request arguments: "ids", a list of torrent id numbers, sha1 hash strings,
|
||||
or both. These are the torrents that the request will
|
||||
be applied to. If "ids" is ommitted, the request is
|
||||
applied to all torrents.
|
||||
|
||||
Response arguments: none
|
||||
|
||||
3.2. Torrent Information Requests
|
||||
3.2. Torrent Mutator
|
||||
|
||||
Method name: "torrent-info".
|
||||
Method name: "torrent-set"
|
||||
|
||||
The request supports four arguments:
|
||||
Request arguments:
|
||||
|
||||
(1) An optional "ids" array as described in section 3.1.
|
||||
(2) A required "fields" number as described in the table below.
|
||||
(3) An optional "sort" string whose value should be one of
|
||||
"activity", "age", "id", "name", "progress", "ratio", "state", "tracker".
|
||||
The default value is "id".
|
||||
(4) An optional "sort-ascending" 'boolean'.
|
||||
This is only used if "sort-method" is supplied.
|
||||
Its default value is 'true'.
|
||||
(5) An optional "filter" string whose value may be one of
|
||||
"active", "all", "downloading", "paused", "seeding".
|
||||
The default value is "all".
|
||||
string | value type & description
|
||||
---------------------------+-------------------------------------------------
|
||||
"files-wanted" | array indices of one or more file to download
|
||||
"files-unwanted" | array indices of one or more file to not download
|
||||
"ids" | array which torrent(s) to set, described in 3.1
|
||||
"peer-limit" | number maximum number of peers
|
||||
"priority-high" | array indices of one or more high-priority files
|
||||
"priority-low" | array indices of one or more low-priority files
|
||||
"priority-normal" | array indices of one or more normal-priority files
|
||||
"speed-limit-down" | number maximum download speed (in KiB/s)
|
||||
"speed-limit-down-enabled" | 'boolean' true if the download speed is limited
|
||||
"speed-limit-up" | number maximum upload speed (in KiB/s)
|
||||
"speed-limit-up-enabled" | 'boolean' true if the upload speed is limited
|
||||
|
||||
The respons supports two arguments:
|
||||
Response arguments: none
|
||||
|
||||
(1) A required "fields" number identical to the request's
|
||||
(2) A "torrent-info" list of objects, each of which contains the
|
||||
response names described in the table below.
|
||||
3.3. Torrent Accessors
|
||||
|
||||
field and | response | response | source
|
||||
numeric value | type | name |
|
||||
Method name: "torrent-get".
|
||||
|
||||
Request arguments:
|
||||
|
||||
string | required? | default | value type & description
|
||||
-------------+-----------+---------+---------------------------------------
|
||||
"ids" | no | all | array described in 3.1
|
||||
"fields" | yes | n/a | number bitwise-or'ed field
|
||||
| | | values from the table below
|
||||
"sort" | no | "id" | string "activity", "age", "id",
|
||||
| | | "name", "progress", "ratio",
|
||||
| | | "state", or "tracker".
|
||||
"ascending" | no | 'true' | 'boolean' true if sorting ascending
|
||||
"filter" | no | "all" | string "active", "all", "paused",
|
||||
| | | "downloading", or "seeding".
|
||||
|
||||
The response contains two arguments:
|
||||
|
||||
(1) A "fields" number identical to the request's
|
||||
(2) A "torrents" array of objects, each of which contains the
|
||||
key/value fields that match the "fields" argument.
|
||||
See the table below for a complete list.
|
||||
|
||||
"fields" value | response | response | source
|
||||
| value | key |
|
||||
-------------------+----------+------------------------+-------------
|
||||
activity, 1 | number | desiredAvailable | tr_stat
|
||||
| number | eta | tr_stat
|
||||
|
@ -113,12 +137,12 @@
|
|||
-------------------+----------+------------------------+-------------
|
||||
announce, 2 | string | announceResponse | tr_stat
|
||||
| string | announceURL | tr_stat
|
||||
| string | lastAnnounceTime | tr_stat
|
||||
| string | manualAnnounceTime | tr_stat
|
||||
| string | nextAnnounceTime | tr_stat
|
||||
| number | lastAnnounceTime | tr_stat
|
||||
| number | manualAnnounceTime | tr_stat
|
||||
| number | nextAnnounceTime | tr_stat
|
||||
-------------------+----------+------------------------+-------------
|
||||
error, 4 | number | error | tr_stat
|
||||
| number | errorString | tr_Stat
|
||||
| number | errorString | tr_stat
|
||||
-------------------+----------+------------------------+-------------
|
||||
files, 8 | array | files
|
||||
+----------+--------------------------------------
|
||||
|
@ -156,23 +180,34 @@
|
|||
| number | fromPex | tr_stat
|
||||
| number | fromTracker | tr_stat
|
||||
-------------------+----------+------------------------+-------------
|
||||
scrape, 512 | number | lastScrapeTime | tr_stat
|
||||
priorities, 512 | array | priorities | tr_info
|
||||
| array | wanted | tr_info
|
||||
+----------+--------------------------------------
|
||||
| priorities is an array of tr_info.fileCount
|
||||
| numbers. Each is the tr_priority_t mode for
|
||||
| the corresponding file.
|
||||
+-------------------------------------------------
|
||||
| wanted is an array of tr_info.fileCount
|
||||
| 'booleans' true if the corresponding file
|
||||
| is to be downloaded.
|
||||
-------------------+----------+------------------------+-------------
|
||||
scrape, 1024 | number | lastScrapeTime | tr_stat
|
||||
| number | nextScrapeTime | tr_stat
|
||||
| string | scrapeResponse | tr_stat
|
||||
| string | scrapeURL | tr_stat
|
||||
-------------------+----------+------------------------+-------------
|
||||
size, 1024 | number | haveUnchecked | tr_stat
|
||||
size, 2048 | number | haveUnchecked | tr_stat
|
||||
| number | haveValid | tr_stat
|
||||
| number | leftUntilDone | tr_stat
|
||||
| number | sizeWhenDone | tr_stat
|
||||
| number | totalSize | tr_info
|
||||
-------------------+----------+------------------------+-------------
|
||||
tracker stats, | number | leechers | tr_stat
|
||||
2048 | number | peersKnown | tr_stat
|
||||
4096 | number | peersKnown | tr_stat
|
||||
| number | seeders | tr_stat
|
||||
| number | timesCompleted | tr_stat
|
||||
-------------------+----------+--------------------------------------
|
||||
trackers, 4096 | array | trackers
|
||||
trackers, 8192 | array | trackers
|
||||
+----------+--------------------------------------
|
||||
| trackers is an array of objects that contain:
|
||||
+----------+------------------------+-------------
|
||||
|
@ -180,29 +215,28 @@
|
|||
| string | scrape | tr_info
|
||||
| number | tier | tr_info
|
||||
-------------------+----------+------------------------+-------------
|
||||
webseeds, 8192 | object | webseeds
|
||||
webseeds, 16384 | array | webseeds
|
||||
+----------+--------------------------------------
|
||||
| webseeds contains:
|
||||
| webseeds is an array of strings:
|
||||
+----------+------------------------+-------------
|
||||
| an array of weseed URL strings | tr_info
|
||||
| string | webseed URL | tr_info
|
||||
-------------------+----------+------------------------+-------------
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
Say we want to get the name and total size torrents 7 and 10.
|
||||
name is in the "id" section (32) and total size is in "size" (1024),
|
||||
so the "fields" argument will be 32 + 1024 == 1056.
|
||||
Say we want to get the name and total size of torrents #7 and #10.
|
||||
name is in the "id" section (32) and total size is in "size" (2048),
|
||||
so the "fields" argument will be 32 + 2048 == 2080.
|
||||
|
||||
Request:
|
||||
|
||||
{
|
||||
"arguments": {
|
||||
"fields": 1056,
|
||||
"fields": 2080,
|
||||
"ids": [ 7, 10 ],
|
||||
"sort-method": "name"
|
||||
}
|
||||
"method": "torrent-info",
|
||||
"method": "torrent-get",
|
||||
"tag": 39693
|
||||
}
|
||||
|
||||
|
@ -211,8 +245,8 @@
|
|||
|
||||
{
|
||||
"arguments": {
|
||||
"fields": 1056,
|
||||
"torrent-info": [
|
||||
"fields": 2080,
|
||||
"torrents": [
|
||||
{
|
||||
"hashString": "sijioejisoefjiosejfioi",
|
||||
"haveUnchecked", 23023,
|
||||
|
@ -239,7 +273,7 @@
|
|||
"tag": 39693
|
||||
}
|
||||
|
||||
3.3. Adding a Torrent
|
||||
3.2. Adding a Torrent
|
||||
|
||||
Method name: "torrent-add"
|
||||
|
||||
|
@ -247,11 +281,11 @@
|
|||
|
||||
key | value type & description
|
||||
-------------------+-------------------------------------------------
|
||||
"download-dir" | string path to download the torrent to
|
||||
"filename" | string location of the .torrent file
|
||||
"metainfo" | string base64-encoded .torrent content
|
||||
"paused" | boolean if true, don't start the torrent
|
||||
"peer-limit" | int maximum number of peers
|
||||
"download-dir" | string path to download the torrent to
|
||||
"filename" | string location of the .torrent file
|
||||
"metainfo" | string base64-encoded .torrent content
|
||||
"paused" | 'boolean' if true, don't start the torrent
|
||||
"peer-limit" | number maximum number of peers
|
||||
|
||||
Either "filename" OR "metainfo" must be included.
|
||||
All other arguments are optional.
|
||||
|
@ -260,66 +294,22 @@
|
|||
form of one of 3.3's tr_info objects with the
|
||||
fields for id, name, and hashString.
|
||||
|
||||
3.4. Other Torrent Settings
|
||||
|
||||
Common arguments:
|
||||
|
||||
string | value type & description
|
||||
---------------------------+-------------------------------------------------
|
||||
"peer-limit" | int maximum number of peers
|
||||
"speed-limit-down" | int maximum download speed (in KiB/s)
|
||||
"speed-limit-down-enabled" | boolean true if the download speed is limited
|
||||
"speed-limit-up" | int maximum upload speed (in KiB/s)
|
||||
"speed-limit-up-enabled" | boolean true if the upload speed is limited
|
||||
|
||||
3.4.1. Mutators
|
||||
|
||||
Method name: "torrent-set"
|
||||
Request arguments: 3.1's "ids", plus one or more of 3.6's arguments
|
||||
Response arguments: none
|
||||
|
||||
|
||||
3.5 File Priorities
|
||||
|
||||
Common arguments:
|
||||
|
||||
string | value type & description
|
||||
-------------------+-------------------------------------------------
|
||||
"files-wanted" | array indices of one or more file to download
|
||||
"files-unwanted" | array indices of one or more file to not download
|
||||
"priority-high" | array indices of one or more high-priority files
|
||||
"priority-low" | array indices of one or more low-priority files
|
||||
"priority-normal" | array indices of one or more normal-priority files
|
||||
|
||||
3.5.1. Mutators
|
||||
|
||||
Method name: "torrent-set-priorities"
|
||||
Request arguments: 3.1's "ids", plus one or more of 3.7's arguments
|
||||
Response arguments: none
|
||||
|
||||
3.5.2. Accessors
|
||||
|
||||
Method name: "torrent-get-priorities"
|
||||
Request arguments: none
|
||||
Response arguments: A "torrents" list of objects containing all
|
||||
of 3.7's arguments plus the torrent's "id" int.
|
||||
|
||||
4. Session Status Requests
|
||||
|
||||
4.1. Session Arguments
|
||||
|
||||
string | value type & description
|
||||
---------------------------+-------------------------------------------------
|
||||
"encryption" | string "required", "preferred", "tolerated"
|
||||
"download-dir" | string default path to download torrents
|
||||
"peer-limit" | int maximum global number of peers
|
||||
"pex-allowed" | boolean true means allow pex in public torrents
|
||||
"port" | int port number
|
||||
"port-forwarding-enabled" | boolean true means enabled
|
||||
"speed-limit-down" | int max global download speed (in KiB/s)
|
||||
"speed-limit-down-enabled" | boolean true means enabled
|
||||
"speed-limit-up" | int max global upload speed (in KiB/s)
|
||||
"speed-limit-up-enabled" | boolean true means enabled
|
||||
"encryption" | string "required", "preferred", "tolerated"
|
||||
"download-dir" | string default path to download torrents
|
||||
"peer-limit" | number maximum global number of peers
|
||||
"pex-allowed" | 'boolean' true means allow pex in public torrents
|
||||
"port" | number port number
|
||||
"port-forwarding-enabled" | 'boolean' true means enabled
|
||||
"speed-limit-down" | number max global download speed (in KiB/s)
|
||||
"speed-limit-down-enabled" | 'boolean' true means enabled
|
||||
"speed-limit-up" | number max global upload speed (in KiB/s)
|
||||
"speed-limit-up-enabled" | 'boolean' true means enabled
|
||||
|
||||
4.2. Mutators
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
static int
|
||||
compareTorrentsByActivity( const void * a, const void * b )
|
||||
{
|
||||
const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
|
||||
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
|
||||
int i;
|
||||
if(( i = tr_compareDouble( sa->rateUpload + sa->rateDownload,
|
||||
sb->rateUpload + sb->rateDownload ) ))
|
||||
|
@ -39,21 +39,25 @@ compareTorrentsByActivity( const void * a, const void * b )
|
|||
static int
|
||||
compareTorrentsByAge( const void * a, const void * b )
|
||||
{
|
||||
return tr_compareTime( tr_torrentStatCached( (tr_torrent*)a )->addedDate,
|
||||
tr_torrentStatCached( (tr_torrent*)b )->addedDate );
|
||||
const tr_torrent * ta = * (tr_torrent **) a;
|
||||
const tr_torrent * tb = * (tr_torrent **) b;
|
||||
return tr_compareTime( tr_torrentStatCached( ta )->addedDate,
|
||||
tr_torrentStatCached( tb )->addedDate );
|
||||
}
|
||||
|
||||
static int
|
||||
compareTorrentsByID( const void * a, const void * b )
|
||||
{
|
||||
return ((tr_torrent*)a)->uniqueId - ((tr_torrent*)b)->uniqueId;
|
||||
const tr_torrent * ta = * (tr_torrent **) a;
|
||||
const tr_torrent * tb = * (tr_torrent **) b;
|
||||
return ta->uniqueId - tb->uniqueId;
|
||||
}
|
||||
|
||||
static int
|
||||
compareTorrentsByName( const void * a, const void * b )
|
||||
{
|
||||
const tr_torrent * ta = a;
|
||||
const tr_torrent * tb = b;
|
||||
const tr_torrent * ta = * (tr_torrent **) a;
|
||||
const tr_torrent * tb = * (tr_torrent **) b;
|
||||
return tr_strcasecmp( ta->info.name, tb->info.name );
|
||||
}
|
||||
|
||||
|
@ -69,8 +73,8 @@ compareRatio( double a, double b )
|
|||
static int
|
||||
compareTorrentsByProgress( const void * a, const void * b )
|
||||
{
|
||||
const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
|
||||
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
|
||||
int ret = tr_compareDouble( sa->percentDone, sb->percentDone );
|
||||
if( !ret )
|
||||
ret = compareRatio( sa->ratio, sb->ratio );
|
||||
|
@ -80,16 +84,16 @@ compareTorrentsByProgress( const void * a, const void * b )
|
|||
static int
|
||||
compareTorrentsByRatio( const void * a, const void * b )
|
||||
{
|
||||
const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
|
||||
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
|
||||
return compareRatio( sa->ratio, sb->ratio );
|
||||
}
|
||||
|
||||
static int
|
||||
compareTorrentsByState( const void * a, const void * b )
|
||||
{
|
||||
const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
|
||||
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
|
||||
int ret = sa->status - sb->status;
|
||||
if( !ret )
|
||||
ret = compareTorrentsByRatio( a, b );
|
||||
|
@ -99,8 +103,8 @@ compareTorrentsByState( const void * a, const void * b )
|
|||
static int
|
||||
compareTorrentsByTracker( const void * a, const void * b )
|
||||
{
|
||||
const tr_stat * sa = tr_torrentStatCached( (tr_torrent*) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( (tr_torrent*) b );
|
||||
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
|
||||
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
|
||||
return tr_strcmp( sa->announceURL, sb->announceURL );
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ getTorrents( tr_handle * handle, tr_benc * args, int * setmeCount )
|
|||
|
||||
method = TR_SORT_ID;
|
||||
sortAscending = 1;
|
||||
tr_bencDictFindInt( args, "sort-ascending", &sortAscending );
|
||||
tr_bencDictFindInt( args, "ascending", &sortAscending );
|
||||
if( tr_bencDictFindStr( args, "sort", &str ) ) {
|
||||
if( !strcmp( str, "activity" ) ) method = TR_SORT_ACTIVITY;
|
||||
else if( !strcmp( str, "age" ) ) method = TR_SORT_AGE;
|
||||
|
@ -313,6 +313,16 @@ addInfo( const tr_torrent * tor, tr_benc * d, uint64_t fields )
|
|||
tr_bencDictAddInt( d, "fromTracker", f[TR_PEER_FROM_TRACKER] );
|
||||
}
|
||||
|
||||
if( fields & TR_RPC_TORRENT_FIELD_PRIORITIES ) {
|
||||
tr_file_index_t i;
|
||||
tr_benc * p = tr_bencDictAddList( d, "priorities", inf->fileCount );
|
||||
tr_benc * w = tr_bencDictAddList( d, "wanted", inf->fileCount );
|
||||
for( i=0; i<inf->fileCount; ++i ) {
|
||||
tr_bencListAddInt( p, inf->files[i].priority );
|
||||
tr_bencListAddInt( w, inf->files[i].dnd ? 0 : 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( fields & TR_RPC_TORRENT_FIELD_SCRAPE ) {
|
||||
tr_bencDictAddInt( d, "lastScrapeTime", st->lastScrapeTime );
|
||||
tr_bencDictAddInt( d, "nextScrapeTime", st->nextScrapeTime );
|
||||
|
@ -343,11 +353,11 @@ addInfo( const tr_torrent * tor, tr_benc * d, uint64_t fields )
|
|||
}
|
||||
|
||||
static const char*
|
||||
torrentInfo( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
|
||||
torrentGet( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
|
||||
{
|
||||
int i, torrentCount;
|
||||
tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount );
|
||||
tr_benc * list = tr_bencDictAddList( args_out, "torrent-info", torrentCount );
|
||||
tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount );
|
||||
int64_t fields = 0;
|
||||
|
||||
if( !tr_bencDictFindInt( args_in, "fields", &fields ) )
|
||||
|
@ -365,109 +375,6 @@ torrentInfo( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
|
|||
****
|
||||
***/
|
||||
|
||||
static const char*
|
||||
torrentSet( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
|
||||
{
|
||||
int i, torrentCount;
|
||||
tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount );
|
||||
|
||||
for( i=0; i<torrentCount; ++i )
|
||||
{
|
||||
int64_t tmp;
|
||||
tr_torrent * tor = torrents[i];
|
||||
if( tr_bencDictFindInt( args_in, "peer-limit", &tmp ) )
|
||||
tr_torrentSetPeerLimit( tor, tmp );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-down", &tmp ) )
|
||||
tr_torrentSetSpeedLimit( tor, TR_DOWN, tmp );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &tmp ) )
|
||||
tr_torrentSetSpeedMode( tor, TR_DOWN, tmp ? TR_SPEEDLIMIT_SINGLE
|
||||
: TR_SPEEDLIMIT_GLOBAL );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-up", &tmp ) )
|
||||
tr_torrentSetSpeedLimit( tor, TR_UP, tmp );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &tmp ) )
|
||||
tr_torrentSetSpeedMode( tor, TR_UP, tmp ? TR_SPEEDLIMIT_SINGLE
|
||||
: TR_SPEEDLIMIT_GLOBAL );
|
||||
notify( h, TR_RPC_TORRENT_CHANGED, tor );
|
||||
}
|
||||
|
||||
tr_free( torrents );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedef int( *fileTestFunc )( const tr_torrent * tor, int i );
|
||||
|
||||
static int
|
||||
testFileHigh( const tr_torrent * tor, int i )
|
||||
{
|
||||
return tor->info.files[i].priority == TR_PRI_HIGH;
|
||||
}
|
||||
static int
|
||||
testFileLow( const tr_torrent * tor, int i )
|
||||
{
|
||||
return tor->info.files[i].priority == TR_PRI_LOW;
|
||||
}
|
||||
static int
|
||||
testFileNormal( const tr_torrent * tor, int i )
|
||||
{
|
||||
return tor->info.files[i].priority == TR_PRI_NORMAL;
|
||||
}
|
||||
static int
|
||||
testFileDND( const tr_torrent * tor, int i )
|
||||
{
|
||||
return tor->info.files[i].dnd != 0;
|
||||
}
|
||||
static int
|
||||
testFileDownload( const tr_torrent * tor, int i )
|
||||
{
|
||||
return tor->info.files[i].dnd == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
buildFileList( const tr_torrent * tor, tr_benc * dict,
|
||||
const char * key, fileTestFunc func )
|
||||
{
|
||||
int i;
|
||||
const int n = tor->info.fileCount;
|
||||
tr_benc * list;
|
||||
int * files = tr_new0( int, n );
|
||||
int fileCount = 0;
|
||||
|
||||
for( i=0; i<n; ++i )
|
||||
if( func( tor, i ) )
|
||||
files[fileCount++] = i;
|
||||
|
||||
list = tr_bencDictAddList( dict, key, fileCount );
|
||||
|
||||
for( i=0; i<fileCount; ++i )
|
||||
tr_bencListAddInt( list, files[i] );
|
||||
|
||||
tr_free( files );
|
||||
}
|
||||
|
||||
static const char*
|
||||
torrentGetPriorities( tr_handle * handle,
|
||||
tr_benc * args_in, tr_benc * args_out )
|
||||
{
|
||||
int i, torrentCount;
|
||||
tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount );
|
||||
tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount );
|
||||
|
||||
for( i=0; i<torrentCount; ++i )
|
||||
{
|
||||
const tr_torrent * tor = torrents[i];
|
||||
tr_benc * d = tr_bencListAddDict( list, 6 );
|
||||
tr_bencDictAddInt( d, "id", tr_torrentId( tor ) );
|
||||
buildFileList( tor, d, "files-unwanted", testFileDND );
|
||||
buildFileList( tor, d, "files-wanted", testFileDownload );
|
||||
buildFileList( tor, d, "priority-low", testFileLow );
|
||||
buildFileList( tor, d, "priority-normal", testFileNormal );
|
||||
buildFileList( tor, d, "priority-high", testFileHigh );
|
||||
}
|
||||
|
||||
tr_free( torrents );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
setFilePriorities( tr_torrent * tor, int priority, tr_benc * list )
|
||||
{
|
||||
|
@ -507,14 +414,14 @@ setFileDLs( tr_torrent * tor, int do_download, tr_benc * list )
|
|||
}
|
||||
|
||||
static const char*
|
||||
torrentSetPriorities( tr_handle * h,
|
||||
tr_benc * args_in, tr_benc * args_out UNUSED )
|
||||
torrentSet( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
|
||||
{
|
||||
int i, torrentCount;
|
||||
tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount );
|
||||
|
||||
for( i=0; i<torrentCount; ++i )
|
||||
{
|
||||
int64_t tmp;
|
||||
tr_benc * files;
|
||||
tr_torrent * tor = torrents[i];
|
||||
|
||||
|
@ -522,12 +429,24 @@ torrentSetPriorities( tr_handle * h,
|
|||
setFileDLs( tor, FALSE, files );
|
||||
if( tr_bencDictFindList( args_in, "files-wanted", &files ) )
|
||||
setFileDLs( tor, TRUE, files );
|
||||
if( tr_bencDictFindInt( args_in, "peer-limit", &tmp ) )
|
||||
tr_torrentSetPeerLimit( tor, tmp );
|
||||
if( tr_bencDictFindList( args_in, "priority-high", &files ) )
|
||||
setFilePriorities( tor, TR_PRI_HIGH, files );
|
||||
if( tr_bencDictFindList( args_in, "priority-low", &files ) )
|
||||
setFilePriorities( tor, TR_PRI_LOW, files );
|
||||
if( tr_bencDictFindList( args_in, "priority-normal", &files ) )
|
||||
setFilePriorities( tor, TR_PRI_NORMAL, files );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-down", &tmp ) )
|
||||
tr_torrentSetSpeedLimit( tor, TR_DOWN, tmp );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &tmp ) )
|
||||
tr_torrentSetSpeedMode( tor, TR_DOWN, tmp ? TR_SPEEDLIMIT_SINGLE
|
||||
: TR_SPEEDLIMIT_GLOBAL );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-up", &tmp ) )
|
||||
tr_torrentSetSpeedLimit( tor, TR_UP, tmp );
|
||||
if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &tmp ) )
|
||||
tr_torrentSetSpeedMode( tor, TR_UP, tmp ? TR_SPEEDLIMIT_SINGLE
|
||||
: TR_SPEEDLIMIT_GLOBAL );
|
||||
|
||||
notify( h, TR_RPC_TORRENT_CHANGED, tor );
|
||||
}
|
||||
|
@ -684,10 +603,8 @@ struct method {
|
|||
{ "session-get", sessionGet },
|
||||
{ "session-set", sessionSet },
|
||||
{ "torrent-add", torrentAdd },
|
||||
{ "torrent-get-priorities", torrentGetPriorities },
|
||||
{ "torrent-info", torrentInfo },
|
||||
{ "torrent-get", torrentGet },
|
||||
{ "torrent-remove", torrentRemove },
|
||||
{ "torrent-set-priorities", torrentSetPriorities },
|
||||
{ "torrent-set", torrentSet },
|
||||
{ "torrent-start", torrentStart },
|
||||
{ "torrent-stop", torrentStop },
|
||||
|
|
|
@ -28,11 +28,12 @@ enum
|
|||
TR_RPC_TORRENT_FIELD_INFO = (1<<6),
|
||||
TR_RPC_TORRENT_FIELD_LIMITS = (1<<7),
|
||||
TR_RPC_TORRENT_FIELD_PEERS = (1<<8),
|
||||
TR_RPC_TORRENT_FIELD_SCRAPE = (1<<9),
|
||||
TR_RPC_TORRENT_FIELD_SIZE = (1<<10),
|
||||
TR_RPC_TORRENT_FIELD_TRACKER_STATS = (1<<11),
|
||||
TR_RPC_TORRENT_FIELD_TRACKERS = (1<<12),
|
||||
TR_RPC_TORRENT_FIELD_WEBSEEDS = (1<<13)
|
||||
TR_RPC_TORRENT_FIELD_PRIORITIES = (1<<9),
|
||||
TR_RPC_TORRENT_FIELD_SCRAPE = (1<<10),
|
||||
TR_RPC_TORRENT_FIELD_SIZE = (1<<11),
|
||||
TR_RPC_TORRENT_FIELD_TRACKER_STATS = (1<<12),
|
||||
TR_RPC_TORRENT_FIELD_TRACKERS = (1<<13),
|
||||
TR_RPC_TORRENT_FIELD_WEBSEEDS = (1<<14)
|
||||
};
|
||||
|
||||
struct tr_benc;
|
||||
|
|
Loading…
Reference in a new issue