Changeset 5827
- Timestamp:
- May 12, 2008, 11:51:17 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/rpc-json-spec.txt
r5819 r5827 19 19 booleans are represented as integers where 0 is false and 1 is true. 20 20 21 There are only two message types: request and response. Both 22 are JSON objects with two members: "headers" (described in 2.1) 23 and "body" (described in 2.2 - 2.3). 24 25 2.1. Headers 26 27 Message headers support two members: 28 (1) A required "type" string whose value must be "request" or "response". 29 (2) An optional "tag" integer supplied by requests for their own use. 30 Responses MUST include the request tag's verbatim. 31 32 2.2. Request Body 33 34 Request bodies support two members: 35 (1) A required "name" string telling the name of the request. 36 (2) An optional "arguments" object of name/value pairs. 37 38 2.3. Response Body 39 40 All response bodies support two members: 21 Messages are represented as a JSON objects. There are two types: 22 requests (described in 2.1) and responses (described in 2.2). 23 24 2.1. Requests 25 26 Requests supports three keys: 27 28 (1) A required "method" string telling the name of the method to invoke 29 (2) An optional "arguments" object of name/value pairs 30 (3) An optional "tag" integer used for clients to track responses. 31 If provided by a request, the response MUST include the same tag. 32 33 2.2. Responses 34 35 Reponses support three keys: 36 41 37 (1) A required "result" string whose value must be "success" on success, 42 and may be "no-permission", "bad-format", or "error"on failure.43 (2) An optional "arguments" object of name/value pairs .44 The contents of these arguments depend on the request's name.38 or an error string on failure. 39 (2) An optional "arguments" object of name/value pairs 40 (3) An optional "tag" integer as described in 2.1. 45 41 46 42 3. Torrent Requests … … 48 44 3.1. Torrent Action Requests 49 45 50 Request names: "torrent-start", "torrent-stop", 51 "torrent-remove", "torrent-verify" 46 Method names: "torrent-start", "torrent-stop", 47 "torrent-remove", "torrent-verify" 48 52 49 Request arguments: "ids", a list of unique torrent ids, sha1 hash strings, 53 50 or both. These are the torrents that the request will 54 51 be applied to. If "ids" is ommitted, the request is 55 52 applied to all torrents. 53 56 54 Response arguments: none. 57 55 58 56 3.2. Torrent Info Requests 59 57 60 Request name: "torrent-info". 58 Method name: "torrent-info". 59 61 60 Request arguments: 3.1's optional "ids" argument. 62 61 … … 71 70 72 71 { 73 "headers": { 74 "type": "request", 75 "tag": 666 76 }, 77 "body": { 78 "name": "torrent-info", 79 "arguments": { 80 "ids": [ 7, 10 ] 81 } 72 "arguments": { "ids": [ 7, 10 ] } 73 "method": "torrent-info", 74 "tag": 666 75 } 76 77 Example Response: 78 79 { 80 "tag": 666 81 "result": "success", 82 "arguments": { 83 "info": [ 84 { 85 "id": 7, 86 "totalSize": 9803930483, 87 "pieceCount": 1209233, 88 "pieceSize": 4096, 89 "name": "Ubuntu x86_64 DVD", 90 ... 91 }, 92 { 93 "id": 10, 94 "totalSize": 2398480394, 95 "pieceCount": 83943, 96 "pieceSize": 12345, 97 "name": "Ubuntu i386 DVD", 98 ... 99 } 100 ] 82 101 } 83 102 } 84 103 85 Example Response:86 87 {88 "headers": {89 "type": "response",90 "tag": 66691 }92 "body": {93 "result": "success",94 "arguments": {95 "info": [96 {97 "id": 7,98 "totalSize": 9803930483,99 "pieceCount": 1209233,100 "pieceSize": 4096,101 "name": "Ubuntu x86_64 DVD",102 ...103 }104 {105 "id": 10,106 "totalSize": 2398480394,107 "pieceCount": 83943,108 "pieceSize": 12345,109 "name": "Ubuntu i386 DVD",110 ...111 }112 ]113 }114 }115 }116 117 104 3.3. Torrent Status Requests 118 105 119 Request name is "torrent-status". 106 Method name: "torrent-status" 107 120 108 Request arguments: 3.1's optional "ids" argument. 121 109 … … 129 117 3.4. Adding a Torrent 130 118 131 Request name: "torrent-add" 119 Method name: "torrent-add" 120 132 121 Request arguments: 133 122 134 123 string | value type & description 135 124 -------------------+------------------------------------------------- 136 " autostart" | boolean true means to auto-start torrents125 "paused" | boolean if true, don't start the torrent 137 126 "destination" | string path to download the torrent to 138 127 "filename" | string location of the .torrent file … … 148 137 Common arguments: 149 138 150 string | value type & description 151 -------------------+------------------------------------------------- 152 "peer-limit" | int maximum number of peers 153 "speed-limit-down" | int maximum download speed (in KiB/s) 154 "speed-limit-up" | int maximum upload speed (in KiB/s) 139 string | value type & description 140 ---------------------------+------------------------------------------------- 141 "peer-limit" | int maximum number of peers 142 "speed-limit-down" | int maximum download speed (in KiB/s) 143 "speed-limit-down-enabled" | boolean true if the download speed is limited 144 "speed-limit-up" | int maximum upload speed (in KiB/s) 145 "speed-limit-up-enabled" | boolean true if the upload speed is limited 155 146 156 147 3.5.1. Mutators 157 148 158 Requestname: "torrent-set"149 Method name: "torrent-set" 159 150 Request arguments: 3.1's "ids", plus one or more of 3.5's arguments 160 151 Response arguments: none … … 162 153 3.5.2. Accessors 163 154 164 Requestname: "torrent-get"155 Method name: "torrent-get" 165 156 Request arguments: none 166 157 Response arguments: A "torrents" list of objects containing all … … 182 173 3.6.1. Mutators 183 174 184 Requestname: "torrent-set-file"175 Method name: "torrent-set-file" 185 176 Request arguments: 3.1's "ids", plus one or more of 3.6's arguments 186 177 Response arguments: none … … 188 179 3.6.2. Accessors 189 180 190 Requestname: "torrent-get-file"181 Method name: "torrent-get-file" 191 182 Request arguments: none 192 183 Response arguments: A "torrents" list of objects containing all … … 211 202 4.2. Mutators 212 203 213 Requestname: "session-set"204 Method name: "session-set" 214 205 Request arguments: one or more of 4.1's arguments 215 206 Response arguments: none … … 217 208 4.2. Accessors 218 209 219 Requestname: "session-get"210 Method name: "session-get" 220 211 Request arguments: none 221 212 Response arguments: all of 4.1's arguments -
trunk/libtransmission/Makefile.am
r5813 r5827 17 17 handshake.c \ 18 18 inout.c \ 19 ipc.c \20 19 ipcparse.c \ 21 20 json.c \ … … 34 33 ratecontrol.c \ 35 34 resume.c \ 35 rpc.c \ 36 36 session.c \ 37 37 stats.c \ … … 58 58 handshake.h \ 59 59 inout.h \ 60 ipc.h \61 60 ipcparse.h \ 62 61 list.h \ … … 75 74 ratecontrol.h \ 76 75 resume.h \ 76 rpc.h \ 77 77 session.h \ 78 78 stats.h \ -
trunk/libtransmission/rpc.c
r5819 r5827 16 16 #include "transmission.h" 17 17 #include "bencode.h" 18 #include " ipc.h"18 #include "rpc.h" 19 19 #include "torrent.h" 20 20 #include "utils.h" … … 246 246 { 247 247 tr_torrent * tor = torrents[i]; 248 tr_benc * d = tr_bencListAddDict( list, 4);248 tr_benc * d = tr_bencListAddDict( list, 6 ); 249 249 tr_bencDictAddInt( d, "id", tor->uniqueId ); 250 250 tr_bencDictAddInt( d, "peer-limit", … … 252 252 tr_bencDictAddInt( d, "speed-limit-down", 253 253 tr_torrentGetSpeedLimit( tor, TR_DOWN ) ); 254 tr_bencDictAddInt( d, "speed-limit-down-enabled", 255 tr_torrentGetSpeedMode( tor, TR_DOWN ) 256 == TR_SPEEDLIMIT_SINGLE ); 254 257 tr_bencDictAddInt( d, "speed-limit-up", 255 258 tr_torrentGetSpeedLimit( tor, TR_UP ) ); 259 tr_bencDictAddInt( d, "speed-limit-up-enabled", 260 tr_torrentGetSpeedMode( tor, TR_UP ) 261 == TR_SPEEDLIMIT_SINGLE ); 256 262 } 257 263 … … 274 280 if( tr_bencDictFindInt( args_in, "speed-limit-down", &tmp ) ) 275 281 tr_torrentSetSpeedLimit( tor, TR_DOWN, tmp ); 282 if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &tmp ) ) 283 tr_torrentSetSpeedMode( tor, TR_DOWN, tmp ? TR_SPEEDLIMIT_SINGLE 284 : TR_SPEEDLIMIT_GLOBAL ); 276 285 if( tr_bencDictFindInt( args_in, "speed-limit-up", &tmp ) ) 277 286 tr_torrentSetSpeedLimit( tor, TR_UP, tmp ); 287 if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &tmp ) ) 288 tr_torrentSetSpeedMode( tor, TR_UP, tmp ? TR_SPEEDLIMIT_SINGLE 289 : TR_SPEEDLIMIT_GLOBAL ); 278 290 } 279 291 … … 439 451 ctor = tr_ctorNew( h ); 440 452 tr_ctorSetMetainfoFromFile( ctor, filename ); 441 if( tr_bencDictFindInt( args_in, " autostart", &i ) )442 tr_ctorSetPaused( ctor, TR_FORCE, !i );453 if( tr_bencDictFindInt( args_in, "paused", &i ) ) 454 tr_ctorSetPaused( ctor, TR_FORCE, i ); 443 455 if( tr_bencDictFindInt( args_in, "peer-limit", &i ) ) 444 456 tr_ctorSetPeerLimit( ctor, TR_FORCE, i ); … … 539 551 struct request_handler 540 552 { 541 const char * name;553 const char * method; 542 554 handler * func; 543 555 } request_handlers[] = { … … 566 578 char * out; 567 579 tr_benc response; 568 tr_benc * headers_in = NULL; 569 tr_benc * body_in = NULL; 570 tr_benc * args_in = NULL; 571 tr_benc * headers_out = NULL; 572 tr_benc * body_out = NULL; 580 tr_benc * args_in = tr_bencDictFind( request, "args" ); 573 581 tr_benc * args_out = NULL; 574 582 const char * result = NULL; 575 583 576 headers_in = tr_bencDictFind( request, "headers" );577 body_in = tr_bencDictFind( request, "body" );578 args_in = tr_bencDictFind( body_in, "args" );579 580 584 /* build the response skeleton */ 581 tr_bencInitDict( &response, 2 ); 582 headers_out = tr_bencDictAddDict( &response, "headers", 2 ); 583 tr_bencDictAddStr( headers_out, "type", "response" ); 584 if( tr_bencDictFindInt( headers_in, "tag", &i ) ) 585 tr_bencDictAddInt( headers_out, "tag", i ); 586 body_out = tr_bencDictAddDict( &response, "body", 2 ); 587 args_out = tr_bencDictAddDict( body_out, "args", 0 ); 585 tr_bencInitDict( &response, 3 ); 586 if( tr_bencDictFindInt( request, "tag", &i ) ) 587 tr_bencDictAddInt( request, "tag", i ); 588 args_out = tr_bencDictAddDict( &response, "args", 0 ); 588 589 589 590 /* parse the request */ 590 if( !tr_bencDictFindStr( body_in, "name", &str ) )591 result = "no request name given";591 if( !tr_bencDictFindStr( request, "method", &str ) ) 592 result = "no method name"; 592 593 else { 593 594 const int n = TR_N_ELEMENTS( request_handlers ); 594 595 for( i=0; i<n; ++i ) 595 if( !strcmp( str, request_handlers[i]. name) )596 if( !strcmp( str, request_handlers[i].method ) ) 596 597 break; 597 598 result = i==n 598 ? " requestname not recognized"599 ? "method name not recognized" 599 600 : (*request_handlers[i].func)( handle, args_in, args_out ); 600 601 } … … 602 603 /* serialize & return the response */ 603 604 if( !result ) 604 result = "success";605 tr_bencDictAddStr( body_out, "result", result );606 out = tr_bencSave ( &response, response_len ); /* TODO: json, not benc */605 result = "success"; 606 tr_bencDictAddStr( &response, "result", result ); 607 out = tr_bencSaveAsJSON( &response, response_len ); 607 608 tr_bencFree( &response ); 608 609 return out; … … 610 611 611 612 char* 612 tr_ ipc_request_exec( struct tr_handle * handle,613 tr_rpc_request_exec( struct tr_handle * handle, 613 614 const void * request_json, 614 615 int request_len, -
trunk/libtransmission/rpc.h
r5817 r5827 11 11 */ 12 12 13 #ifndef TR_ IPC_H14 #define TR_ IPC_H13 #ifndef TR_RPC_H 14 #define TR_RPC_H 15 15 16 16 struct tr_handle; 17 17 18 18 char* 19 tr_ ipc_request_exec( struct tr_handle * handle,19 tr_rpc_request_exec( struct tr_handle * handle, 20 20 const void * request_json, 21 21 int request_len,
Note: See TracChangeset
for help on using the changeset viewer.