1 | /* |
---|
2 | * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com> |
---|
3 | * |
---|
4 | * This file is licensed by the GPL version 2. Works owned by the |
---|
5 | * Transmission project are granted a special exemption to clause 2(b) |
---|
6 | * so that the bulk of its code can remain under the MIT license. |
---|
7 | * This exemption does not extend to derived works not owned by |
---|
8 | * the Transmission project. |
---|
9 | * |
---|
10 | * $Id: rpcimpl.c 7178 2008-11-29 17:19:06Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #include <assert.h> |
---|
14 | #include <ctype.h> /* isdigit */ |
---|
15 | #include <stdlib.h> /* strtol */ |
---|
16 | #include <string.h> /* strcmp */ |
---|
17 | |
---|
18 | #include "transmission.h" |
---|
19 | #include "bencode.h" |
---|
20 | #include "rpcimpl.h" |
---|
21 | #include "json.h" |
---|
22 | #include "session.h" |
---|
23 | #include "torrent.h" |
---|
24 | #include "utils.h" |
---|
25 | |
---|
26 | #define TR_N_ELEMENTS( ary ) ( sizeof( ary ) / sizeof( *ary ) ) |
---|
27 | |
---|
28 | /*** |
---|
29 | **** |
---|
30 | ***/ |
---|
31 | |
---|
32 | static tr_rpc_callback_status |
---|
33 | notify( tr_handle * session, |
---|
34 | int type, |
---|
35 | tr_torrent * tor ) |
---|
36 | { |
---|
37 | tr_rpc_callback_status status = 0; |
---|
38 | |
---|
39 | if( session->rpc_func ) |
---|
40 | status = session->rpc_func( session, type, tor, |
---|
41 | session->rpc_func_user_data ); |
---|
42 | |
---|
43 | return status; |
---|
44 | } |
---|
45 | |
---|
46 | /*** |
---|
47 | **** |
---|
48 | ***/ |
---|
49 | |
---|
50 | static tr_torrent ** |
---|
51 | getTorrents( tr_handle * handle, |
---|
52 | tr_benc * args, |
---|
53 | int * setmeCount ) |
---|
54 | { |
---|
55 | int torrentCount = 0; |
---|
56 | int64_t id; |
---|
57 | tr_torrent ** torrents = NULL; |
---|
58 | tr_benc * ids; |
---|
59 | |
---|
60 | if( tr_bencDictFindList( args, "ids", &ids ) ) |
---|
61 | { |
---|
62 | int i; |
---|
63 | const int n = tr_bencListSize( ids ); |
---|
64 | |
---|
65 | torrents = tr_new0( tr_torrent *, n ); |
---|
66 | |
---|
67 | for( i = 0; i < n; ++i ) |
---|
68 | { |
---|
69 | tr_torrent * tor = NULL; |
---|
70 | tr_benc * node = tr_bencListChild( ids, i ); |
---|
71 | int64_t id; |
---|
72 | const char * str; |
---|
73 | if( tr_bencGetInt( node, &id ) ) |
---|
74 | tor = tr_torrentFindFromId( handle, id ); |
---|
75 | else if( tr_bencGetStr( node, &str ) ) |
---|
76 | tor = tr_torrentFindFromHashString( handle, str ); |
---|
77 | if( tor ) |
---|
78 | torrents[torrentCount++] = tor; |
---|
79 | } |
---|
80 | } |
---|
81 | else if( tr_bencDictFindInt( args, "ids", &id ) |
---|
82 | || tr_bencDictFindInt( args, "id", &id ) ) |
---|
83 | { |
---|
84 | tr_torrent * tor; |
---|
85 | torrents = tr_new0( tr_torrent *, 1 ); |
---|
86 | if( ( tor = tr_torrentFindFromId( handle, id ) ) ) |
---|
87 | torrents[torrentCount++] = tor; |
---|
88 | } |
---|
89 | else /* all of them */ |
---|
90 | { |
---|
91 | tr_torrent * tor = NULL; |
---|
92 | const int n = tr_sessionCountTorrents( handle ); |
---|
93 | torrents = tr_new0( tr_torrent *, n ); |
---|
94 | while( ( tor = tr_torrentNext( handle, tor ) ) ) |
---|
95 | torrents[torrentCount++] = tor; |
---|
96 | } |
---|
97 | |
---|
98 | *setmeCount = torrentCount; |
---|
99 | return torrents; |
---|
100 | } |
---|
101 | |
---|
102 | static const char* |
---|
103 | torrentStart( tr_handle * h, |
---|
104 | tr_benc * args_in, |
---|
105 | tr_benc * args_out UNUSED ) |
---|
106 | { |
---|
107 | int i, torrentCount; |
---|
108 | tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); |
---|
109 | |
---|
110 | for( i = 0; i < torrentCount; ++i ) |
---|
111 | { |
---|
112 | tr_torrent * tor = torrents[i]; |
---|
113 | tr_torrentStart( tor ); |
---|
114 | notify( h, TR_RPC_TORRENT_STARTED, tor ); |
---|
115 | } |
---|
116 | tr_free( torrents ); |
---|
117 | return NULL; |
---|
118 | } |
---|
119 | |
---|
120 | static const char* |
---|
121 | torrentStop( tr_handle * h, |
---|
122 | tr_benc * args_in, |
---|
123 | tr_benc * args_out UNUSED ) |
---|
124 | { |
---|
125 | int i, torrentCount; |
---|
126 | tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); |
---|
127 | |
---|
128 | for( i = 0; i < torrentCount; ++i ) |
---|
129 | { |
---|
130 | tr_torrent * tor = torrents[i]; |
---|
131 | tr_torrentStop( tor ); |
---|
132 | notify( h, TR_RPC_TORRENT_STOPPED, tor ); |
---|
133 | } |
---|
134 | tr_free( torrents ); |
---|
135 | return NULL; |
---|
136 | } |
---|
137 | |
---|
138 | static const char* |
---|
139 | torrentRemove( tr_handle * h, |
---|
140 | tr_benc * args_in, |
---|
141 | tr_benc * args_out UNUSED ) |
---|
142 | { |
---|
143 | int i, torrentCount; |
---|
144 | tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); |
---|
145 | |
---|
146 | for( i = 0; i < torrentCount; ++i ) |
---|
147 | { |
---|
148 | tr_torrent * tor = torrents[i]; |
---|
149 | const tr_rpc_callback_status status = notify( |
---|
150 | h, TR_RPC_TORRENT_REMOVING, tor ); |
---|
151 | if( !( status & TR_RPC_NOREMOVE ) ) |
---|
152 | tr_torrentRemove( tor ); |
---|
153 | } |
---|
154 | tr_free( torrents ); |
---|
155 | return NULL; |
---|
156 | } |
---|
157 | |
---|
158 | static const char* |
---|
159 | torrentVerify( tr_handle * h, |
---|
160 | tr_benc * args_in, |
---|
161 | tr_benc * args_out UNUSED ) |
---|
162 | { |
---|
163 | int i, torrentCount; |
---|
164 | tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); |
---|
165 | |
---|
166 | for( i = 0; i < torrentCount; ++i ) |
---|
167 | { |
---|
168 | tr_torrent * tor = torrents[i]; |
---|
169 | tr_torrentVerify( tor ); |
---|
170 | notify( h, TR_RPC_TORRENT_CHANGED, tor ); |
---|
171 | } |
---|
172 | tr_free( torrents ); |
---|
173 | return NULL; |
---|
174 | } |
---|
175 | |
---|
176 | /*** |
---|
177 | **** |
---|
178 | ***/ |
---|
179 | |
---|
180 | static void |
---|
181 | addFiles( const tr_torrent * tor, |
---|
182 | tr_benc * list ) |
---|
183 | { |
---|
184 | tr_file_index_t i; |
---|
185 | tr_file_index_t n; |
---|
186 | const tr_info * info = tr_torrentInfo( tor ); |
---|
187 | tr_file_stat * files = tr_torrentFiles( tor, &n ); |
---|
188 | |
---|
189 | for( i = 0; i < info->fileCount; ++i ) |
---|
190 | { |
---|
191 | const tr_file * file = &info->files[i]; |
---|
192 | tr_benc * d = tr_bencListAddDict( list, 3 ); |
---|
193 | tr_bencDictAddInt( d, "bytesCompleted", files[i].bytesCompleted ); |
---|
194 | tr_bencDictAddInt( d, "length", file->length ); |
---|
195 | tr_bencDictAddStr( d, "name", file->name ); |
---|
196 | } |
---|
197 | |
---|
198 | tr_torrentFilesFree( files, n ); |
---|
199 | } |
---|
200 | |
---|
201 | static void |
---|
202 | addWebseeds( const tr_info * info, |
---|
203 | tr_benc * webseeds ) |
---|
204 | { |
---|
205 | int i; |
---|
206 | |
---|
207 | for( i = 0; i < info->webseedCount; ++i ) |
---|
208 | tr_bencListAddStr( webseeds, info->webseeds[i] ); |
---|
209 | } |
---|
210 | |
---|
211 | static void |
---|
212 | addTrackers( const tr_info * info, |
---|
213 | tr_benc * trackers ) |
---|
214 | { |
---|
215 | int i; |
---|
216 | |
---|
217 | for( i = 0; i < info->trackerCount; ++i ) |
---|
218 | { |
---|
219 | const tr_tracker_info * t = &info->trackers[i]; |
---|
220 | tr_benc * d = tr_bencListAddDict( trackers, 3 ); |
---|
221 | tr_bencDictAddStr( d, "announce", t->announce ); |
---|
222 | tr_bencDictAddStr( d, "scrape", t->scrape ); |
---|
223 | tr_bencDictAddInt( d, "tier", t->tier ); |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | static void |
---|
228 | addPeers( const tr_torrent * tor, |
---|
229 | tr_benc * list ) |
---|
230 | { |
---|
231 | int i; |
---|
232 | int peerCount; |
---|
233 | tr_peer_stat * peers = tr_torrentPeers( tor, &peerCount ); |
---|
234 | |
---|
235 | tr_bencInitList( list, peerCount ); |
---|
236 | |
---|
237 | for( i = 0; i < peerCount; ++i ) |
---|
238 | { |
---|
239 | tr_benc * d = tr_bencListAddDict( list, 14 ); |
---|
240 | const tr_peer_stat * peer = peers + i; |
---|
241 | tr_bencDictAddStr( d, "address", peer->addr ); |
---|
242 | tr_bencDictAddStr( d, "clientName", peer->client ); |
---|
243 | tr_bencDictAddInt( d, "clientIsChoked", peer->clientIsChoked ); |
---|
244 | tr_bencDictAddInt( d, "clientIsInterested", |
---|
245 | peer->clientIsInterested ); |
---|
246 | tr_bencDictAddStr( d, "flagStr", peer->flagStr ); |
---|
247 | tr_bencDictAddInt( d, "isDownloadingFrom", peer->isDownloadingFrom ); |
---|
248 | tr_bencDictAddInt( d, "isEncrypted", peer->isEncrypted ); |
---|
249 | tr_bencDictAddInt( d, "isIncoming", peer->isIncoming ); |
---|
250 | tr_bencDictAddInt( d, "isUploadingTo", peer->isUploadingTo ); |
---|
251 | tr_bencDictAddInt( d, "peerIsChoked", peer->peerIsChoked ); |
---|
252 | tr_bencDictAddInt( d, "peerIsInterested", peer->peerIsInterested ); |
---|
253 | tr_bencDictAddInt( d, "port", peer->port ); |
---|
254 | tr_bencDictAddDouble( d, "progress", peer->progress ); |
---|
255 | tr_bencDictAddInt( d, "rateToClient", |
---|
256 | (int)( peer->rateToClient * 1024.0 ) ); |
---|
257 | tr_bencDictAddInt( d, "rateToPeer", |
---|
258 | (int)( peer->rateToPeer * 1024.0 ) ); |
---|
259 | } |
---|
260 | |
---|
261 | tr_torrentPeersFree( peers, peerCount ); |
---|
262 | } |
---|
263 | |
---|
264 | static void |
---|
265 | addField( const tr_torrent * tor, |
---|
266 | tr_benc * d, |
---|
267 | const char * key ) |
---|
268 | { |
---|
269 | const tr_info * inf = tr_torrentInfo( tor ); |
---|
270 | const tr_stat * st = tr_torrentStat( (tr_torrent*)tor ); |
---|
271 | |
---|
272 | if( !strcmp( key, "activityDate" ) ) |
---|
273 | tr_bencDictAddInt( d, key, st->activityDate ); |
---|
274 | else if( !strcmp( key, "addedDate" ) ) |
---|
275 | tr_bencDictAddInt( d, key, st->addedDate ); |
---|
276 | else if( !strcmp( key, "announceResponse" ) ) |
---|
277 | tr_bencDictAddStr( d, key, st->announceResponse ); |
---|
278 | else if( !strcmp( key, "announceURL" ) ) |
---|
279 | tr_bencDictAddStr( d, key, st->announceURL ); |
---|
280 | else if( !strcmp( key, "comment" ) ) |
---|
281 | tr_bencDictAddStr( d, key, inf->comment ? inf->comment : "" ); |
---|
282 | else if( !strcmp( key, "corruptEver" ) ) |
---|
283 | tr_bencDictAddInt( d, key, st->corruptEver ); |
---|
284 | else if( !strcmp( key, "creator" ) ) |
---|
285 | tr_bencDictAddStr( d, key, inf->creator ? inf->creator : "" ); |
---|
286 | else if( !strcmp( key, "dateCreated" ) ) |
---|
287 | tr_bencDictAddInt( d, key, inf->dateCreated ); |
---|
288 | else if( !strcmp( key, "desiredAvailable" ) ) |
---|
289 | tr_bencDictAddInt( d, key, st->desiredAvailable ); |
---|
290 | else if( !strcmp( key, "doneDate" ) ) |
---|
291 | tr_bencDictAddInt( d, key, st->doneDate ); |
---|
292 | else if( !strcmp( key, "downloadedEver" ) ) |
---|
293 | tr_bencDictAddInt( d, key, st->downloadedEver ); |
---|
294 | else if( !strcmp( key, "downloadLimitMode" ) ) |
---|
295 | tr_bencDictAddInt( d, key, tr_torrentGetSpeedMode( tor, TR_DOWN ) ); |
---|
296 | else if( !strcmp( key, "downloadLimit" ) ) |
---|
297 | tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit( tor, TR_DOWN ) ); |
---|
298 | else if( !strcmp( key, "error" ) ) |
---|
299 | tr_bencDictAddInt( d, key, st->error ); |
---|
300 | else if( !strcmp( key, "errorString" ) ) |
---|
301 | tr_bencDictAddStr( d, key, st->errorString ); |
---|
302 | else if( !strcmp( key, "eta" ) ) |
---|
303 | tr_bencDictAddInt( d, key, st->eta ); |
---|
304 | else if( !strcmp( key, "files" ) ) |
---|
305 | addFiles( tor, tr_bencDictAddList( d, key, inf->fileCount ) ); |
---|
306 | else if( !strcmp( key, "hashString" ) ) |
---|
307 | tr_bencDictAddStr( d, key, tor->info.hashString ); |
---|
308 | else if( !strcmp( key, "haveUnchecked" ) ) |
---|
309 | tr_bencDictAddInt( d, key, st->haveUnchecked ); |
---|
310 | else if( !strcmp( key, "haveValid" ) ) |
---|
311 | tr_bencDictAddInt( d, key, st->haveValid ); |
---|
312 | else if( !strcmp( key, "id" ) ) |
---|
313 | tr_bencDictAddInt( d, key, st->id ); |
---|
314 | else if( !strcmp( key, "isPrivate" ) ) |
---|
315 | tr_bencDictAddInt( d, key, tr_torrentIsPrivate( tor ) ); |
---|
316 | else if( !strcmp( key, "lastAnnounceTime" ) ) |
---|
317 | tr_bencDictAddInt( d, key, st->lastAnnounceTime ); |
---|
318 | else if( !strcmp( key, "lastScrapeTime" ) ) |
---|
319 | tr_bencDictAddInt( d, key, st->lastScrapeTime ); |
---|
320 | else if( !strcmp( key, "leechers" ) ) |
---|
321 | tr_bencDictAddInt( d, key, st->leechers ); |
---|
322 | else if( !strcmp( key, "leftUntilDone" ) ) |
---|
323 | tr_bencDictAddInt( d, key, st->leftUntilDone ); |
---|
324 | else if( !strcmp( key, "manualAnnounceTime" ) ) |
---|
325 | tr_bencDictAddInt( d, key, st->manualAnnounceTime ); |
---|
326 | else if( !strcmp( key, "maxConnectedPeers" ) ) |
---|
327 | tr_bencDictAddInt( d, key, tr_torrentGetPeerLimit( tor ) ); |
---|
328 | else if( !strcmp( key, "name" ) ) |
---|
329 | tr_bencDictAddStr( d, key, inf->name ); |
---|
330 | else if( !strcmp( key, "nextAnnounceTime" ) ) |
---|
331 | tr_bencDictAddInt( d, key, st->nextAnnounceTime ); |
---|
332 | else if( !strcmp( key, "nextScrapeTime" ) ) |
---|
333 | tr_bencDictAddInt( d, key, st->nextScrapeTime ); |
---|
334 | else if( !strcmp( key, "peers" ) ) |
---|
335 | addPeers( tor, tr_bencDictAdd( d, key ) ); |
---|
336 | else if( !strcmp( key, "peersConnected" ) ) |
---|
337 | tr_bencDictAddInt( d, key, st->peersConnected ); |
---|
338 | else if( !strcmp( key, "peersFrom" ) ) |
---|
339 | { |
---|
340 | tr_benc * tmp = tr_bencDictAddDict( d, key, 4 ); |
---|
341 | const int * f = st->peersFrom; |
---|
342 | tr_bencDictAddInt( tmp, "fromCache", f[TR_PEER_FROM_CACHE] ); |
---|
343 | tr_bencDictAddInt( tmp, "fromIncoming", f[TR_PEER_FROM_INCOMING] ); |
---|
344 | tr_bencDictAddInt( tmp, "fromPex", f[TR_PEER_FROM_PEX] ); |
---|
345 | tr_bencDictAddInt( tmp, "fromTracker", f[TR_PEER_FROM_TRACKER] ); |
---|
346 | } |
---|
347 | else if( !strcmp( key, "peersGettingFromUs" ) ) |
---|
348 | tr_bencDictAddInt( d, key, st->peersGettingFromUs ); |
---|
349 | else if( !strcmp( key, "peersKnown" ) ) |
---|
350 | tr_bencDictAddInt( d, key, st->peersKnown ); |
---|
351 | else if( !strcmp( key, "peersSendingToUs" ) ) |
---|
352 | tr_bencDictAddInt( d, key, st->peersSendingToUs ); |
---|
353 | else if( !strcmp( key, "pieceCount" ) ) |
---|
354 | tr_bencDictAddInt( d, key, inf->pieceCount ); |
---|
355 | else if( !strcmp( key, "pieceSize" ) ) |
---|
356 | tr_bencDictAddInt( d, key, inf->pieceSize ); |
---|
357 | else if( !strcmp( key, "priorities" ) ) |
---|
358 | { |
---|
359 | tr_file_index_t i; |
---|
360 | tr_benc * p = tr_bencDictAddList( d, key, inf->fileCount ); |
---|
361 | for( i = 0; i < inf->fileCount; ++i ) |
---|
362 | tr_bencListAddInt( p, inf->files[i].priority ); |
---|
363 | } |
---|
364 | else if( !strcmp( key, "rateDownload" ) ) |
---|
365 | tr_bencDictAddInt( d, key, (int)( st->pieceDownloadSpeed * 1024 ) ); |
---|
366 | else if( !strcmp( key, "rateUpload" ) ) |
---|
367 | tr_bencDictAddInt( d, key, (int)( st->pieceUploadSpeed * 1024 ) ); |
---|
368 | else if( !strcmp( key, "recheckProgress" ) ) |
---|
369 | tr_bencDictAddDouble( d, key, st->recheckProgress ); |
---|
370 | else if( !strcmp( key, "scrapeResponse" ) ) |
---|
371 | tr_bencDictAddStr( d, key, st->scrapeResponse ); |
---|
372 | else if( !strcmp( key, "scrapeURL" ) ) |
---|
373 | tr_bencDictAddStr( d, key, st->scrapeURL ); |
---|
374 | else if( !strcmp( key, "seeders" ) ) |
---|
375 | tr_bencDictAddInt( d, key, st->seeders ); |
---|
376 | else if( !strcmp( key, "sizeWhenDone" ) ) |
---|
377 | tr_bencDictAddInt( d, key, st->sizeWhenDone ); |
---|
378 | else if( !strcmp( key, "startDate" ) ) |
---|
379 | tr_bencDictAddInt( d, key, st->startDate ); |
---|
380 | else if( !strcmp( key, "status" ) ) |
---|
381 | tr_bencDictAddInt( d, key, st->activity ); |
---|
382 | else if( !strcmp( key, "swarmSpeed" ) ) |
---|
383 | tr_bencDictAddInt( d, key, (int)( st->swarmSpeed * 1024 ) ); |
---|
384 | else if( !strcmp( key, "timesCompleted" ) ) |
---|
385 | tr_bencDictAddInt( d, key, st->timesCompleted ); |
---|
386 | else if( !strcmp( key, "trackers" ) ) |
---|
387 | addTrackers( inf, tr_bencDictAddList( d, key, inf->trackerCount ) ); |
---|
388 | else if( !strcmp( key, "totalSize" ) ) |
---|
389 | tr_bencDictAddInt( d, key, inf->totalSize ); |
---|
390 | else if( !strcmp( key, "uploadedEver" ) ) |
---|
391 | tr_bencDictAddInt( d, key, st->uploadedEver ); |
---|
392 | else if( !strcmp( key, "uploadLimitMode" ) ) |
---|
393 | tr_bencDictAddInt( d, key, tr_torrentGetSpeedMode( tor, TR_UP ) ); |
---|
394 | else if( !strcmp( key, "uploadLimit" ) ) |
---|
395 | tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit( tor, TR_UP ) ); |
---|
396 | else if( !strcmp( key, "uploadRatio" ) ) |
---|
397 | tr_bencDictAddDouble( d, key, |
---|
398 | tr_getRatio( st->uploadedEver, |
---|
399 | st->downloadedEver ) ); |
---|
400 | else if( !strcmp( key, "wanted" ) ) |
---|
401 | { |
---|
402 | tr_file_index_t i; |
---|
403 | tr_benc * w = tr_bencDictAddList( d, key, inf->fileCount ); |
---|
404 | for( i = 0; i < inf->fileCount; ++i ) |
---|
405 | tr_bencListAddInt( w, inf->files[i].dnd ? 0 : 1 ); |
---|
406 | } |
---|
407 | else if( !strcmp( key, "webseeds" ) ) |
---|
408 | addWebseeds( inf, tr_bencDictAddList( d, key, inf->trackerCount ) ); |
---|
409 | else if( !strcmp( key, "webseedsSendingToUs" ) ) |
---|
410 | tr_bencDictAddInt( d, key, st->webseedsSendingToUs ); |
---|
411 | } |
---|
412 | |
---|
413 | static void |
---|
414 | addInfo( const tr_torrent * tor, |
---|
415 | tr_benc * d, |
---|
416 | tr_benc * fields ) |
---|
417 | { |
---|
418 | int i; |
---|
419 | const int n = tr_bencListSize( fields ); |
---|
420 | const char * str; |
---|
421 | |
---|
422 | tr_bencInitDict( d, n ); |
---|
423 | |
---|
424 | for( i = 0; i < n; ++i ) |
---|
425 | if( tr_bencGetStr( tr_bencListChild( fields, i ), &str ) ) |
---|
426 | addField( tor, d, str ); |
---|
427 | } |
---|
428 | |
---|
429 | static const char* |
---|
430 | torrentGet( tr_handle * handle, |
---|
431 | tr_benc * args_in, |
---|
432 | tr_benc * args_out ) |
---|
433 | { |
---|
434 | int i, torrentCount; |
---|
435 | tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount ); |
---|
436 | tr_benc * list = tr_bencDictAddList( args_out, "torrents", |
---|
437 | torrentCount ); |
---|
438 | tr_benc * fields; |
---|
439 | char * msg = NULL; |
---|
440 | |
---|
441 | if( !tr_bencDictFindList( args_in, "fields", &fields ) ) |
---|
442 | msg = "no fields specified"; |
---|
443 | else for( i = 0; i < torrentCount; ++i ) |
---|
444 | addInfo( torrents[i], tr_bencListAdd( list ), fields ); |
---|
445 | |
---|
446 | tr_free( torrents ); |
---|
447 | return msg; |
---|
448 | } |
---|
449 | |
---|
450 | /*** |
---|
451 | **** |
---|
452 | ***/ |
---|
453 | |
---|
454 | static void |
---|
455 | setFilePriorities( tr_torrent * tor, |
---|
456 | int priority, |
---|
457 | tr_benc * list ) |
---|
458 | { |
---|
459 | int i; |
---|
460 | int64_t tmp; |
---|
461 | int fileCount = 0; |
---|
462 | const int n = tr_bencListSize( list ); |
---|
463 | tr_file_index_t * files = tr_new0( tr_file_index_t, tor->info.fileCount ); |
---|
464 | |
---|
465 | if( n ) |
---|
466 | { |
---|
467 | for( i = 0; i < n; ++i ) |
---|
468 | if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) ) |
---|
469 | if( 0 <= tmp && tmp < tor->info.fileCount ) |
---|
470 | files[fileCount++] = tmp; |
---|
471 | } |
---|
472 | else /* if empty set, apply to all */ |
---|
473 | { |
---|
474 | tr_file_index_t t; |
---|
475 | for( t = 0; t < tor->info.fileCount; ++t ) |
---|
476 | files[fileCount++] = t; |
---|
477 | } |
---|
478 | |
---|
479 | if( fileCount ) |
---|
480 | tr_torrentSetFilePriorities( tor, files, fileCount, priority ); |
---|
481 | |
---|
482 | tr_free( files ); |
---|
483 | } |
---|
484 | |
---|
485 | static void |
---|
486 | setFileDLs( tr_torrent * tor, |
---|
487 | int do_download, |
---|
488 | tr_benc * list ) |
---|
489 | { |
---|
490 | int i; |
---|
491 | int64_t tmp; |
---|
492 | int fileCount = 0; |
---|
493 | const int n = tr_bencListSize( list ); |
---|
494 | tr_file_index_t * files = tr_new0( tr_file_index_t, tor->info.fileCount ); |
---|
495 | |
---|
496 | if( n ) /* if argument list, process them */ |
---|
497 | { |
---|
498 | for( i = 0; i < n; ++i ) |
---|
499 | if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) ) |
---|
500 | if( 0 <= tmp && tmp < tor->info.fileCount ) |
---|
501 | files[fileCount++] = tmp; |
---|
502 | } |
---|
503 | else /* if empty set, apply to all */ |
---|
504 | { |
---|
505 | tr_file_index_t t; |
---|
506 | for( t = 0; t < tor->info.fileCount; ++t ) |
---|
507 | files[fileCount++] = t; |
---|
508 | } |
---|
509 | |
---|
510 | if( fileCount ) |
---|
511 | tr_torrentSetFileDLs( tor, files, fileCount, do_download ); |
---|
512 | |
---|
513 | tr_free( files ); |
---|
514 | } |
---|
515 | |
---|
516 | static const char* |
---|
517 | torrentSet( tr_handle * h, |
---|
518 | tr_benc * args_in, |
---|
519 | tr_benc * args_out UNUSED ) |
---|
520 | { |
---|
521 | int i, torrentCount; |
---|
522 | tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); |
---|
523 | |
---|
524 | for( i = 0; i < torrentCount; ++i ) |
---|
525 | { |
---|
526 | int64_t tmp; |
---|
527 | tr_benc * files; |
---|
528 | tr_torrent * tor = torrents[i]; |
---|
529 | |
---|
530 | if( tr_bencDictFindList( args_in, "files-unwanted", &files ) ) |
---|
531 | setFileDLs( tor, FALSE, files ); |
---|
532 | if( tr_bencDictFindList( args_in, "files-wanted", &files ) ) |
---|
533 | setFileDLs( tor, TRUE, files ); |
---|
534 | if( tr_bencDictFindInt( args_in, "peer-limit", &tmp ) ) |
---|
535 | tr_torrentSetPeerLimit( tor, tmp ); |
---|
536 | if( tr_bencDictFindList( args_in, "priority-high", &files ) ) |
---|
537 | setFilePriorities( tor, TR_PRI_HIGH, files ); |
---|
538 | if( tr_bencDictFindList( args_in, "priority-low", &files ) ) |
---|
539 | setFilePriorities( tor, TR_PRI_LOW, files ); |
---|
540 | if( tr_bencDictFindList( args_in, "priority-normal", &files ) ) |
---|
541 | setFilePriorities( tor, TR_PRI_NORMAL, files ); |
---|
542 | if( tr_bencDictFindInt( args_in, "speed-limit-down", &tmp ) ) |
---|
543 | tr_torrentSetSpeedLimit( tor, TR_DOWN, tmp ); |
---|
544 | if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &tmp ) ) |
---|
545 | tr_torrentSetSpeedMode( |
---|
546 | tor, TR_DOWN, tmp ? TR_SPEEDLIMIT_SINGLE |
---|
547 | : TR_SPEEDLIMIT_GLOBAL ); |
---|
548 | if( tr_bencDictFindInt( args_in, "speed-limit-up", &tmp ) ) |
---|
549 | tr_torrentSetSpeedLimit( tor, TR_UP, tmp ); |
---|
550 | if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &tmp ) ) |
---|
551 | tr_torrentSetSpeedMode( tor, TR_UP, tmp ? TR_SPEEDLIMIT_SINGLE |
---|
552 | : TR_SPEEDLIMIT_GLOBAL ); |
---|
553 | |
---|
554 | notify( h, TR_RPC_TORRENT_CHANGED, tor ); |
---|
555 | } |
---|
556 | |
---|
557 | tr_free( torrents ); |
---|
558 | return NULL; |
---|
559 | } |
---|
560 | |
---|
561 | /*** |
---|
562 | **** |
---|
563 | ***/ |
---|
564 | |
---|
565 | static const char* |
---|
566 | torrentAdd( tr_handle * h, |
---|
567 | tr_benc * args_in, |
---|
568 | tr_benc * args_out ) |
---|
569 | { |
---|
570 | const char * filename = NULL; |
---|
571 | const char * metainfo_base64 = NULL; |
---|
572 | |
---|
573 | tr_bencDictFindStr( args_in, "filename", &filename ); |
---|
574 | tr_bencDictFindStr( args_in, "metainfo", &metainfo_base64 ); |
---|
575 | if( !filename && !metainfo_base64 ) |
---|
576 | return "no filename or metainfo specified"; |
---|
577 | else |
---|
578 | { |
---|
579 | int64_t i; |
---|
580 | int err = 0; |
---|
581 | const char * str; |
---|
582 | tr_ctor * ctor; |
---|
583 | tr_torrent * tor; |
---|
584 | |
---|
585 | ctor = tr_ctorNew( h ); |
---|
586 | |
---|
587 | /* set the metainfo */ |
---|
588 | if( filename ) |
---|
589 | tr_ctorSetMetainfoFromFile( ctor, filename ); |
---|
590 | else |
---|
591 | { |
---|
592 | int len; |
---|
593 | char * metainfo = tr_base64_decode( metainfo_base64, -1, &len ); |
---|
594 | tr_ctorSetMetainfo( ctor, (uint8_t*)metainfo, len ); |
---|
595 | tr_free( metainfo ); |
---|
596 | } |
---|
597 | |
---|
598 | /* set the optional arguments */ |
---|
599 | if( tr_bencDictFindStr( args_in, "download-dir", &str ) ) |
---|
600 | tr_ctorSetDownloadDir( ctor, TR_FORCE, str ); |
---|
601 | if( tr_bencDictFindInt( args_in, "paused", &i ) ) |
---|
602 | tr_ctorSetPaused( ctor, TR_FORCE, i ); |
---|
603 | if( tr_bencDictFindInt( args_in, "peer-limit", &i ) ) |
---|
604 | tr_ctorSetPeerLimit( ctor, TR_FORCE, i ); |
---|
605 | |
---|
606 | tor = tr_torrentNew( h, ctor, &err ); |
---|
607 | tr_ctorFree( ctor ); |
---|
608 | |
---|
609 | if( tor ) |
---|
610 | { |
---|
611 | tr_benc fields; |
---|
612 | tr_bencInitList( &fields, 3 ); |
---|
613 | tr_bencListAddStr( &fields, "id" ); |
---|
614 | tr_bencListAddStr( &fields, "name" ); |
---|
615 | tr_bencListAddStr( &fields, "hashString" ); |
---|
616 | addInfo( tor, tr_bencDictAdd( args_out, |
---|
617 | "torrent-added" ), &fields ); |
---|
618 | notify( h, TR_RPC_TORRENT_ADDED, tor ); |
---|
619 | tr_bencFree( &fields ); |
---|
620 | } |
---|
621 | else if( err == TR_EDUPLICATE ) |
---|
622 | { |
---|
623 | return "duplicate torrent"; |
---|
624 | } |
---|
625 | else if( err == TR_EINVALID ) |
---|
626 | { |
---|
627 | return "invalid or corrupt torrent file"; |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | return NULL; |
---|
632 | } |
---|
633 | |
---|
634 | /*** |
---|
635 | **** |
---|
636 | ***/ |
---|
637 | |
---|
638 | static const char* |
---|
639 | sessionSet( tr_handle * h, |
---|
640 | tr_benc * args_in, |
---|
641 | tr_benc * args_out UNUSED ) |
---|
642 | { |
---|
643 | int64_t i; |
---|
644 | const char * str; |
---|
645 | |
---|
646 | if( tr_bencDictFindStr( args_in, "download-dir", &str ) ) |
---|
647 | tr_sessionSetDownloadDir( h, str ); |
---|
648 | if( tr_bencDictFindInt( args_in, "peer-limit", &i ) ) |
---|
649 | tr_sessionSetPeerLimit( h, i ); |
---|
650 | if( tr_bencDictFindInt( args_in, "pex-allowed", &i ) ) |
---|
651 | tr_sessionSetPexEnabled( h, i ); |
---|
652 | if( tr_bencDictFindInt( args_in, "port", &i ) ) |
---|
653 | tr_sessionSetPeerPort( h, i ); |
---|
654 | if( tr_bencDictFindInt( args_in, "port-forwarding-enabled", &i ) ) |
---|
655 | tr_sessionSetPortForwardingEnabled( h, i ); |
---|
656 | if( tr_bencDictFindInt( args_in, "speed-limit-down", &i ) ) |
---|
657 | tr_sessionSetSpeedLimit( h, TR_DOWN, i ); |
---|
658 | if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &i ) ) |
---|
659 | tr_sessionSetSpeedLimitEnabled( h, TR_DOWN, i ); |
---|
660 | if( tr_bencDictFindInt( args_in, "speed-limit-up", &i ) ) |
---|
661 | tr_sessionSetSpeedLimit( h, TR_UP, i ); |
---|
662 | if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &i ) ) |
---|
663 | tr_sessionSetSpeedLimitEnabled( h, TR_UP, i ); |
---|
664 | if( tr_bencDictFindStr( args_in, "encryption", &str ) ) |
---|
665 | { |
---|
666 | if( !strcmp( str, "required" ) ) |
---|
667 | tr_sessionSetEncryption( h, TR_ENCRYPTION_REQUIRED ); |
---|
668 | else if( !strcmp( str, "tolerated" ) ) |
---|
669 | tr_sessionSetEncryption( h, TR_CLEAR_PREFERRED ); |
---|
670 | else |
---|
671 | tr_sessionSetEncryption( h, TR_ENCRYPTION_PREFERRED ); |
---|
672 | } |
---|
673 | |
---|
674 | notify( h, TR_RPC_SESSION_CHANGED, NULL ); |
---|
675 | |
---|
676 | return NULL; |
---|
677 | } |
---|
678 | |
---|
679 | static const char* |
---|
680 | sessionStats( tr_handle * h, |
---|
681 | tr_benc * args_in UNUSED, |
---|
682 | tr_benc * args_out ) |
---|
683 | { |
---|
684 | tr_benc * d = tr_bencDictAddDict( args_out, "session-stats", 10 ); |
---|
685 | tr_torrent * tor = NULL; |
---|
686 | int running = 0; |
---|
687 | int total = 0; |
---|
688 | |
---|
689 | while( ( tor = tr_torrentNext( h, tor ) ) ) |
---|
690 | { |
---|
691 | ++total; |
---|
692 | if( tor->isRunning ) |
---|
693 | ++running; |
---|
694 | } |
---|
695 | |
---|
696 | tr_bencDictAddInt( d, "activeTorrentCount", running ); |
---|
697 | tr_bencDictAddInt( d, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( h, TR_DOWN ) * 1024 ) ); |
---|
698 | tr_bencDictAddInt( d, "pausedTorrentCount", total - running ); |
---|
699 | tr_bencDictAddInt( d, "torrentCount", total ); |
---|
700 | tr_bencDictAddInt( d, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( h, TR_UP ) * 1024 ) ); |
---|
701 | return NULL; |
---|
702 | } |
---|
703 | |
---|
704 | static const char* |
---|
705 | sessionGet( tr_handle * h, |
---|
706 | tr_benc * args_in UNUSED, |
---|
707 | tr_benc * args_out ) |
---|
708 | { |
---|
709 | const char * str; |
---|
710 | tr_benc * d = args_out; |
---|
711 | |
---|
712 | tr_bencDictAddStr( d, "download-dir", |
---|
713 | tr_sessionGetDownloadDir( h ) ); |
---|
714 | tr_bencDictAddInt( d, "peer-limit", |
---|
715 | tr_sessionGetPeerLimit( h ) ); |
---|
716 | tr_bencDictAddInt( d, "pex-allowed", |
---|
717 | tr_sessionIsPexEnabled( h ) ); |
---|
718 | tr_bencDictAddInt( d, "port", |
---|
719 | tr_sessionGetPeerPort( h ) ); |
---|
720 | tr_bencDictAddInt( d, "port-forwarding-enabled", |
---|
721 | tr_sessionIsPortForwardingEnabled( h ) ); |
---|
722 | tr_bencDictAddInt( d, "speed-limit-up", |
---|
723 | tr_sessionGetSpeedLimit( h, TR_UP ) ); |
---|
724 | tr_bencDictAddInt( d, "speed-limit-up-enabled", |
---|
725 | tr_sessionIsSpeedLimitEnabled( h, TR_UP ) ); |
---|
726 | tr_bencDictAddInt( d, "speed-limit-down", |
---|
727 | tr_sessionGetSpeedLimit( h, TR_DOWN ) ); |
---|
728 | tr_bencDictAddInt( d, "speed-limit-down-enabled", |
---|
729 | tr_sessionIsSpeedLimitEnabled( h, TR_DOWN ) ); |
---|
730 | switch( tr_sessionGetEncryption( h ) ) |
---|
731 | { |
---|
732 | case TR_CLEAR_PREFERRED: |
---|
733 | str = "tolerated"; break; |
---|
734 | |
---|
735 | case TR_ENCRYPTION_REQUIRED: |
---|
736 | str = "required"; break; |
---|
737 | |
---|
738 | default: |
---|
739 | str = "preferred"; break; |
---|
740 | } |
---|
741 | tr_bencDictAddStr( d, "encryption", str ); |
---|
742 | |
---|
743 | return NULL; |
---|
744 | } |
---|
745 | |
---|
746 | /*** |
---|
747 | **** |
---|
748 | ***/ |
---|
749 | |
---|
750 | typedef const char* ( handler )( tr_handle*, tr_benc*, tr_benc* ); |
---|
751 | |
---|
752 | static struct method |
---|
753 | { |
---|
754 | const char * name; |
---|
755 | handler * func; |
---|
756 | } methods[] = { |
---|
757 | { "session-get", sessionGet }, |
---|
758 | { "session-set", sessionSet }, |
---|
759 | { "session-stats", sessionStats }, |
---|
760 | { "torrent-add", torrentAdd }, |
---|
761 | { "torrent-get", torrentGet }, |
---|
762 | { "torrent-remove", torrentRemove }, |
---|
763 | { "torrent-set", torrentSet }, |
---|
764 | { "torrent-start", torrentStart }, |
---|
765 | { "torrent-stop", torrentStop }, |
---|
766 | { "torrent-verify", torrentVerify } |
---|
767 | }; |
---|
768 | |
---|
769 | static char* |
---|
770 | request_exec( struct tr_handle * handle, |
---|
771 | tr_benc * request, |
---|
772 | int * response_len ) |
---|
773 | { |
---|
774 | int64_t i; |
---|
775 | const char * str; |
---|
776 | char * out; |
---|
777 | tr_benc response; |
---|
778 | tr_benc * args_in = tr_bencDictFind( request, "arguments" ); |
---|
779 | tr_benc * args_out = NULL; |
---|
780 | const char * result = NULL; |
---|
781 | |
---|
782 | /* build the response skeleton */ |
---|
783 | tr_bencInitDict( &response, 3 ); |
---|
784 | args_out = tr_bencDictAddDict( &response, "arguments", 0 ); |
---|
785 | |
---|
786 | /* parse the request */ |
---|
787 | if( !tr_bencDictFindStr( request, "method", &str ) ) |
---|
788 | result = "no method name"; |
---|
789 | else |
---|
790 | { |
---|
791 | const int n = TR_N_ELEMENTS( methods ); |
---|
792 | for( i = 0; i < n; ++i ) |
---|
793 | if( !strcmp( str, methods[i].name ) ) |
---|
794 | break; |
---|
795 | result = i == n |
---|
796 | ? "method name not recognized" |
---|
797 | : ( *methods[i].func )( handle, args_in, args_out ); |
---|
798 | } |
---|
799 | |
---|
800 | /* serialize & return the response */ |
---|
801 | if( !result ) |
---|
802 | result = "success"; |
---|
803 | tr_bencDictAddStr( &response, "result", result ); |
---|
804 | if( tr_bencDictFindInt( request, "tag", &i ) ) |
---|
805 | tr_bencDictAddInt( &response, "tag", i ); |
---|
806 | out = tr_bencSaveAsJSON( &response, response_len ); |
---|
807 | tr_bencFree( &response ); |
---|
808 | return out; |
---|
809 | } |
---|
810 | |
---|
811 | char* |
---|
812 | tr_rpc_request_exec_json( struct tr_handle * handle, |
---|
813 | const void * request_json, |
---|
814 | int request_len, |
---|
815 | int * response_len ) |
---|
816 | { |
---|
817 | tr_benc top; |
---|
818 | int have_content; |
---|
819 | char * ret; |
---|
820 | |
---|
821 | if( request_len < 0 ) |
---|
822 | request_len = strlen( request_json ); |
---|
823 | |
---|
824 | have_content = !tr_jsonParse( request_json, request_len, &top, NULL ); |
---|
825 | ret = request_exec( handle, have_content ? &top : NULL, response_len ); |
---|
826 | |
---|
827 | if( have_content ) |
---|
828 | tr_bencFree( &top ); |
---|
829 | return ret; |
---|
830 | } |
---|
831 | |
---|
832 | static void |
---|
833 | addToken( tr_benc * list, |
---|
834 | const char * token, |
---|
835 | size_t len ) |
---|
836 | { |
---|
837 | char * p; |
---|
838 | const char * end = token + len; |
---|
839 | const long a = strtol( token, &p, 10 ); |
---|
840 | |
---|
841 | if( p == end ) |
---|
842 | tr_bencListAddInt( list, a ); |
---|
843 | else if( *p == '-' && isdigit( p[1] ) ) |
---|
844 | { |
---|
845 | const long b = strtol( p + 1, &p, 10 ); |
---|
846 | if( ( p == end ) && ( b > a ) ) |
---|
847 | { |
---|
848 | long i; |
---|
849 | for( i = a; i <= b; ++i ) |
---|
850 | tr_bencListAddInt( list, i ); |
---|
851 | } |
---|
852 | } |
---|
853 | } |
---|
854 | |
---|
855 | /** |
---|
856 | * Munge the URI into a usable form. |
---|
857 | * |
---|
858 | * We have very loose typing on this to make the URIs as simple as possible: |
---|
859 | * - anything not a 'tag' or 'method' is automatically in 'arguments' |
---|
860 | * - values that are all-digits are numbers |
---|
861 | * - values that are all-digits or commas are number lists |
---|
862 | * - all other values are strings |
---|
863 | */ |
---|
864 | void |
---|
865 | tr_rpc_parse_list_str( tr_benc * setme, |
---|
866 | const char * str_in, |
---|
867 | size_t len ) |
---|
868 | |
---|
869 | { |
---|
870 | char * str = tr_strndup( str_in, len ); |
---|
871 | int isNum; |
---|
872 | int isNumList; |
---|
873 | int commaCount; |
---|
874 | const char * walk; |
---|
875 | |
---|
876 | isNum = 1; |
---|
877 | isNumList = 1; |
---|
878 | commaCount = 0; |
---|
879 | walk = str; |
---|
880 | for( ; *walk && ( isNumList || isNum ); ++walk ) |
---|
881 | { |
---|
882 | if( isNumList ) isNumList = *walk == '-' || isdigit( *walk ) |
---|
883 | || *walk == ','; |
---|
884 | if( isNum ) isNum = *walk == '-' || isdigit( *walk ); |
---|
885 | if( *walk == ',' ) ++commaCount; |
---|
886 | } |
---|
887 | |
---|
888 | if( isNum ) |
---|
889 | tr_bencInitInt( setme, strtol( str, NULL, 10 ) ); |
---|
890 | else if( !isNumList ) |
---|
891 | tr_bencInitStr( setme, str, len ); |
---|
892 | else |
---|
893 | { |
---|
894 | tr_bencInitList( setme, commaCount + 1 ); |
---|
895 | walk = str; |
---|
896 | while( *walk ) |
---|
897 | { |
---|
898 | const char * p = strchr( walk, ',' ); |
---|
899 | if( !p ) |
---|
900 | p = walk + strlen( walk ); |
---|
901 | addToken( setme, walk, p - walk ); |
---|
902 | if( *p != ',' ) |
---|
903 | break; |
---|
904 | walk = p + 1; |
---|
905 | } |
---|
906 | } |
---|
907 | |
---|
908 | tr_free( str ); |
---|
909 | } |
---|
910 | |
---|
911 | char* |
---|
912 | tr_rpc_request_exec_uri( struct tr_handle * handle, |
---|
913 | const void * request_uri, |
---|
914 | int request_len, |
---|
915 | int * response_len ) |
---|
916 | { |
---|
917 | char * ret = NULL; |
---|
918 | tr_benc top, * args; |
---|
919 | char * request = tr_strndup( request_uri, request_len ); |
---|
920 | const char * pch; |
---|
921 | |
---|
922 | tr_bencInitDict( &top, 3 ); |
---|
923 | args = tr_bencDictAddDict( &top, "arguments", 0 ); |
---|
924 | |
---|
925 | pch = strchr( request, '?' ); |
---|
926 | if( !pch ) pch = request; |
---|
927 | while( pch ) |
---|
928 | { |
---|
929 | const char * delim = strchr( pch, '=' ); |
---|
930 | const char * next = strchr( pch, '&' ); |
---|
931 | if( delim ) |
---|
932 | { |
---|
933 | char * key = tr_strndup( pch, delim - pch ); |
---|
934 | int isArg = strcmp( key, "method" ) && strcmp( key, "tag" ); |
---|
935 | tr_benc * parent = isArg ? args : ⊤ |
---|
936 | tr_rpc_parse_list_str( tr_bencDictAdd( parent, key ), |
---|
937 | delim + 1, |
---|
938 | next ? (size_t)( |
---|
939 | next - |
---|
940 | ( delim + 1 ) ) : strlen( delim + 1 ) ); |
---|
941 | tr_free( key ); |
---|
942 | } |
---|
943 | pch = next ? next + 1 : NULL; |
---|
944 | } |
---|
945 | |
---|
946 | ret = request_exec( handle, &top, response_len ); |
---|
947 | |
---|
948 | /* cleanup */ |
---|
949 | tr_bencFree( &top ); |
---|
950 | tr_free( request ); |
---|
951 | return ret; |
---|
952 | } |
---|
953 | |
---|