92
tr_sessionSetEncryption( tr_session * session, tr_encryption_mode mode )
95
tr_sessionSetEncryption( tr_session * session,
96
tr_encryption_mode mode )
95
assert( mode==TR_ENCRYPTION_PREFERRED
96
|| mode==TR_ENCRYPTION_REQUIRED
97
|| mode==TR_PLAINTEXT_PREFERRED );
99
assert( mode == TR_ENCRYPTION_PREFERRED
100
|| mode == TR_ENCRYPTION_REQUIRED
101
|| mode == TR_CLEAR_PREFERRED );
99
103
session->encryptionMode = mode;
111
tr_stringEndsWith( const char * str,
114
const size_t slen = strlen( str );
115
const size_t elen = strlen( end );
117
return slen >= elen && !memcmp( &str[slen - elen], end, elen );
107
121
loadBlocklists( tr_session * session )
112
char dirname[MAX_PATH_LENGTH];
114
tr_list * list = NULL;
115
const int isEnabled = session->isBlocklistEnabled;
128
tr_list * list = NULL;
129
const int isEnabled = session->isBlocklistEnabled;
117
131
/* walk through the directory and find blocklists */
118
tr_buildPath( dirname, sizeof( dirname ), session->configDir, "blocklists", NULL );
119
if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && (( odir = opendir( dirname ))))
132
dirname = tr_buildPath( session->configDir, "blocklists", NULL );
134
&sb ) && S_ISDIR( sb.st_mode )
135
&& ( ( odir = opendir( dirname ) ) ) )
121
137
struct dirent *d;
122
for( d=readdir( odir ); d; d=readdir( odir ) )
138
for( d = readdir( odir ); d; d = readdir( odir ) )
124
char filename[MAX_PATH_LENGTH];
126
if( !d->d_name || d->d_name[0]=='.' ) /* skip dotfiles, ., and .. */
142
if( !d->d_name || d->d_name[0] == '.' ) /* skip dotfiles, ., and ..
129
tr_buildPath( filename, sizeof(filename), dirname, d->d_name, NULL );
146
filename = tr_buildPath( dirname, d->d_name, NULL );
131
148
if( tr_stringEndsWith( filename, ".bin" ) )
133
150
/* if we don't already have this blocklist, add it */
134
if( !tr_list_find( list, filename, (TrListCompareFunc)strcmp ) )
151
if( !tr_list_find( list, filename,
152
(TrListCompareFunc)strcmp ) )
136
tr_list_append( &list, _tr_blocklistNew( filename, isEnabled ) );
154
tr_list_append( &list,
155
_tr_blocklistNew( filename, isEnabled ) );
142
/* strip out the file suffix, if there is one, and add ".bin" instead */
161
/* strip out the file suffix, if there is one, and add ".bin"
143
163
tr_blocklist * b;
144
const char * dot = strrchr( d->d_name, '.' );
145
const int len = dot ? dot - d->d_name : (int)strlen( d->d_name );
146
char tmp[MAX_PATH_LENGTH];
147
tr_snprintf( tmp, sizeof( tmp ),
148
"%s%c%*.*s.bin", dirname, TR_PATH_DELIMITER, len, len, d->d_name );
164
const char * dot = strrchr( d->d_name, '.' );
165
const int len = dot ? dot - d->d_name
166
: (int)strlen( d->d_name );
167
char * tmp = tr_strdup_printf(
168
"%s" TR_PATH_DELIMITER_STR "%*.*s.bin",
169
dirname, len, len, d->d_name );
149
170
b = _tr_blocklistNew( tmp, isEnabled );
150
171
_tr_blocklistSetContent( b, filename );
151
172
tr_list_append( &list, b );
156
180
closedir( odir );
171
197
static void metainfoLookupRescan( tr_handle * h );
174
tr_sessionInitFull( const char * configDir,
176
const char * downloadDir,
178
int isPortForwardingEnabled,
181
int isUploadLimitEnabled,
183
int isDownloadLimitEnabled,
187
int isMessageQueueingEnabled,
188
int isBlocklistEnabled,
193
int rpcAuthIsEnabled,
194
const char * rpcUsername,
195
const char * rpcPassword,
199
tr_proxy_type proxyType,
200
int proxyAuthIsEnabled,
201
const char * proxyUsername,
202
const char * proxyPassword )
200
tr_sessionInitFull( const char * configDir,
202
const char * downloadDir,
204
int isPortForwardingEnabled,
206
tr_encryption_mode encryptionMode,
210
int useDownloadLimit,
214
int isMessageQueueingEnabled,
215
int isBlocklistEnabled,
219
int rpcWhitelistIsEnabled,
220
const char * rpcWhitelist,
221
int rpcAuthIsEnabled,
222
const char * rpcUsername,
223
const char * rpcPassword,
227
tr_proxy_type proxyType,
228
int proxyAuthIsEnabled,
229
const char * proxyUsername,
230
const char * proxyPassword )
205
char filename[MAX_PATH_LENGTH];
208
236
/* Don't exit when writing on a broken socket */
209
237
signal( SIGPIPE, SIG_IGN );
212
if( configDir == NULL )
213
configDir = tr_getDefaultConfigDir( );
216
241
tr_setMessageLevel( messageLevel );
217
242
tr_setMessageQueuing( isMessageQueueingEnabled );
226
251
h->proxy = tr_strdup( proxy );
227
252
h->proxyPort = proxyPort;
228
253
h->proxyType = proxyType;
229
h->isProxyAuthEnabled = proxyAuthIsEnabled ? 1 : 0;
254
h->isProxyAuthEnabled = proxyAuthIsEnabled != 0;
230
255
h->proxyUsername = tr_strdup( proxyUsername );
231
256
h->proxyPassword = tr_strdup( proxyPassword );
257
h->pieceSpeed[TR_PEER_TO_CLIENT] = tr_rcInit( );
258
h->pieceSpeed[TR_CLIENT_TO_PEER] = tr_rcInit( );
259
h->rawSpeed[TR_PEER_TO_CLIENT] = tr_rcInit( );
260
h->rawSpeed[TR_CLIENT_TO_PEER] = tr_rcInit( );
262
if( configDir == NULL )
263
configDir = tr_getDefaultConfigDir( );
233
264
tr_setConfigDir( h, configDir );
235
tr_netInit(); /* must go before tr_eventInit */
266
tr_netInit( ); /* must go before tr_eventInit */
237
268
tr_eventInit( h );
238
269
while( !h->events )
241
272
h->tag = tr_strdup( tag );
242
273
h->peerMgr = tr_peerMgrNew( h );
275
h->useLazyBitfield = useLazyBitfield != 0;
244
277
/* Initialize rate and file descripts controls */
246
h->upload = tr_rcInit();
247
tr_rcSetLimit( h->upload, uploadLimit );
248
h->useUploadLimit = isUploadLimitEnabled;
250
h->download = tr_rcInit();
251
tr_rcSetLimit( h->download, downloadLimit );
252
h->useDownloadLimit = isDownloadLimitEnabled;
279
h->uploadLimit = uploadLimit;
280
h->useUploadLimit = useUploadLimit;
281
h->downloadLimit = downloadLimit;
282
h->useDownloadLimit = useDownloadLimit;
254
284
tr_fdInit( globalPeerLimit );
255
285
h->shared = tr_sharedInit( h, isPortForwardingEnabled, publicPort );
260
290
tr_inf( _( "%s %s started" ), TR_NAME, LONG_VERSION_STRING );
262
292
/* initialize the blocklist */
263
tr_buildPath( filename, sizeof( filename ), h->configDir, "blocklists", NULL );
293
filename = tr_buildPath( h->configDir, "blocklists", NULL );
264
294
tr_mkdirp( filename, 0777 );
265
296
h->isBlocklistEnabled = isBlocklistEnabled;
266
297
loadBlocklists( h );
268
299
tr_statsInit( h );
270
301
h->web = tr_webInit( h );
271
h->rpcServer = tr_rpcInit( h, rpcIsEnabled, rpcPort, rpcACL,
272
rpcAuthIsEnabled, rpcUsername, rpcPassword );
302
h->rpcServer = tr_rpcInit( h, rpcIsEnabled, rpcPort,
303
rpcWhitelistIsEnabled, rpcWhitelist,
304
rpcAuthIsEnabled, rpcUsername, rpcPassword );
274
306
metainfoLookupRescan( h );
287
319
TR_DEFAULT_PEX_ENABLED,
288
320
TR_DEFAULT_PORT_FORWARDING_ENABLED,
289
321
-1, /* public port */
290
TR_ENCRYPTION_PREFERRED, /* encryption mode */
291
FALSE, /* use upload speed limit? */
322
TR_DEFAULT_ENCRYPTION, /* encryption mode */
323
TR_DEFAULT_LAZY_BITFIELD_ENABLED,
324
FALSE, /* use upload speed limit? */
292
325
-1, /* upload speed limit */
293
326
FALSE, /* use download speed limit? */
294
327
-1, /* download speed limit */
358
392
/***********************************************************************
360
394
***********************************************************************
362
396
**********************************************************************/
364
398
struct bind_port_data
371
405
tr_setBindPortImpl( void * vdata )
373
407
struct bind_port_data * data = vdata;
374
tr_handle * handle = data->handle;
375
const int port = data->port;
408
tr_handle * handle = data->handle;
409
const int port = data->port;
377
411
handle->isPortSet = 1;
378
412
tr_sharedSetPort( handle->shared, port );
410
tr_sessionSetSpeedLimitEnabled( tr_handle * h,
446
tr_sessionSetSpeedLimitEnabled( tr_handle * h,
447
tr_direction direction,
414
if( up_or_down == TR_UP )
451
assert( direction == TR_UP || direction == TR_DOWN );
453
if( direction == TR_UP )
415
454
h->useUploadLimit = use_flag ? 1 : 0;
417
456
h->useDownloadLimit = use_flag ? 1 : 0;
421
tr_sessionIsSpeedLimitEnabled( const tr_handle * h, int up_or_down )
460
tr_sessionIsSpeedLimitEnabled( const tr_handle * h,
461
tr_direction direction )
423
return up_or_down==TR_UP ? h->useUploadLimit : h->useDownloadLimit;
463
return direction == TR_UP ? h->useUploadLimit : h->useDownloadLimit;
427
tr_sessionSetSpeedLimit( tr_handle * h,
467
tr_sessionSetSpeedLimit( tr_handle * h,
468
tr_direction direction,
431
if( up_or_down == TR_DOWN )
432
tr_rcSetLimit( h->download, KiB_sec );
471
if( direction == TR_DOWN )
472
h->downloadLimit = KiB_sec;
434
tr_rcSetLimit( h->upload, KiB_sec );
474
h->uploadLimit = KiB_sec;
438
tr_sessionGetSpeedLimit( const tr_handle * h, int up_or_down )
478
tr_sessionGetSpeedLimit( const tr_handle * h,
479
tr_direction direction )
440
return tr_rcGetLimit( up_or_down==TR_UP ? h->upload : h->download );
481
return direction == TR_UP ? h->uploadLimit : h->downloadLimit;
465
tr_sessionGetSpeed( const tr_handle * session,
469
if( session && toClient )
470
*toClient = tr_rcRate( session->download );
471
if( session && toPeer )
472
*toPeer = tr_rcRate( session->upload );
506
tr_sessionGetPieceSpeed( const tr_session * session, tr_direction dir )
508
assert( dir==TR_UP || dir==TR_DOWN );
510
return session ? tr_rcRate( session->pieceSpeed[dir] ) : 0.0;
514
tr_sessionGetRawSpeed( const tr_session * session, tr_direction dir )
516
assert( dir==TR_UP || dir==TR_DOWN );
518
return session ? tr_rcRate( session->rawSpeed[dir] ) : 0.0;
478
524
return h->torrentCount;
481
/* close the biggest torrents first */
483
compareTorrentByCur( const void * va, const void * vb )
528
compareTorrentByCur( const void * va,
485
531
const tr_torrent * a = *(const tr_torrent**)va;
486
532
const tr_torrent * b = *(const tr_torrent**)vb;
487
return -tr_compareUint64( a->downloadedCur + a->uploadedCur,
488
b->downloadedCur + b->uploadedCur );
533
const uint64_t aCur = a->downloadedCur + a->uploadedCur;
534
const uint64_t bCur = b->downloadedCur + b->uploadedCur;
537
return aCur > bCur ? -1 : 1; /* close the biggest torrents first */
492
543
tr_closeAllConnections( void * vsession )
494
tr_handle * session = vsession;
545
tr_handle * session = vsession;
497
548
tr_torrent ** torrents;
499
550
tr_statsClose( session );
505
556
* at least we get the most important ones first. */
507
558
n = session->torrentCount;
508
torrents = tr_new( tr_torrent*, session->torrentCount );
559
torrents = tr_new( tr_torrent *, session->torrentCount );
560
for( i = 0; i < n; ++i )
510
561
torrents[i] = tor = tr_torrentNext( session, tor );
511
qsort( torrents, n, sizeof(tr_torrent*), compareTorrentByCur );
562
qsort( torrents, n, sizeof( tr_torrent* ), compareTorrentByCur );
563
for( i = 0; i < n; ++i )
513
564
tr_torrentFree( torrents[i] );
514
565
tr_free( torrents );
516
567
tr_peerMgrFree( session->peerMgr );
518
tr_rcClose( session->upload );
519
tr_rcClose( session->download );
521
569
tr_trackerSessionClose( session );
522
tr_list_free( &session->blocklists, (TrListForeachFunc)_tr_blocklistFree );
570
tr_list_free( &session->blocklists,
571
(TrListForeachFunc)_tr_blocklistFree );
523
572
tr_webClose( &session->web );
525
574
session->isClosed = TRUE;
534
583
#define SHUTDOWN_MAX_SECONDS 30
536
#define dbgmsg(fmt...) tr_deepLog( __FILE__, __LINE__, NULL, ##fmt )
585
#define dbgmsg( ... ) \
587
if( tr_deepLoggingIsActive( ) ) \
588
tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \
539
592
tr_sessionClose( tr_handle * session )
542
const int maxwait_msec = SHUTDOWN_MAX_SECONDS * 1000;
595
const int maxwait_msec = SHUTDOWN_MAX_SECONDS * 1000;
543
596
const uint64_t deadline = tr_date( ) + maxwait_msec;
545
598
dbgmsg( "shutting down transmission session %p", session );
547
600
/* close the session */
548
601
tr_runInEventThread( session, tr_closeAllConnections, session );
549
while( !session->isClosed && !deadlineReached( deadline ) ) {
550
dbgmsg( "waiting for the shutdown commands to run in the main thread" );
602
while( !session->isClosed && !deadlineReached( deadline ) )
605
"waiting for the shutdown commands to run in the main thread" );
555
610
* so we need to keep the transmission thread alive
556
611
* for a bit while they tell the router & tracker
557
612
* that we're closing now */
558
while( ( session->shared || session->tracker ) && !deadlineReached( deadline ) ) {
613
while( ( session->shared
614
|| session->tracker ) && !deadlineReached( deadline ) )
559
616
dbgmsg( "waiting on port unmap (%p) or tracker (%p)",
560
617
session->shared, session->tracker );
565
623
/* close the libtransmission thread */
566
624
tr_eventClose( session );
567
while( session->events && !deadlineReached( deadline ) ) {
625
while( session->events && !deadlineReached( deadline ) )
568
627
dbgmsg( "waiting for the libevent thread to shutdown cleanly" );
572
631
/* free the session memory */
632
tr_rcClose( session->pieceSpeed[TR_PEER_TO_CLIENT] );
633
tr_rcClose( session->pieceSpeed[TR_CLIENT_TO_PEER] );
634
tr_rcClose( session->rawSpeed[TR_PEER_TO_CLIENT] );
635
tr_rcClose( session->rawSpeed[TR_CLIENT_TO_PEER] );
573
636
tr_lockFree( session->lock );
574
for( i=0; i<session->metainfoLookupCount; ++i )
637
for( i = 0; i < session->metainfoLookupCount; ++i )
575
638
tr_free( session->metainfoLookup[i].filename );
576
639
tr_free( session->metainfoLookup );
577
640
tr_free( session->tag );
589
tr_sessionLoadTorrents ( tr_handle * h,
652
tr_sessionLoadTorrents( tr_handle * h,
596
const char * dirname = tr_getTorrentDir( h );
659
const char * dirname = tr_getTorrentDir( h );
597
660
tr_torrent ** torrents;
598
tr_list *l=NULL, *list=NULL;
661
tr_list * l = NULL, *list = NULL;
600
663
tr_ctorSetSave( ctor, FALSE ); /* since we already have them */
602
665
if( !stat( dirname, &sb )
603
&& S_ISDIR( sb.st_mode )
604
&& (( odir = opendir ( dirname ) )) )
666
&& S_ISDIR( sb.st_mode )
667
&& ( ( odir = opendir ( dirname ) ) ) )
606
669
struct dirent *d;
607
for (d = readdir( odir ); d!=NULL; d=readdir( odir ) )
670
for( d = readdir( odir ); d != NULL; d = readdir( odir ) )
609
if( d->d_name && d->d_name[0]!='.' ) /* skip dotfiles, ., and .. */
672
if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles, ., and ..
611
675
tr_torrent * tor;
612
char filename[MAX_PATH_LENGTH];
613
tr_buildPath( filename, sizeof(filename), dirname, d->d_name, NULL );
615
tr_ctorSetMetainfoFromFile( ctor, filename );
616
tor = tr_torrentNew( h, ctor, NULL );
676
char * path = tr_buildPath( dirname, d->d_name, NULL );
677
tr_ctorSetMetainfoFromFile( ctor, path );
678
if(( tor = tr_torrentNew( h, ctor, NULL )))
618
680
tr_list_append( &list, tor );
623
686
closedir( odir );
626
torrents = tr_new( tr_torrent*, n );
627
for( i=0, l=list; l!=NULL; l=l->next )
689
torrents = tr_new( tr_torrent *, n );
690
for( i = 0, l = list; l != NULL; l = l->next )
628
691
torrents[i++] = (tr_torrent*) l->data;
631
694
tr_list_free( &list, NULL );
711
tr_blocklistSetContent( tr_session * session, const char * contentFilename )
796
tr_blocklistSetContent( tr_session * session,
797
const char * contentFilename )
714
800
tr_blocklist * b;
715
const char * defaultName = "level1.bin";
801
const char * defaultName = "level1.bin";
717
for( b=NULL, l=session->blocklists; !b && l; l=l->next )
718
if( tr_stringEndsWith( _tr_blocklistGetFilename( l->data ), defaultName ) )
803
for( b = NULL, l = session->blocklists; !b && l; l = l->next )
804
if( tr_stringEndsWith( _tr_blocklistGetFilename( l->data ),
722
char filename[MAX_PATH_LENGTH];
723
tr_buildPath( filename, sizeof( filename ), session->configDir, "blocklists", defaultName, NULL );
724
b = _tr_blocklistNew( filename, session->isBlocklistEnabled );
810
char * path = tr_buildPath( session->configDir, "blocklists", defaultName, NULL );
811
b = _tr_blocklistNew( path, session->isBlocklistEnabled );
725
812
tr_list_append( &session->blocklists, b );
728
816
return _tr_blocklistSetContent( b, contentFilename );
732
tr_sessionIsAddressBlocked( const tr_session * session,
733
const struct in_addr * addr )
820
tr_sessionIsAddressBlocked( const tr_session * session,
821
const struct in_addr * addr )
736
for( l=session->blocklists; l; l=l->next )
825
for( l = session->blocklists; l; l = l->next )
737
826
if( _tr_blocklistHasAddress( l->data, addr ) )
747
compareLookupEntries( const void * va, const void * vb )
836
compareLookupEntries( const void * va,
749
839
const struct tr_metainfo_lookup * a = va;
750
840
const struct tr_metainfo_lookup * b = vb;
751
842
return strcmp( a->hashString, b->hashString );
755
846
metainfoLookupResort( tr_handle * h )
757
qsort( h->metainfoLookup,
848
qsort( h->metainfoLookup,
758
849
h->metainfoLookupCount,
759
850
sizeof( struct tr_metainfo_lookup ),
760
851
compareLookupEntries );
764
compareHashStringToLookupEntry( const void * va, const void * vb )
855
compareHashStringToLookupEntry( const void * va,
767
859
const struct tr_metainfo_lookup * b = vb;
768
861
return strcmp( a, b->hashString );
772
tr_sessionFindTorrentFile( const tr_handle * h,
773
const char * hashStr )
865
tr_sessionFindTorrentFile( const tr_handle * h,
866
const char * hashStr )
775
868
struct tr_metainfo_lookup * l = bsearch( hashStr,
776
869
h->metainfoLookup,
777
870
h->metainfoLookupCount,
778
sizeof( struct tr_metainfo_lookup ),
872
tr_metainfo_lookup ),
779
873
compareHashStringToLookupEntry );
780
875
return l ? l->filename : NULL;
784
879
metainfoLookupRescan( tr_handle * h )
789
884
const char * dirname = tr_getTorrentDir( h );
791
tr_ctor * ctor = NULL;
792
tr_list * list = NULL;
886
tr_ctor * ctor = NULL;
887
tr_list * list = NULL;
794
889
/* walk through the directory and find the mappings */
795
890
ctor = tr_ctorNew( h );
796
891
tr_ctorSetSave( ctor, FALSE ); /* since we already have them */
797
if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && (( odir = opendir( dirname ))))
893
&sb ) && S_ISDIR( sb.st_mode )
894
&& ( ( odir = opendir( dirname ) ) ) )
799
896
struct dirent *d;
800
for (d = readdir( odir ); d!=NULL; d=readdir( odir ) )
897
for( d = readdir( odir ); d != NULL; d = readdir( odir ) )
802
if( d->d_name && d->d_name[0]!='.' ) /* skip dotfiles, ., and .. */
899
if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles, ., and ..
805
char filename[MAX_PATH_LENGTH];
806
tr_buildPath( filename, sizeof(filename), dirname, d->d_name, NULL );
807
tr_ctorSetMetainfoFromFile( ctor, filename );
903
char * path = tr_buildPath( dirname, d->d_name, NULL );
904
tr_ctorSetMetainfoFromFile( ctor, path );
808
905
if( !tr_torrentParse( h, ctor, &inf ) )
810
907
tr_list_append( &list, tr_strdup( inf.hashString ) );
811
tr_list_append( &list, tr_strdup( filename ) );
908
tr_list_append( &list, tr_strdup( path ) );
812
909
tr_metainfoFree( &inf );
816
914
closedir( odir );
820
918
n = tr_list_size( list ) / 2;
821
919
h->metainfoLookup = tr_new0( struct tr_metainfo_lookup, n );
822
920
h->metainfoLookupCount = n;
921
for( i = 0; i < n; ++i )
825
923
char * hashString = tr_list_pop_front( &list );
826
924
char * filename = tr_list_pop_front( &list );
828
memcpy( h->metainfoLookup[i].hashString, hashString, 2*SHA_DIGEST_LENGTH+1 );
926
memcpy( h->metainfoLookup[i].hashString, hashString,
927
2 * SHA_DIGEST_LENGTH + 1 );
829
928
tr_free( hashString );
830
929
h->metainfoLookup[i].filename = filename;
857
const int n = h->metainfoLookupCount++;
958
const int n = h->metainfoLookupCount++;
858
959
struct tr_metainfo_lookup * node;
859
960
h->metainfoLookup = tr_renew( struct tr_metainfo_lookup,
860
961
h->metainfoLookup,
861
962
h->metainfoLookupCount );
862
963
node = h->metainfoLookup + n;
863
memcpy( node->hashString, hashString, 2*SHA_DIGEST_LENGTH+1 );
964
memcpy( node->hashString, hashString, 2 * SHA_DIGEST_LENGTH + 1 );
864
965
node->filename = tr_strdup( filename );
865
966
metainfoLookupResort( h );
870
tr_torrentNext( tr_handle * session, tr_torrent * tor )
971
tr_torrentNext( tr_handle * session,
872
974
return tor ? tor->next : session->torrentList;
880
tr_sessionSetRPCEnabled( tr_session * session, int isEnabled )
982
tr_sessionSetRPCEnabled( tr_session * session,
882
985
tr_rpcSetEnabled( session->rpcServer, isEnabled );
885
989
tr_sessionIsRPCEnabled( const tr_session * session )
887
991
return tr_rpcIsEnabled( session->rpcServer );
890
tr_sessionSetRPCPort( tr_session * session, int port )
995
tr_sessionSetRPCPort( tr_session * session,
892
998
tr_rpcSetPort( session->rpcServer, port );
895
1002
tr_sessionGetRPCPort( const tr_session * session )
897
1004
return tr_rpcGetPort( session->rpcServer );
900
tr_sessionSetRPCCallback( tr_session * session,
1008
tr_sessionSetRPCCallback( tr_session * session,
904
1012
session->rpc_func = func;
905
1013
session->rpc_func_user_data = user_data;
908
tr_sessionTestRPCACL( const tr_session * session,
910
char ** allocme_errmsg )
912
return tr_rpcTestACL( session->rpcServer, acl, allocme_errmsg );
915
tr_sessionSetRPCACL( tr_session * session,
917
char ** allocme_errmsg )
919
return tr_rpcSetACL( session->rpcServer, acl, allocme_errmsg );
1017
tr_sessionSetRPCWhitelist( tr_session * session,
1018
const char * whitelist )
1020
tr_rpcSetWhitelist( session->rpcServer, whitelist );
922
tr_sessionGetRPCACL( const tr_session * session )
924
return tr_rpcGetACL( session->rpcServer );
927
tr_sessionSetRPCPassword( tr_session * session, const char * password )
1024
tr_sessionGetRPCWhitelist( const tr_session * session )
1026
return tr_rpcGetWhitelist( session->rpcServer );
1030
tr_sessionSetRPCWhitelistEnabled( tr_session * session,
1033
tr_rpcSetWhitelistEnabled( session->rpcServer, isEnabled );
1037
tr_sessionGetRPCWhitelistEnabled( const tr_session * session )
1039
return tr_rpcGetWhitelistEnabled( session->rpcServer );
1044
tr_sessionSetRPCPassword( tr_session * session,
1045
const char * password )
929
1047
tr_rpcSetPassword( session->rpcServer, password );
932
1051
tr_sessionGetRPCPassword( const tr_session * session )
934
1053
return tr_rpcGetPassword( session->rpcServer );
937
tr_sessionSetRPCUsername( tr_session * session, const char * username )
1057
tr_sessionSetRPCUsername( tr_session * session,
1058
const char * username )
939
1060
tr_rpcSetUsername( session->rpcServer, username );
942
1064
tr_sessionGetRPCUsername( const tr_session * session )
944
1066
return tr_rpcGetUsername( session->rpcServer );
947
tr_sessionSetRPCPasswordEnabled( tr_session * session, int isEnabled )
1070
tr_sessionSetRPCPasswordEnabled( tr_session * session,
949
1073
tr_rpcSetPasswordEnabled( session->rpcServer, isEnabled );
952
1077
tr_sessionIsRPCPasswordEnabled( const tr_session * session )
964
1089
return session->isProxyEnabled;
967
tr_sessionSetProxyEnabled( tr_session * session, int isEnabled )
1093
tr_sessionSetProxyEnabled( tr_session * session,
969
1096
session->isProxyEnabled = isEnabled ? 1 : 0;
972
1100
tr_sessionGetProxyType( const tr_session * session )
974
1102
return session->proxyType;
977
tr_sessionSetProxyType( tr_session * session, tr_proxy_type type )
1106
tr_sessionSetProxyType( tr_session * session,
1107
tr_proxy_type type )
979
1109
session->proxyType = type;
982
1113
tr_sessionGetProxy( const tr_session * session )
984
1115
return session->proxy;
987
1119
tr_sessionGetProxyPort( const tr_session * session )
989
1121
return session->proxyPort;
992
tr_sessionSetProxy( tr_session * session, const char * proxy )
1125
tr_sessionSetProxy( tr_session * session,
1126
const char * proxy )
994
1128
if( proxy != session->proxy )
997
1131
session->proxy = tr_strdup( proxy );
1001
tr_sessionSetProxyPort( tr_session * session, int port )
1136
tr_sessionSetProxyPort( tr_session * session,
1003
1139
session->proxyPort = port;
1006
1143
tr_sessionIsProxyAuthEnabled( const tr_session * session )
1008
1145
return session->isProxyAuthEnabled;
1011
tr_sessionSetProxyAuthEnabled( tr_session * session, int isEnabled )
1149
tr_sessionSetProxyAuthEnabled( tr_session * session,
1013
1152
session->isProxyAuthEnabled = isEnabled ? 1 : 0;
1016
1156
tr_sessionGetProxyUsername( const tr_session * session )
1018
1158
return session->proxyUsername;
1021
tr_sessionSetProxyUsername( tr_session * session, const char * username )
1162
tr_sessionSetProxyUsername( tr_session * session,
1163
const char * username )
1023
1165
if( username != session->proxyUsername )