Changeset 7367
- Timestamp:
- Dec 13, 2008, 11:17:36 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/cli.c
r7230 r7367 39 39 #define MY_NAME "transmission-cli" 40 40 41 static int showInfo = 0; 42 static int showScrape = 0; 43 static int isPrivate = 0; 44 static int verboseLevel = 0; 45 static int encryptionMode = TR_DEFAULT_ENCRYPTION; 46 static int peerPort = TR_DEFAULT_PORT; 47 static int peerSocketTOS = TR_DEFAULT_PEER_SOCKET_TOS; 48 static int blocklistEnabled = TR_DEFAULT_BLOCKLIST_ENABLED; 49 static int uploadLimit = 20; 50 static int downloadLimit = -1; 51 static int natTraversal = TR_DEFAULT_PORT_FORWARDING_ENABLED; 52 static int verify = 0; 41 static tr_bool showInfo = 0; 42 static tr_bool showScrape = 0; 43 static tr_bool isPrivate = 0; 44 static tr_bool verify = 0; 53 45 static sig_atomic_t gotsig = 0; 54 46 static sig_atomic_t manualUpdate = 0; 55 47 56 48 static const char * torrentPath = NULL; 57 static const char * downloadDir = NULL;58 49 static const char * finishCall = NULL; 59 50 static const char * announce = NULL; … … 64 55 static const struct tr_option options[] = 65 56 { 66 { 'a', "announce", "Set the new torrent's announce URL", 67 "a", 1, "<url>" }, 68 { 'b', "blocklist", "Enable peer blocklists", 69 "b", 0, NULL }, 70 { 'B', "no-blocklist", "Disable peer blocklists", 71 "B", 0, NULL }, 72 { 'c', "comment", "Set the new torrent's comment", 73 "c", 1, "<comment>" }, 74 { 'd', "downlimit", "Set max download speed in KB/s", 75 "d", 1, "<speed>" }, 76 { 'D', "no-downlimit", "Don't limit the download speed", 77 "D", 0, NULL }, 78 { 910, "encryption-required", "Encrypt all peer connections", 79 "er", 0, NULL }, 80 { 911, "encryption-preferred", "Prefer encrypted peer connections", 81 "ep", 0, NULL }, 82 { 912, "encryption-tolerated", "Prefer unencrypted peer connections", 83 "et", 0, NULL }, 84 { 'f', "finish", "Run a script when the torrent finishes", 85 "f", 1, "<script>" }, 86 { 'g', "config-dir", "Where to find configuration files", 87 "g", 1, "<path>" }, 88 { 'i', "info", "Show torrent details and exit", 89 "i", 0, NULL }, 90 { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", 91 "m", 0, NULL }, 92 { 'M', "no-portmap", "Disable portmapping", 93 "M", 0, NULL }, 94 { 'n', "new", "Create a new torrent", 95 "n", 1, "<source>" }, 96 { 'p', "port", 97 "Port for incoming peers (Default: " TR_DEFAULT_PORT_STR ")", 98 "p", 1, "<port>" }, 99 { 'r', "private", "Set the new torrent's 'private' flag", 100 "r", 0, NULL }, 101 { 's', "scrape", "Scrape the torrent and exit", 102 "s", 0, NULL }, 103 { 't', "tos", 104 "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR 105 ")", 106 "t", 1, "<tos>" }, 107 { 'u', "uplimit", "Set max upload speed in KB/s", 108 "u", 1, "<speed>" }, 109 { 'U', "no-uplimit", "Don't limit the upload speed", 110 "U", 0, NULL }, 111 { 'v', "verify", "Verify the specified torrent", 112 "v", 0, NULL }, 113 { 'w', "download-dir", "Where to save downloaded data", 114 "w", 1, "<path>" }, 115 { 0, NULL, NULL, 116 NULL, 0, NULL } 57 { 'a', "announce", "Set the new torrent's announce URL", "a", 1, "<url>" }, 58 { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL }, 59 { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL }, 60 { 'c', "comment", "Set the new torrent's comment", "c", 1, "<comment>" }, 61 { 'd', "downlimit", "Set max download speed in KB/s", "d", 1, "<speed>" }, 62 { 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL }, 63 { 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL }, 64 { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL }, 65 { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL }, 66 { 'f', "finish", "Run a script when the torrent finishes", "f", 1, "<script>" }, 67 { 'g', "config-dir", "Where to find configuration files", "g", 1, "<path>" }, 68 { 'i', "info", "Show torrent details and exit", "i", 0, NULL }, 69 { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL }, 70 { 'M', "no-portmap", "Disable portmapping", "M", 0, NULL }, 71 { 'n', "new", "Create a new torrent", "n", 1, "<source>" }, 72 { 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", 1, "<port>" }, 73 { 'r', "private", "Set the new torrent's 'private' flag", "r", 0, NULL }, 74 { 's', "scrape", "Scrape the torrent and exit", "s", 0, NULL }, 75 { 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", 1, "<tos>" }, 76 { 'u', "uplimit", "Set max upload speed in KB/s", "u", 1, "<speed>" }, 77 { 'U', "no-uplimit", "Don't limit the upload speed", "U", 0, NULL }, 78 { 'v', "verify", "Verify the specified torrent", "v", 0, NULL }, 79 { 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" }, 80 { 0, NULL, NULL, NULL, 0, NULL } 117 81 }; 118 82 … … 125 89 } 126 90 127 static int parseCommandLine( int argc, 128 const char ** argv ); 91 static int parseCommandLine( tr_benc*, int argc, const char ** argv ); 129 92 130 93 static void sigHandler( int signal ); … … 302 265 } 303 266 267 static const char* 268 getConfigDir( int argc, const char ** argv ) 269 { 270 int c; 271 const char * configDir = NULL; 272 const char * optarg; 273 const int ind = tr_optind; 274 275 while(( c = tr_getopt( getUsage( ), argc, argv, options, &optarg ))) 276 if( c == 'g' ) 277 configdir = optarg; 278 279 tr_optind = ind; 280 281 if( configDir == NULL ) 282 configDir = tr_getDefaultConfigDir( MY_NAME ); 283 284 return configDir; 285 } 286 304 287 int 305 288 main( int argc, … … 310 293 tr_ctor * ctor; 311 294 tr_torrent * tor = NULL; 295 tr_benc settings; 296 const char * configDir; 312 297 313 298 printf( "Transmission %s - http://www.transmissionbt.com/\n", … … 320 305 } 321 306 322 /* Get options */ 323 if( parseCommandLine( argc, (const char**)argv ) ) 307 /* load the defaults from config file + libtransmission defaults */ 308 tr_bencInitDict( &settings, 0 ); 309 configDir = getConfigDir( argc, (const char**)argv ); 310 tr_sessionLoadSettings( &settings, configDir, MY_NAME ); 311 312 /* the command line overrides defaults */ 313 if( parseCommandLine( &settings, argc, (const char**)argv ) ) 324 314 return EXIT_FAILURE; 325 315 326 316 /* Check the options for validity */ 327 if( !torrentPath ) 328 { 317 if( !torrentPath ) { 329 318 fprintf( stderr, "No torrent specified!\n" ); 330 319 return EXIT_FAILURE; 331 320 } 332 if( peerPort < 1 || peerPort > 65535 )333 {334 fprintf( stderr, "Error: Port must between 1 and 65535; got %d\n",335 peerPort );336 return EXIT_FAILURE;337 }338 if( peerSocketTOS < 0 || peerSocketTOS > 255 )339 {340 fprintf( stderr, "Error: value must between 0 and 255; got %d\n",341 peerSocketTOS );342 return EXIT_FAILURE;343 }344 321 345 322 /* don't bind the port if we're just running the CLI 346 *to get metainfo or to create a torrent */323 to get metainfo or to create a torrent */ 347 324 if( showInfo || showScrape || ( sourceFile != NULL ) ) 348 peerPort = -1; 349 350 if( configdir == NULL ) 351 configdir = tr_getDefaultConfigDir( ); 352 353 if( downloadDir == NULL ) 354 downloadDir = tr_getDefaultDownloadDir( ); 355 356 /* Initialize libtransmission */ 357 h = tr_sessionInitFull( 358 configdir, 359 "cli", /* tag */ 360 downloadDir, /* where to download torrents */ 361 TR_DEFAULT_PEX_ENABLED, 362 natTraversal, /* nat enabled */ 363 peerPort, 364 encryptionMode, 365 TR_DEFAULT_LAZY_BITFIELD_ENABLED, 366 uploadLimit >= 0, 367 uploadLimit, 368 downloadLimit >= 0, 369 downloadLimit, 370 TR_DEFAULT_GLOBAL_PEER_LIMIT, 371 verboseLevel + 1, /* messageLevel */ 372 0, /* is message queueing enabled? */ 373 blocklistEnabled, 374 peerSocketTOS, 375 TR_DEFAULT_RPC_ENABLED, 376 TR_DEFAULT_RPC_PORT, 377 TR_DEFAULT_RPC_WHITELIST_ENABLED, 378 TR_DEFAULT_RPC_WHITELIST, 379 FALSE, "fnord", "potzrebie", 380 TR_DEFAULT_PROXY_ENABLED, 381 TR_DEFAULT_PROXY, 382 TR_DEFAULT_PROXY_PORT, 383 TR_DEFAULT_PROXY_TYPE, 384 TR_DEFAULT_PROXY_AUTH_ENABLED, 385 TR_DEFAULT_PROXY_USERNAME, 386 TR_DEFAULT_PROXY_PASSWORD ); 325 tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_PORT, -1 ); 326 327 h = tr_sessionInit( "cli", configDir, FALSE, &settings ); 387 328 388 329 if( sourceFile && *sourceFile ) /* creating a torrent */ … … 408 349 tr_ctorSetMetainfoFromFile( ctor, torrentPath ); 409 350 tr_ctorSetPaused( ctor, TR_FORCE, showScrape ); 410 tr_ctorSetDownloadDir( ctor, TR_FORCE, downloadDir );411 351 412 352 if( showScrape ) … … 522 462 523 463 cleanup: 464 465 tr_sessionSaveSettings( h, configDir, &settings ); 466 524 467 printf( "\n" ); 468 tr_bencFree( &settings ); 525 469 tr_sessionClose( h ); 526 470 return EXIT_SUCCESS; … … 533 477 ***/ 534 478 535 static void536 showUsage( void )537 {538 tr_getopt_usage( MY_NAME, getUsage( ), options );539 exit( 0 );540 }541 542 479 static int 543 numarg( const char * arg ) 544 { 545 char * end = NULL; 546 const long num = strtol( arg, &end, 10 ); 547 548 if( *end ) 549 { 550 fprintf( stderr, "Not a number: \"%s\"\n", arg ); 551 showUsage( ); 552 } 553 return num; 554 } 555 556 static int 557 parseCommandLine( int argc, 558 const char ** argv ) 480 parseCommandLine( tr_benc * d, int argc, const char ** argv ) 559 481 { 560 482 int c; 561 483 const char * optarg; 562 484 563 while( ( c = tr_getopt( getUsage( ), argc, argv, options, &optarg ) ))485 while(( c = tr_getopt( getUsage( ), argc, argv, options, &optarg ))) 564 486 { 565 487 switch( c ) … … 568 490 announce = optarg; break; 569 491 570 case 'b': 571 blocklistEnabled = 1; break; 572 573 case 'B': 574 blocklistEnabled = 0; break; 575 576 case 'c': 577 comment = optarg; break; 578 579 case 'd': 580 downloadLimit = numarg( optarg ); break; 581 582 case 'D': 583 downloadLimit = -1; break; 584 585 case 'f': 586 finishCall = optarg; break; 587 588 case 'g': 589 configdir = optarg; break; 590 591 case 'i': 592 showInfo = 1; break; 593 594 case 'm': 595 natTraversal = 1; break; 596 597 case 'M': 598 natTraversal = 0; break; 599 600 case 'n': 601 sourceFile = optarg; break; 602 603 case 'p': 604 peerPort = numarg( optarg ); break; 605 606 case 'r': 607 isPrivate = 1; break; 608 609 case 's': 610 showScrape = 1; break; 611 612 case 't': 613 peerSocketTOS = numarg( optarg ); break; 614 615 case 'u': 616 uploadLimit = numarg( optarg ); break; 617 618 case 'U': 619 uploadLimit = -1; break; 620 621 case 'v': 622 verify = 1; break; 623 624 case 'w': 625 downloadDir = optarg; break; 626 627 case 910: 628 encryptionMode = TR_ENCRYPTION_REQUIRED; break; 629 630 case 911: 631 encryptionMode = TR_CLEAR_PREFERRED; break; 632 633 case 912: 634 encryptionMode = TR_ENCRYPTION_PREFERRED; break; 635 492 case 'b': tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, 1 ); 493 break; 494 case 'B': tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, 0 ); 495 break; 496 case 'c': comment = optarg; 497 break; 498 case 'd': tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED, atoi( optarg ) ); 499 tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED, 1 ); 500 break; 501 case 'D': tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED, 0 ); 502 break; 503 case 'f': finishCall = optarg; 504 break; 505 case 'g': /* handled above */ 506 break; 507 case 'i': showInfo = 1; 508 break; 509 case 'm': tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, 1 ); 510 break; 511 case 'M': tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, 0 ); 512 break; 513 case 'n': sourceFile = optarg; break; 514 case 'p': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT, 1 ); 515 break; 516 case 'r': isPrivate = 1; 517 break; 518 case 's': showScrape = 1; 519 break; 520 case 't': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi( optarg ) ); 521 break; 522 case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED, atoi( optarg ) ); 523 tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED, 1 ); 524 break; 525 case 'U': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED, 0 ); 526 break; 527 case 'v': verify = 1; 528 break; 529 case 'w': tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, optarg ); 530 break; 531 case 910: tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_REQUIRED ); 532 break; 533 case 911: tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION, TR_CLEAR_PREFERRED ); 534 break; 535 case 912: tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_PREFERRED ); 536 break; 636 537 case TR_OPT_UNK: 637 torrentPath = optarg; break; 638 639 default: 640 return 1; 538 torrentPath = optarg; 539 break; 540 default: return 1; 641 541 } 642 542 } -
trunk/daemon/daemon.c
r7345 r7367 31 31 static int closing = FALSE; 32 32 static tr_session * mySession = NULL; 33 static char * myConfigFilename = NULL;34 35 #define KEY_BLOCKLIST "blocklist-enabled"36 #define KEY_DOWNLOAD_DIR "download-dir"37 #define KEY_ENCRYPTION "encryption"38 #define KEY_LAZY_BITFIELD "lazy-bitfield-enabled"39 #define KEY_PEER_LIMIT "max-peers-global"40 #define KEY_PEER_PORT "peer-port"41 #define KEY_PORT_FORWARDING "port-forwarding-enabled"42 #define KEY_PEX_ENABLED "pex-enabled"43 #define KEY_AUTH_REQUIRED "rpc-authentication-required"44 #define KEY_USERNAME "rpc-username"45 #define KEY_PASSWORD "rpc-password"46 #define KEY_WHITELIST "rpc-whitelist"47 #define KEY_WHITELIST_ENABLED "rpc-whitelist-enabled"48 #define KEY_RPC_PORT "rpc-port"49 #define KEY_DSPEED "download-limit"50 #define KEY_DSPEED_ENABLED "download-limit-enabled"51 #define KEY_USPEED "upload-limit"52 #define KEY_USPEED_ENABLED "upload-limit-enabled"53 54 #define CONFIG_FILE "settings.json"55 33 56 34 /*** 57 35 **** Config File 58 36 ***/ 59 60 static void61 replaceInt( tr_benc * dict,62 const char * key,63 int64_t value )64 {65 tr_bencDictRemove( dict, key );66 tr_bencDictAddInt( dict, key, value );67 }68 69 static void70 replaceStr( tr_benc * dict,71 const char * key,72 const char* value )73 {74 tr_bencDictRemove( dict, key );75 tr_bencDictAddStr( dict, key, value );76 }77 78 static void79 saveState( tr_session * s )80 {81 int i, n = 0;82 char * strs[4];83 84 tr_benc d;85 86 if( tr_bencLoadJSONFile( myConfigFilename, &d ) )87 tr_bencInitDict( &d, 16 );88 89 replaceInt( &d, KEY_BLOCKLIST, tr_blocklistIsEnabled( s ) );90 replaceStr( &d, KEY_DOWNLOAD_DIR, tr_sessionGetDownloadDir( s ) );91 replaceInt( &d, KEY_PEER_LIMIT, tr_sessionGetPeerLimit( s ) );92 replaceInt( &d, KEY_PEER_PORT, tr_sessionGetPeerPort( s ) );93 replaceInt( &d, KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled( s ) );94 replaceInt( &d, KEY_PEX_ENABLED, tr_sessionIsPexEnabled( s ) );95 replaceStr( &d, KEY_USERNAME, strs[n++] = tr_sessionGetRPCUsername( s ) );96 replaceStr( &d, KEY_PASSWORD, strs[n++] = tr_sessionGetRPCPassword( s ) );97 replaceStr( &d, KEY_WHITELIST, strs[n++] = tr_sessionGetRPCWhitelist( s ) );98 replaceInt( &d, KEY_RPC_PORT, tr_sessionGetRPCPort( s ) );99 replaceInt( &d, KEY_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled( s ) );100 replaceInt( &d, KEY_DSPEED, tr_sessionGetSpeedLimit( s, TR_DOWN ) );101 replaceInt( &d, KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimitEnabled( s, TR_DOWN ) );102 replaceInt( &d, KEY_USPEED, tr_sessionGetSpeedLimit( s, TR_UP ) );103 replaceInt( &d, KEY_USPEED_ENABLED, tr_sessionIsSpeedLimitEnabled( s, TR_UP ) );104 replaceInt( &d, KEY_ENCRYPTION, tr_sessionGetEncryption( s ) );105 106 tr_bencSaveJSONFile( myConfigFilename, &d );107 tr_bencFree( &d );108 tr_ninf( MY_NAME, "saved \"%s\"", myConfigFilename );109 110 for( i = 0; i < n; ++i )111 tr_free( strs[i] );112 }113 114 static void115 getConfigInt( tr_benc * dict,116 const char * key,117 int * setme,118 int defaultVal )119 {120 if( *setme < 0 )121 {122 int64_t i;123 if( tr_bencDictFindInt( dict, key, &i ) )124 *setme = i;125 else126 *setme = defaultVal;127 }128 }129 130 static void131 getConfigStr( tr_benc * dict,132 const char * key,133 const char ** setme,134 const char * defaultVal )135 {136 if( !*setme )137 {138 const char * s;139 if( tr_bencDictFindStr( dict, key, &s ) )140 *setme = s;141 else142 *setme = defaultVal;143 }144 }145 146 /**147 * @param port port number, or -1 if not set in the command line148 * @param auth TRUE, FALSE, or -1 if not set on the command line149 * @param blocklist TRUE, FALSE, or -1 if not set on the command line150 */151 static void152 session_init( const char * configDir,153 const char * downloadDir,154 int rpcPort,155 const char * whitelist,156 int authRequired,157 const char * username,158 const char * password,159 int blocklistEnabled )160 {161 tr_benc state, *dict = NULL;162 int peerPort = -1, peers = -1;163 int whitelistEnabled = -1;164 int pexEnabled = -1;165 int fwdEnabled = -1;166 int upLimit = -1, upLimited = -1, downLimit = -1,167 downLimited = -1;168 int encryption = -1;169 int useLazyBitfield = -1;170 tr_ctor * ctor;171 tr_torrent ** torrents;172 173 if( !tr_bencLoadJSONFile( myConfigFilename, &state ) )174 dict = &state;175 176 177 /***178 **** Decide on which values to pass into tr_sessionInitFull().179 **** The command-line arguments are given precedence and180 **** the state file from the previous session is used as a fallback.181 **** If neither of those can be found, the TR_DEFAULT fields are used .182 ***/183 184 getConfigStr( dict, KEY_DOWNLOAD_DIR, &downloadDir, TR_DEFAULT_DOWNLOAD_DIR );185 getConfigInt( dict, KEY_PEX_ENABLED, &pexEnabled, TR_DEFAULT_PEX_ENABLED );186 getConfigInt( dict, KEY_PORT_FORWARDING, &fwdEnabled, TR_DEFAULT_PORT_FORWARDING_ENABLED );187 getConfigInt( dict, KEY_PEER_PORT, &peerPort, TR_DEFAULT_PORT );188 getConfigInt( dict, KEY_DSPEED, &downLimit, 100 );189 getConfigInt( dict, KEY_DSPEED_ENABLED, &downLimited, FALSE );190 getConfigInt( dict, KEY_USPEED, &upLimit, 100 );191 getConfigInt( dict, KEY_USPEED_ENABLED, &upLimited, FALSE );192 getConfigInt( dict, KEY_LAZY_BITFIELD, &useLazyBitfield, TR_DEFAULT_LAZY_BITFIELD_ENABLED );193 getConfigInt( dict, KEY_PEER_LIMIT, &peers, TR_DEFAULT_GLOBAL_PEER_LIMIT );194 getConfigInt( dict, KEY_BLOCKLIST, &blocklistEnabled, TR_DEFAULT_BLOCKLIST_ENABLED );195 getConfigInt( dict, KEY_RPC_PORT, &rpcPort, TR_DEFAULT_RPC_PORT );196 getConfigStr( dict, KEY_WHITELIST, &whitelist, TR_DEFAULT_RPC_WHITELIST );197 getConfigInt( dict, KEY_AUTH_REQUIRED, &authRequired, FALSE );198 getConfigStr( dict, KEY_USERNAME, &username, NULL );199 getConfigStr( dict, KEY_PASSWORD, &password, NULL );200 getConfigInt( dict, KEY_ENCRYPTION, &encryption, TR_DEFAULT_ENCRYPTION );201 202 whitelistEnabled = whitelist && *whitelist;203 204 /***205 ****206 ***/207 208 /* start the session */209 mySession = tr_sessionInitFull( configDir, "daemon", downloadDir,210 pexEnabled, fwdEnabled, peerPort,211 encryption,212 useLazyBitfield,213 upLimited, upLimit,214 downLimited, downLimit,215 peers,216 TR_MSG_INF, 0,217 blocklistEnabled,218 TR_DEFAULT_PEER_SOCKET_TOS,219 TRUE, rpcPort,220 whitelistEnabled, whitelist,221 authRequired, username, password,222 TR_DEFAULT_PROXY_ENABLED,223 TR_DEFAULT_PROXY,224 TR_DEFAULT_PROXY_PORT,225 TR_DEFAULT_PROXY_TYPE,226 TR_DEFAULT_PROXY_AUTH_ENABLED,227 TR_DEFAULT_PROXY_USERNAME,228 TR_DEFAULT_PROXY_PASSWORD );229 230 231 if( authRequired )232 tr_ninf( MY_NAME, "requiring authentication" );233 234 /* load the torrents */235 ctor = tr_ctorNew( mySession );236 torrents = tr_sessionLoadTorrents( mySession, ctor, NULL );237 tr_free( torrents );238 tr_ctorFree( ctor );239 240 if( dict )241 tr_bencFree( &state );242 }243 37 244 38 static const char * … … 257 51 static const struct tr_option options[] = 258 52 { 259 { 'a', "allowed", 260 "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", 261 1, "<list>" }, 262 { 'b', "blocklist", "Enable peer blocklists", 263 "b", 0, NULL }, 264 { 'B', "no-blocklist", "Disable peer blocklists", 265 "B", 0, NULL }, 266 { 'f', "foreground", "Run in the foreground instead of daemonizing", 267 "f", 0, NULL }, 268 { 'g', "config-dir", "Where to look for configuration files", 269 "g", 1, "<path>" }, 270 { 'p', "port", 271 "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", 272 1, "<port>" }, 273 { 't', "auth", "Require authentication", 274 "t", 0, NULL }, 275 { 'T', "no-auth", "Don't require authentication", 276 "T", 0, NULL }, 277 { 'u', "username", "Set username for authentication", 278 "u", 1, "<username>" }, 279 { 'v', "password", "Set password for authentication", 280 "v", 1, "<password>" }, 281 { 'w', "download-dir", "Where to save downloaded data", 282 "w", 1, "<path>" }, 283 { 0, NULL, NULL, 284 NULL, 0, NULL } 53 { 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", 1, "<list>" }, 54 { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL }, 55 { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL }, 56 { 'f', "foreground", "Run in the foreground instead of daemonizing", "f", 0, NULL }, 57 { 'g', "config-dir", "Where to look for configuration files", "g", 1, "<path>" }, 58 { 'p', "port", "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", 1, "<port>" }, 59 { 't', "auth", "Require authentication", "t", 0, NULL }, 60 { 'T', "no-auth", "Don't require authentication", "T", 0, NULL }, 61 { 'u', "username", "Set username for authentication", "u", 1, "<username>" }, 62 { 'v', "password", "Set password for authentication", "v", 1, "<password>" }, 63 { 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" }, 64 { 0, NULL, NULL, NULL, 0, NULL } 285 65 }; 286 66 … … 290 70 tr_getopt_usage( MY_NAME, getUsage( ), options ); 291 71 exit( 0 ); 292 }293 294 static void295 readargs( int argc,296 const char ** argv,297 int * nofork,298 const char ** configDir,299 const char ** downloadDir,300 int * rpcPort,301 const char ** whitelist,302 int * authRequired,303 const char ** username,304 const char ** password,305 int * blocklistEnabled )306 {307 int c;308 const char * optarg;309 310 while( ( c = tr_getopt( getUsage( ), argc, argv, options, &optarg ) ) )311 {312 switch( c )313 {314 case 'a':315 *whitelist = optarg; break;316 317 case 'b':318 *blocklistEnabled = 1; break;319 320 case 'B':321 *blocklistEnabled = 0; break;322 323 case 'f':324 *nofork = 1; break;325 326 case 'g':327 *configDir = optarg; break;328 329 case 'p':330 *rpcPort = atoi( optarg ); break;331 332 case 't':333 *authRequired = TRUE; break;334 335 case 'T':336 *authRequired = FALSE; break;337 338 case 'u':339 *username = optarg; break;340 341 case 'v':342 *password = optarg; break;343 344 case 'w':345 *downloadDir = optarg; break;346 347 default:348 showUsage( ); break;349 }350 }351 72 } 352 73 … … 434 155 #endif 435 156 157 static const char* 158 getConfigDir( int argc, const char ** argv ) 159 { 160 int c; 161 const char * configDir = NULL; 162 const char * optarg; 163 const int ind = tr_optind; 164 165 while(( c = tr_getopt( getUsage( ), argc, argv, options, &optarg ))) 166 if( c == 'g' ) 167 configDir = optarg; 168 169 tr_optind = ind; 170 171 if( configDir == NULL ) 172 configDir = tr_getDefaultConfigDir( MY_NAME ); 173 174 return configDir; 175 } 176 177 436 178 int 437 179 main( int argc, 438 180 char ** argv ) 439 181 { 440 int nofork = 0; 441 int rpcPort = -1; 442 int authRequired = -1; 443 int blocklistEnabled = -1; 444 char * freeme = NULL; 182 int c; 183 const char * optarg; 184 tr_benc settings; 185 tr_bool foreground = FALSE; 445 186 const char * configDir = NULL; 446 const char * downloadDir = NULL;447 const char * whitelist = NULL;448 const char * username = NULL;449 const char * password = NULL;450 187 451 188 signal( SIGINT, gotsig ); … … 457 194 #endif 458 195 459 readargs( argc, (const char**)argv, &nofork, &configDir, &downloadDir, 460 &rpcPort, &whitelist, &authRequired, &username, &password, 461 &blocklistEnabled ); 462 if( configDir == NULL ) 463 configDir = getenv( "TRANSMISSION_HOME" ); 464 if( configDir == NULL ) 465 configDir = freeme = tr_strdup_printf( "%s-daemon", 466 tr_getDefaultConfigDir( ) ); 467 myConfigFilename = tr_buildPath( configDir, CONFIG_FILE, NULL ); 196 /* load settings from defaults + config file */ 197 tr_bencInitDict( &settings, 0 ); 198 configDir = getConfigDir( argc, (const char**)argv ); 199 tr_sessionLoadSettings( &settings, configDir, MY_NAME ); 200 201 /* overwrite settings from the comamndline */ 202 tr_optind = 1; 203 while(( c = tr_getopt( getUsage(), argc, (const char**)argv, options, &optarg ))) { 204 switch( c ) { 205 case 'a': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, optarg ); 206 tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, 1 ); 207 break; 208 case 'b': tr_bencDictAddInt( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, 1 ); 209 break; 210 case 'B': tr_bencDictAddInt( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, 0 ); 211 break; 212 case 'f': foreground = TRUE; 213 break; 214 case 'g': /* handled above */ 215 break; 216 case 'p': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_PORT, atoi( optarg ) ); 217 break; 218 case 't': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, 0 ); 219 break; 220 case 'T': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, 1 ); 221 break; 222 case 'u': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_USERNAME, optarg ); 223 break; 224 case 'v': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_PASSWORD, optarg ); 225 break; 226 case 'w': tr_bencDictAddStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, optarg ); 227 break; 228 default: showUsage( ); 229 break; 230 } 231 } 468 232 469 233 #ifndef WIN32 470 if( ! nofork)234 if( !foreground ) 471 235 { 472 236 if( 0 > daemon( 1, 0 ) ) … … 478 242 #endif 479 243 480 session_init( configDir, downloadDir, 481 rpcPort, whitelist, authRequired, username, password, 482 blocklistEnabled ); 244 /* start the session */ 245 mySession = tr_sessionInit( "daemon", configDir, FALSE, &settings ); 246 247 if( tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, NULL ) ) 248 tr_ninf( MY_NAME, "requiring authentication" ); 249 250 /* load the torrents */ 251 { 252 tr_ctor * ctor = tr_ctorNew( mySession ); 253 tr_torrent ** torrents = tr_sessionLoadTorrents( mySession, ctor, NULL ); 254 tr_free( torrents ); 255 tr_ctorFree( ctor ); 256 } 483 257 484 258 while( !closing ) 485 259 tr_wait( 1000 ); /* sleep one second */ 486 260 487 saveState( mySession );261 /* shutdown */ 488 262 printf( "Closing transmission session..." ); 263 tr_sessionSaveSettings( mySession, configDir, &settings ); 489 264 tr_sessionClose( mySession ); 490 265 printf( " done.\n" ); 491 266 492 tr_free( freeme );493 tr_ free( myConfigFilename);267 /* cleanup */ 268 tr_bencFree( &settings ); 494 269 return 0; 495 270 } 496 -
trunk/daemon/remote.c
r7331 r7367 35 35 #define MY_NAME "transmission-remote" 36 36 #define DEFAULT_HOST "localhost" 37 #define DEFAULT_PORT TR_DEFAULT_RPC_PORT37 #define DEFAULT_PORT atoi(TR_DEFAULT_RPC_PORT_STR) 38 38 39 39 enum { TAG_LIST, TAG_DETAILS, TAG_FILES, TAG_PEERS }; … … 90 90 "n", 1, "<username:password>" }, 91 91 { 'p', "port", 92 "Port for incoming peers (Default: " TR_DEFAULT_P ORT_STR ")",92 "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", 93 93 "p", 1, "<port>" }, 94 94 { 900, "priority-high", "Set the files' priorities as high", -
trunk/gtk/add-dialog.c
r6998 r7367 43 43 44 44 static void 45 save_recent_destination( const char * dir )45 save_recent_destination( TrCore * core, const char * dir ) 46 46 { 47 47 int i; … … 71 71 pref_string_set( key, l->data ); 72 72 } 73 pref_save( );73 pref_save( tr_core_session( core ) ); 74 74 75 75 /* cleanup */ … … 117 117 { 118 118 if( response != GTK_RESPONSE_ACCEPT ) 119 { 119 120 removeOldTorrent( data ); 121 } 120 122 else 121 123 { 122 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data-> 123 run_check ) ) ) 124 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->run_check ) ) ) 124 125 tr_torrentStart( tr_torrent_handle( data->gtor ) ); 126 125 127 tr_core_add_torrent( data->core, data->gtor ); 126 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data-> 127 trash_check ) ) ) 128 129 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->trash_check ) ) ) 130 128 131 tr_file_trash_or_unlink( data->filename ); 129 save_recent_destination( data-> downloadDir );132 save_recent_destination( data->core, data->downloadDir ); 130 133 } 131 134 } -
trunk/gtk/conf.c
r6862 r7367 42 42 #include "util.h" 43 43 44 #define MY_NAME "transmission" 45 44 46 static char * gl_confdir = NULL; 45 47 static char * gl_lockpath = NULL; … … 47 49 /* errstr may be NULL, this might be called before GTK is initialized */ 48 50 gboolean 49 cf_init( const char *dir,50 char **errstr )51 cf_init( const char * configDir, 52 char ** errstr ) 51 53 { 52 54 if( errstr != NULL ) 53 55 *errstr = NULL; 54 56 55 gl_confdir = g_strdup( dir );57 gl_confdir = g_strdup( configDir ); 56 58 57 59 if( mkdir_p( gl_confdir, 0755 ) ) … … 152 154 getPrefs( void ) 153 155 { 154 static tr_benc dict;156 static tr_benc settings; 155 157 static gboolean loaded = FALSE; 156 158 157 159 if( !loaded ) 158 160 { 159 char * filename = getPrefsFilename( ); 160 if( tr_bencLoadJSONFile( filename, &dict ) ) 161 tr_bencInitDict( &dict, 100 ); 162 g_free( filename ); 161 tr_bencInitDict( &settings, 0 ); 162 tr_sessionLoadSettings( &settings, gl_confdir, MY_NAME ); 163 163 loaded = TRUE; 164 164 } 165 165 166 return &dict; 167 } 168 169 /*** 170 **** 171 ***/ 166 return &settings; 167 } 168 169 /*** 170 **** 171 ***/ 172 173 tr_benc* 174 pref_get_all( void ) 175 { 176 return getPrefs( ); 177 } 172 178 173 179 int64_t … … 278 284 279 285 void 280 pref_save( void ) 281 { 282 char * filename = getPrefsFilename( ); 283 char * path = g_path_get_dirname( filename ); 284 285 mkdir_p( path, 0755 ); 286 tr_bencSaveJSONFile( filename, getPrefs( ) ); 287 288 g_free( path ); 289 g_free( filename ); 286 pref_save( tr_session * session ) 287 { 288 tr_sessionSaveSettings( session, gl_confdir, getPrefs( ) ); 290 289 } 291 290 … … 317 316 { 318 317 assert( gl_confdir != NULL ); 319 return g_build_filename( 320 318 319 return g_build_filename( g_get_home_dir( ), ".transmission", "gtk", "prefs", NULL ); 321 320 } 322 321 … … 325 324 { 326 325 assert( gl_confdir != NULL ); 327 return g_build_filename( 328 326 327 return g_build_filename( g_get_home_dir( ), ".transmission", "gtk", "prefs.ini", NULL ); 329 328 } 330 329 … … 332 331 getCompat121PrefsFilename( void ) 333 332 { 334 return g_build_filename( 335 g_get_user_config_dir( ), "transmission", "gtk", "prefs.ini", 336 NULL ); 333 return g_build_filename( g_get_user_config_dir( ), "transmission", "gtk", "prefs.ini", NULL ); 337 334 } 338 335 … … 341 338 const char* newfile ) 342 339 { 343 static struct pref_entry 344 { 340 static struct pref_entry { 345 341 const char* oldkey; 346 342 const char* newkey; -
trunk/gtk/conf.h
r6795 r7367 23 23 *****************************************************************************/ 24 24 25 struct tr_benc; 26 struct tr_handle; 27 25 28 /** 26 29 *** … … 30 33 #define TG_CONF_H 31 34 32 int64_t pref_int_get( const char * key ); 35 int64_t pref_int_get ( const char * key ); 36 void pref_int_set ( const char * key, int64_t value ); 37 void pref_int_set_default ( const char * key, int64_t value ); 33 38 34 void pref_int_set( const char * key, 35 int64_t value ); 39 gboolean pref_flag_get ( const char * key ); 40 void pref_flag_set ( const char * key, gboolean value ); 41 void pref_flag_set_default ( const char * key, gboolean value ); 36 42 37 void pref_int_set_default( const char * key, 38 int64_t value ); 43 const char* pref_string_get ( const char * key ); 44 void pref_string_set ( const char * key, const char * value ); 45 void pref_string_set_default( const char * key, const char * value ); 39 46 40 gboolean pref_flag_get( const char * key ); 41 42 void pref_flag_set( const char * key, 43 gboolean value ); 44 45 void pref_flag_set_default( const char * key, 46 gboolean value ); 47 48 const char* pref_string_get( const char * key ); 49 50 void pref_string_set( const char * key, 51 const char * value ); 52 53 void pref_string_set_default( const char * key, 54 const char * value ); 55 56 void pref_save( void ); 47 void pref_save ( struct tr_handle * ); 48 struct tr_benc* pref_get_all ( void ); 57 49 58 50 /** -
trunk/gtk/main.c
r7255 r7367 68 68 #include <libtransmission/transmission.h> 69 69 #include <libtransmission/version.h> 70 71 #define MY_NAME "transmission" 70 72 71 73 /* interval in milliseconds to update the torrent list display */ … … 353 355 gboolean startpaused = FALSE; 354 356 gboolean startminimized = FALSE; 355 char * domain = "transmission";357 char * domain = MY_NAME; 356 358 char * configDir = NULL; 357 359 tr_lockfile_state_t tr_state; … … 403 405 404 406 if( configDir == NULL ) 405 configDir = (char*) tr_getDefaultConfigDir( );407 configDir = (char*) tr_getDefaultConfigDir( MY_NAME ); 406 408 407 409 tr_notify_init( ); 408 409 410 didinit = cf_init( configDir, NULL ); /* must come before actions_init */ 410 411 tr_prefs_init_global( ); 412 411 413 myUIManager = gtk_ui_manager_new ( ); 412 414 actions_init ( myUIManager, cbdata ); 413 gtk_ui_manager_add_ui_from_string ( myUIManager, fallback_ui_file, -1, 414 NULL ); 415 gtk_ui_manager_add_ui_from_string ( myUIManager, fallback_ui_file, -1, NULL ); 415 416 gtk_ui_manager_ensure_update ( myUIManager ); 416 gtk_window_set_default_icon_name ( "transmission");417 gtk_window_set_default_icon_name ( MY_NAME ); 417 418 418 419 setupsighandlers( ); /* set up handlers for fatal signals */ … … 441 442 { 442 443 GtkWindow * win; 443 444 tr_session * h = tr_sessionInitFull( 445 configDir, 446 "gtk", 447 pref_string_get( PREF_KEY_DOWNLOAD_DIR ), 448 pref_flag_get( PREF_KEY_PEX ), 449 pref_flag_get( PREF_KEY_PORT_FORWARDING ), 450 pref_int_get( PREF_KEY_PORT ), 451 pref_int_get( PREF_KEY_ENCRYPTION ), 452 pref_flag_get( PREF_KEY_LAZY_BITFIELD ), 453 pref_flag_get( PREF_KEY_UL_LIMIT_ENABLED ), 454 pref_int_get( PREF_KEY_UL_LIMIT ), 455 pref_flag_get( PREF_KEY_DL_LIMIT_ENABLED ), 456 pref_int_get( PREF_KEY_DL_LIMIT ), 457 pref_int_get( PREF_KEY_MAX_PEERS_GLOBAL ), 458 pref_int_get( PREF_KEY_MSGLEVEL ), 459 TRUE, /* message queueing */ 460 pref_flag_get( PREF_KEY_BLOCKLIST_ENABLED ), 461 pref_int_get( PREF_KEY_PEER_SOCKET_TOS ), 462 pref_flag_get( PREF_KEY_RPC_ENABLED ), 463 pref_int_get( PREF_KEY_RPC_PORT ), 464 pref_flag_get( PREF_KEY_RPC_WHITELIST_ENABLED ), 465 pref_string_get( PREF_KEY_RPC_WHITELIST ), 466 pref_flag_get( PREF_KEY_RPC_AUTH_ENABLED ), 467 pref_string_get( PREF_KEY_RPC_USERNAME ), 468 pref_string_get( PREF_KEY_RPC_PASSWORD ), 469 pref_flag_get( PREF_KEY_PROXY_SERVER_ENABLED ), 470 pref_string_get( PREF_KEY_PROXY_SERVER ), 471 pref_int_get( PREF_KEY_PROXY_PORT ), 472 pref_int_get( PREF_KEY_PROXY_TYPE ), 473 pref_flag_get( PREF_KEY_PROXY_AUTH_ENABLED ), 474 pref_string_get( PREF_KEY_PROXY_USERNAME ), 475 pref_string_get( PREF_KEY_PROXY_PASSWORD ) ); 476 477 cbdata->core = tr_core_new( h ); 444 tr_session * session; 445 446 /* initialize the libtransmission session */ 447 session = tr_sessionInit( "gtk", configDir, TRUE, pref_get_all( ) ); 448 cbdata->core = tr_core_new( session ); 478 449 479 450 /* create main window now to be a parent to any error dialogs */ 480 451 win = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) ); 481 g_signal_connect( win, "size-allocate", 482 G_CALLBACK( onMainWindowSizeAllocated ), cbdata ); 452 g_signal_connect( win, "size-allocate", G_CALLBACK( onMainWindowSizeAllocated ), cbdata ); 483 453 484 454 appsetup( win, argfiles, cbdata, startpaused, startminimized ); 485 tr_sessionSetRPCCallback( h, onRPCChanged, cbdata );455 tr_sessionSetRPCCallback( session, onRPCChanged, cbdata ); 486 456 gtr_blocklist_maybe_autoupdate( cbdata->core ); 487 457 … … 556 526 tr_inf ( _( "Ending use of scheduled bandwidth limits" ) ); 557 527 558 b = pref_flag_get( PREF_KEY_DL_LIMIT_ENABLED );528 b = pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ); 559 529 tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, b ); 560 limit = pref_int_get( PREF_KEY_DL_LIMIT);530 limit = pref_int_get( TR_PREFS_KEY_DSPEED ); 561 531 tr_sessionSetSpeedLimit( tr, TR_DOWN, limit ); 562 b = pref_flag_get( PREF_KEY_UL_LIMIT_ENABLED );532 b = pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ); 563 533 tr_sessionSetSpeedLimitEnabled( tr, TR_UP, b ); 564 limit = pref_int_get( PREF_KEY_UL_LIMIT);534 limit = pref_int_get( TR_PREFS_KEY_USPEED ); 565 535 tr_sessionSetSpeedLimit( tr, TR_UP, limit ); 566 536 } … … 1059 1029 tr_session * tr = tr_core_session( cbdata->core ); 1060 1030 1061 if( !strcmp( key, PREF_KEY_ENCRYPTION ) )1031 if( !strcmp( key, TR_PREFS_KEY_ENCRYPTION ) ) 1062 1032 { 1063 1033 const int encryption = pref_int_get( key ); … … 1065 1035 tr_sessionSetEncryption( tr, encryption ); 1066 1036 } 1067 else if( !strcmp( key, PREF_KEY_PORT ) )1037 else if( !strcmp( key, TR_PREFS_KEY_PEER_PORT ) ) 1068 1038 { 1069 1039 const int port = pref_int_get( key ); … … 1081 1051 } 1082 1052 } 1083 else if( !strcmp( key, PREF_KEY_DL_LIMIT_ENABLED ) )1053 else if( !strcmp( key, TR_PREFS_KEY_DSPEED_ENABLED ) ) 1084 1054 { 1085 1055 const gboolean b = pref_flag_get( key ); 1086 1056 tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, b ); 1087 1057 } 1088 else if( !strcmp( key, PREF_KEY_DL_LIMIT) )1058 else if( !strcmp( key, TR_PREFS_KEY_DSPEED ) ) 1089 1059 { 1090 1060 const int limit = pref_int_get( key ); 1091 1061 tr_sessionSetSpeedLimit( tr, TR_DOWN, limit ); 1092 1062 } 1093 else if( !strcmp( key, PREF_KEY_UL_LIMIT_ENABLED ) )1063 else if( !strcmp( key, TR_PREFS_KEY_USPEED_ENABLED ) ) 1094 1064 { 1095 1065 const gboolean b = pref_flag_get( key ); 1096 1066 tr_sessionSetSpeedLimitEnabled( tr, TR_UP, b ); 1097 1067 } 1098 else if( !strcmp( key, PREF_KEY_UL_LIMIT) )1068 else if( !strcmp( key, TR_PREFS_KEY_USPEED ) ) 1099 1069 { 1100 1070 const int limit = pref_int_get( key ); … … 1105 1075 updateScheduledLimits( tr ); 1106 1076 } 1107 else if( !strcmp( key, PREF_KEY_PORT_FORWARDING ) )1077 else if( !strcmp( key, TR_PREFS_KEY_PORT_FORWARDING ) ) 1108 1078 { 1109 1079 const gboolean enabled = pref_flag_get( key ); 1110 1080 tr_sessionSetPortForwardingEnabled( tr, enabled ); 1111 1081 } 1112 else if( !strcmp( key, PREF_KEY_PEX) )1082 else if( !strcmp( key, TR_PREFS_KEY_PEX_ENABLED ) ) 1113 1083 { 1114 1084 const gboolean b = pref_flag_get( key ); 1115 1085 tr_sessionSetPortForwardingEnabled( tr, b ); 1116 1086 } 1117 else if( !strcmp( key, PREF_KEY_RPC_ENABLED ) )1087 else if( !strcmp( key, TR_PREFS_KEY_RPC_ENABLED ) ) 1118 1088 { 1119 1089 tr_sessionSetRPCEnabled( tr, pref_flag_get( key ) ); 1120 1090 } 1121 else if( !strcmp( key, PREF_KEY_RPC_PORT ) )1091 else if( !strcmp( key, TR_PREFS_KEY_RPC_PORT ) ) 1122 1092 { 1123 1093 tr_sessionSetRPCPort( tr, pref_int_get( key ) ); 1124 1094 } 1125 else if( !strcmp( key, PREF_KEY_RPC_ENABLED ) )1095 else if( !strcmp( key, TR_PREFS_KEY_RPC_ENABLED ) ) 1126 1096 { 1127 1097 tr_sessionSetRPCEnabled( tr, pref_flag_get( key ) ); 1128 1098 } 1129 else if( !strcmp( key, PREF_KEY_RPC_WHITELIST ) )1099 else if( !strcmp( key, TR_PREFS_KEY_RPC_WHITELIST ) ) 1130 1100 { 1131 1101 const char * s = pref_string_get( key ); 1132 1102 tr_sessionSetRPCWhitelist( tr, s ); 1133 1103 } 1134 else if( !strcmp( key, PREF_KEY_RPC_WHITELIST_ENABLED ) )1104 else if( !strcmp( key, TR_PREFS_KEY_RPC_WHITELIST_ENABLED ) ) 1135 1105 { 1136 1106 tr_sessionSetRPCWhitelistEnabled( tr, pref_flag_get( key ) ); 1137 1107 } 1138 else if( !strcmp( key, PREF_KEY_RPC_USERNAME ) )1108 else if( !strcmp( key, TR_PREFS_KEY_RPC_USERNAME ) ) 1139 1109 { 1140 1110 const char * s = pref_string_get( key ); 1141 1111 tr_sessionSetRPCUsername( tr, s ); 1142 1112 } 1143 else if( !strcmp( key, PREF_KEY_RPC_PASSWORD ) )1113 else if( !strcmp( key, TR_PREFS_KEY_RPC_PASSWORD ) ) 1144 1114 { 1145 1115 const char * s = pref_string_get( key ); 1146 1116 tr_sessionSetRPCPassword( tr, s ); 1147 1117 } 1148 else if( !strcmp( key, PREF_KEY_RPC_AUTH_ENABLED ) )1118 else if( !strcmp( key, TR_PREFS_KEY_RPC_AUTH_REQUIRED ) ) 1149 1119 { 1150 1120 const gboolean enabled = pref_flag_get( key ); 1151 1121 tr_sessionSetRPCPasswordEnabled( tr, enabled ); 1152 1122 } 1153 else if( !strcmp( key, PREF_KEY_PROXY_SERVER) )1123 else if( !strcmp( key, TR_PREFS_KEY_PROXY ) ) 1154 1124 { 1155 1125 const char * s = pref_string_get( key ); 1156 1126 tr_sessionSetProxy( tr, s ); 1157 1127 } 1158 else if( !strcmp( key, PREF_KEY_PROXY_TYPE ) )1128 else if( !strcmp( key, TR_PREFS_KEY_PROXY_TYPE ) ) 1159 1129 { 1160 1130 const int i = pref_int_get( key ); 1161 1131 tr_sessionSetProxyType( tr, i ); 1162 1132 } 1163 else if( !strcmp( key, PREF_KEY_PROXY_SERVER_ENABLED ) )1133 else if( !strcmp( key, TR_PREFS_KEY_PROXY_ENABLED ) ) 1164 1134 { 1165 1135 const gboolean enabled = pref_flag_get( key ); 1166 1136 tr_sessionSetProxyEnabled( tr, enabled ); 1167 1137 } 1168 else if( !strcmp( key, PREF_KEY_PROXY_AUTH_ENABLED ) )1138 else if( !strcmp( key, TR_PREFS_KEY_PROXY_AUTH_ENABLED ) ) 1169 1139 { 1170 1140 const gboolean enabled = pref_flag_get( key ); 1171 1141 tr_sessionSetProxyAuthEnabled( tr, enabled ); 1172 1142 } 1173 else if( !strcmp( key, PREF_KEY_PROXY_USERNAME ) )1143 else if( !strcmp( key, TR_PREFS_KEY_PROXY_USERNAME ) ) 1174 1144 { 1175 1145 const char * s = pref_string_get( key ); 1176 1146 tr_sessionSetProxyUsername( tr, s ); 1177 1147 } 1178 else if( !strcmp( key, PREF_KEY_PROXY_PASSWORD ) )1148 else if( !strcmp( key, TR_PREFS_KEY_RPC_PASSWORD ) ) 1179 1149 { 1180 1150 const char * s = pref_string_get( key ); … … 1238 1208 "website-label", website_url, 1239 1209 "copyright", 1240 _( 1241 "Copyright 2005-2008 The Transmission Project" ), 1242 "logo-icon-name", "transmission", 1210 _( "Copyright 2005-2008 The Transmission Project" ), 1211 "logo-icon-name", MY_NAME, 1243 1212 #ifdef SHOW_LICENSE 1244 1213 "license", LICENSE, -
trunk/gtk/msgwin.c
r6807 r7367 69 69 70 70 tr_setMessageLevel( level ); 71 tr_core_set_pref_int( data->core, PREF_KEY_MSGLEVEL, level );71 tr_core_set_pref_int( data->core, TR_PREFS_KEY_MSGLEVEL, level ); 72 72 data->maxLevel = level; 73 73 gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( data->filter ) ); … … 406 406 store = gtk_list_store_new ( 2, G_TYPE_STRING, G_TYPE_INT ); 407 407 408 curlevel = pref_int_get( PREF_KEY_MSGLEVEL );408 curlevel = pref_int_get( TR_PREFS_KEY_MSGLEVEL ); 409 409 for( i = ii = 0; i < G_N_ELEMENTS( trLevels ); ++i ) 410 410 { … … 520 520 COL_SEQUENCE, 521 521 GTK_SORT_ASCENDING ); 522 data->maxLevel = pref_int_get( PREF_KEY_MSGLEVEL );522 data->maxLevel = pref_int_get( TR_PREFS_KEY_MSGLEVEL ); 523 523 gtk_tree_model_filter_set_visible_func( GTK_TREE_MODEL_FILTER( data-> 524 524 filter ), -
trunk/gtk/tr-core.c
r7255 r7367 164 164 GObjectClass * parent; 165 165 166 pref_save( );167 166 core->priv = NULL; 168 167 … … 450 449 if( tr_ctorGetPeerLimit( ctor, TR_FORCE, NULL ) ) 451 450 tr_ctorSetPeerLimit( ctor, TR_FORCE, 452 pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) );451 pref_int_get( TR_PREFS_KEY_PEER_LIMIT_TORRENT ) ); 453 452 454 453 if( tr_ctorGetDownloadDir( ctor, TR_FORCE, NULL ) ) 455 454 { 456 const char * path = pref_string_get( PREF_KEY_DOWNLOAD_DIR );455 const char * path = pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR ); 457 456 tr_ctorSetDownloadDir( ctor, TR_FORCE, path ); 458 457 } … … 585 584 setSort( core, mode, isReversed ); 586 585 } 587 else if( !strcmp( key, PREF_KEY_MAX_PEERS_GLOBAL ) )586 else if( !strcmp( key, TR_PREFS_KEY_PEER_LIMIT_GLOBAL ) ) 588 587 { 589 588 const uint16_t val = pref_int_get( key ); … … 685 684 prefsChanged( core, PREF_KEY_SORT_REVERSED, NULL ); 686 685 prefsChanged( core, PREF_KEY_DIR_WATCH_ENABLED, NULL ); 687 prefsChanged( core, PREF_KEY_MAX_PEERS_GLOBAL, NULL );686 prefsChanged( core, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, NULL ); 688 687 prefsChanged( core, PREF_KEY_INHIBIT_HIBERNATION, NULL ); 689 g_signal_connect( core, "prefs-changed", G_CALLBACK( 690 prefsChanged ), NULL ); 688 g_signal_connect( core, "prefs-changed", G_CALLBACK( prefsChanged ), NULL ); 691 689 692 690 return core; … … 701 699 { 702 700 core->priv->session = NULL; 701 pref_save( session ); 703 702 tr_sessionClose( session ); 704 703 } … … 820 819 tr_ctorSetPaused( ctor, TR_FORCE, TRUE ); 821 820 tr_ctorSetPeerLimit( ctor, TR_FALLBACK, 822 pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) );821 pref_int_get( TR_PREFS_KEY_PEER_LIMIT_TORRENT ) ); 823 822 824 823 torrents = tr_sessionLoadTorrents ( tr_core_session( self ), ctor, &count ); … … 1226 1225 const char * key ) 1227 1226 { 1228 pref_save( );1227 pref_save( tr_core_session( core ) ); 1229 1228 g_signal_emit( core, TR_CORE_GET_CLASS( core )->prefsig, 0, key ); 1230 1229 } -
trunk/gtk/tr-prefs.c
r7356 r7367 36 36 tr_prefs_init_global( void ) 37 37 { 38 int i;39 char pw[32];40 38 const char * str; 41 const char * pool = "abcdefghijklmnopqrstuvwxyz"42 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"43 "1234567890";44 GRand * rand;45 39 46 40 cf_check_older_configs( ); … … 54 48 #endif 55 49 56 pref_int_set_default ( PREF_KEY_PEER_SOCKET_TOS,57 TR_DEFAULT_PEER_SOCKET_TOS );58 50 pref_flag_set_default ( PREF_KEY_INHIBIT_HIBERNATION, FALSE ); 59 pref_flag_set_default ( PREF_KEY_BLOCKLIST_ENABLED, TRUE );60 51 pref_flag_set_default ( PREF_KEY_BLOCKLIST_UPDATES_ENABLED, TRUE ); 61 52 62 53 pref_string_set_default ( PREF_KEY_OPEN_DIALOG_FOLDER, g_get_home_dir( ) ); 63 64 pref_int_set_default ( PREF_KEY_MAX_PEERS_GLOBAL,65 TR_DEFAULT_GLOBAL_PEER_LIMIT );66 pref_int_set_default ( PREF_KEY_MAX_PEERS_PER_TORRENT, 50 );67 54 68 55 pref_flag_set_default ( PREF_KEY_TOOLBAR, TRUE ); … … 72 59 pref_string_set_default ( PREF_KEY_STATUSBAR_STATS, "total-ratio" ); 73 60 74 pref_flag_set_default ( PREF_KEY_DL_LIMIT_ENABLED, FALSE );75 pref_int_set_default ( PREF_KEY_DL_LIMIT, 100 );76 pref_flag_set_default ( PREF_KEY_UL_LIMIT_ENABLED, FALSE );77 pref_int_set_default ( PREF_KEY_UL_LIMIT, 50 );78 61 pref_flag_set_default ( PREF_KEY_SCHED_LIMIT_ENABLED, FALSE ); 79 62 pref_int_set_default ( PREF_KEY_SCHED_BEGIN, 60 * 23 ); /* 11pm */ 80 63 pref_int_set_default ( PREF_KEY_SCHED_END, 60 * 7 ); /* 7am */ 81 pref_int_set_default ( PREF_KEY_SCHED_DL_LIMIT, 200 ); /* 2x the other 82 limit */ 83 pref_int_set_default ( PREF_KEY_SCHED_UL_LIMIT, 100 ); /* 2x the other 84 limit */ 64 pref_int_set_default ( PREF_KEY_SCHED_DL_LIMIT, 200 ); /* 2x the other limit */ 65 pref_int_set_default ( PREF_KEY_SCHED_UL_LIMIT, 100 ); /* 2x the other limit */ 85 66 86 67 pref_flag_set_default ( PREF_KEY_OPTIONS_PROMPT, TRUE ); … … 90 71 pref_int_set_default ( PREF_KEY_MAIN_WINDOW_X, 50 ); 91 72 pref_int_set_default ( PREF_KEY_MAIN_WINDOW_Y, 50 ); 92 93 pref_string_set_default ( PREF_KEY_PROXY_SERVER, "" );94 pref_int_set_default ( PREF_KEY_PROXY_PORT, TR_DEFAULT_PROXY_PORT );95 pref_int_set_default ( PREF_KEY_PROXY_TYPE, TR_DEFAULT_PROXY_TYPE );96 pref_flag_set_default ( PREF_KEY_PROXY_SERVER_ENABLED,97 TR_DEFAULT_PROXY_ENABLED );98 pref_flag_set_default ( PREF_KEY_PROXY_AUTH_ENABLED,99 TR_DEFAULT_PROXY_AUTH_ENABLED );100 pref_string_set_default ( PREF_KEY_PROXY_USERNAME, "" );101 pref_string_set_default ( PREF_KEY_PROXY_PASSWORD, "" );102 73 103 74 str = NULL; … … 106 77 #endif 107 78 if( !str ) str = g_get_home_dir( ); 108 pref_string_set_default ( PREF_KEY_DOWNLOAD_DIR, str ); 109 110 pref_int_set_default ( PREF_KEY_PORT, TR_DEFAULT_PORT ); 111 112 pref_flag_set_default ( PREF_KEY_PORT_FORWARDING, TRUE ); 113 pref_flag_set_default ( PREF_KEY_PEX, TR_DEFAULT_PEX_ENABLED ); 79 pref_string_set_default ( TR_PREFS_KEY_DOWNLOAD_DIR, str ); 80 114 81 pref_flag_set_default ( PREF_KEY_ASKQUIT, TRUE ); 115 pref_flag_set_default ( PREF_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION );116 pref_flag_set_default ( PREF_KEY_LAZY_BITFIELD,117 TR_DEFAULT_LAZY_BITFIELD_ENABLED );118 119 pref_int_set_default ( PREF_KEY_MSGLEVEL, TR_MSG_INF );120 82 121 83 pref_string_set_default ( PREF_KEY_SORT_MODE, "sort-by-name" ); … … 125 87 pref_flag_set_default ( PREF_KEY_START, TRUE ); 126 88 pref_flag_set_default ( PREF_KEY_TRASH_ORIGINAL, FALSE ); 127 128 pref_flag_set_default ( PREF_KEY_RPC_ENABLED, TR_DEFAULT_RPC_ENABLED );129 pref_int_set_default ( PREF_KEY_RPC_PORT, TR_DEFAULT_RPC_PORT );130 pref_string_set_default ( PREF_KEY_RPC_WHITELIST, TR_DEFAULT_RPC_WHITELIST );131 pref_flag_set_default ( PREF_KEY_RPC_WHITELIST_ENABLED,132 TR_DEFAULT_RPC_WHITELIST_ENABLED );133 134 rand = g_rand_new ( );135 for( i = 0; i < 16; ++i )136 pw[i] = pool[g_rand_int_range ( rand, 0, strlen( pool ) )];137 g_rand_free ( rand );138 139 pw[16] = '\0';140 pref_string_set_default( PREF_KEY_RPC_USERNAME, "transmission" );141 pref_string_set_default( PREF_KEY_RPC_PASSWORD, pw );142 pref_flag_set_default ( PREF_KEY_RPC_AUTH_ENABLED, FALSE );143 144 pref_save( );145 89 } 146 90 … … 376 320 hig_workarea_add_wide_control( t, &row, w ); 377 321 378 w = new_path_chooser_button( PREF_KEY_DOWNLOAD_DIR, core );322 w = new_path_chooser_button( TR_PREFS_KEY_DOWNLOAD_DIR, core ); 379 323 hig_workarea_add_row( t, &row, _( "_Destination folder:" ), w, NULL ); 380 324 … … 511 455 : TR_ENCRYPTION_PREFERRED; 512 456 513 tr_core_set_pref_int( TR_CORE( core ), PREF_KEY_ENCRYPTION, val );457 tr_core_set_pref_int( TR_CORE( core ), TR_PREFS_KEY_ENCRYPTION, val ); 514 458 } 515 459 … … 531 475 hig_workarea_add_section_title( t, &row, _( "Blocklist" ) ); 532 476 533 w = new_check_button( "", PREF_KEY_BLOCKLIST_ENABLED, core );477 w = new_check_button( "", TR_PREFS_KEY_BLOCKLIST_ENABLED, core ); 534 478 updateBlocklistText( w, TR_CORE( core ) ); 535 479 h = gtk_hbox_new( FALSE, GUI_PAD_BIG ); … … 554 498 hig_workarea_add_section_title( t, &row, _( "Limits" ) ); 555 499 556 w = new_spin_button( PREF_KEY_MAX_PEERS_GLOBAL, core, 1, 3000, 5 );500 w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, 3000, 5 ); 557 501 hig_workarea_add_row( t, &row, _( "Maximum peers _overall:" ), w, NULL ); 558 w = new_spin_button( PREF_KEY_MAX_PEERS_PER_TORRENT, core, 1, 300, 5 ); 559 hig_workarea_add_row( t, &row, _( 560 "Maximum peers per _torrent:" ), w, NULL ); 502 w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, 300, 5 ); 503 hig_workarea_add_row( t, &row, _( "Maximum peers per _torrent:" ), w, NULL ); 561 504 562 505 hig_workarea_add_section_divider( t, &row ); … … 566 509 w = gtk_check_button_new_with_mnemonic( s ); 567 510 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), 568 pref_int_get( 569 PREF_KEY_ENCRYPTION ) == 511 pref_int_get( TR_PREFS_KEY_ENCRYPTION ) == 570 512 TR_ENCRYPTION_REQUIRED ); 571 513 g_signal_connect( w, "toggled", G_CALLBACK( onEncryptionToggled ), core ); … … 573 515 574 516 s = _( "Use peer e_xchange" ); 575 w = new_check_button( s, PREF_KEY_PEX, core );517 w = new_check_button( s, TR_PREFS_KEY_PEX_ENABLED, core ); 576 518 hig_workarea_add_wide_control( t, &row, w ); 577 519 … … 649 591 g_string_truncate( gstr, gstr->len - 1 ); /* remove the trailing comma */ 650 592 651 tr_core_set_pref( page->core, PREF_KEY_RPC_WHITELIST, gstr->str );593 tr_core_set_pref( page->core, TR_PREFS_KEY_RPC_WHITELIST, gstr->str ); 652 594 653 595 g_string_free( gstr, TRUE ); … … 758 700 gpointer data UNUSED ) 759 701 { 760 int port = pref_int_get( PREF_KEY_RPC_PORT );702 int port = pref_int_get( TR_PREFS_KEY_RPC_PORT ); 761 703 char * url = g_strdup_printf( "http://localhost:%d/transmission/web", 762 704 port ); … … 785 727 /* "enabled" checkbutton */ 786 728 s = _( "_Enable web interface" ); 787 w = new_check_button( s, PREF_KEY_RPC_ENABLED, core );729 w = new_check_button( s, TR_PREFS_KEY_RPC_ENABLED, core ); 788 730 page->rpc_tb = GTK_TOGGLE_BUTTON( w ); 789 731 g_signal_connect( w, "clicked", G_CALLBACK( onRPCToggled ), page ); … … 797 739 798 740 /* port */ 799 w = new_spin_button( PREF_KEY_RPC_PORT, core, 0, 65535, 1 );741 w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 0, 65535, 1 ); 800 742 page->widgets = g_slist_append( page->widgets, w ); 801 743 w = hig_workarea_add_row( t, &row, _( "Listening _port:" ), w, NULL ); … … 804 746 /* require authentication */ 805 747 s = _( "_Require username" ); 806 w = new_check_button( s, PREF_KEY_RPC_AUTH_ENABLED, core );748 w = new_check_button( s, TR_PREFS_KEY_RPC_AUTH_REQUIRED, core ); 807 749 hig_workarea_add_wide_control( t, &row, w ); 808 750 page->auth_tb = GTK_TOGGLE_BUTTON( w ); … … 812 754 /* username */ 813 755 s = _( "_Username:" ); 814 w = new_entry( PREF_KEY_RPC_USERNAME, core );756 w = new_entry( TR_PREFS_KEY_RPC_USERNAME, core ); 815 757 page->auth_widgets = g_slist_append( page->auth_widgets, w ); 816 758 w = hig_workarea_add_row( t, &row, s, w, NULL ); … … 819 761 /* password */ 820 762 s = _( "Pass_word:" ); 821 w = new_entry( PREF_KEY_RPC_PASSWORD, core );763 w = new_entry( TR_PREFS_KEY_RPC_PASSWORD, core ); 822 764 gtk_entry_set_visibility( GTK_ENTRY( w ), FALSE ); 823 765 page->auth_widgets = g_slist_append( page->auth_widgets, w ); … … 827 769 /* require authentication */ 828 770 s = _( "Only allow the following IP _addresses to connect:" ); 829 w = new_check_button( s, PREF_KEY_RPC_WHITELIST_ENABLED, core );771 w = new_check_button( s, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, core ); 830 772 hig_workarea_add_wide_control( t, &row, w ); 831 773 page->whitelist_tb = GTK_TOGGLE_BUTTON( w ); … … 835 777 /* access control list */ 836 778 { 837 const char * val = pref_string_get( PREF_KEY_RPC_WHITELIST );779 const char * val = pref_string_get( TR_PREFS_KEY_RPC_WHITELIST ); 838 780 GtkTreeModel * m = whitelist_tree_model_new( val ); 839 781 GtkTreeViewColumn * c; … … 920 862 { 921 863 GSList * l; 922 const gboolean proxy_enabled = pref_flag_get( 923 PREF_KEY_PROXY_SERVER_ENABLED ); 924 const gboolean proxy_auth_enabled = pref_flag_get( 925 PREF_KEY_PROXY_AUTH_ENABLED ); 864 const gboolean proxy_enabled = pref_flag_get( TR_PREFS_KEY_PROXY_ENABLED ); 865 const gboolean proxy_auth_enabled = pref_flag_get( TR_PREFS_KEY_PROXY_AUTH_ENABLED ); 926 866 927 867 for( l = p->proxy_widgets; l != NULL; l = l->next ) … … 974 914 { 975 915 struct ProxyPage * page = gpage; 976 int type = TR_PROXY_HTTP; 977 gtk_tree_model_get( gtk_combo_box_get_model( 978 w ), &iter, 1, &type, -1 ); 979 tr_core_set_pref_int( TR_CORE( 980 page->core ), PREF_KEY_PROXY_TYPE, type ); 916 int type = TR_PROXY_HTTP; 917 gtk_tree_model_get( gtk_combo_box_get_model( w ), &iter, 1, &type, -1 ); 918 tr_core_set_pref_int( TR_CORE( page->core ), TR_PREFS_KEY_PROXY_TYPE, type ); 981 919 } 982 920 } … … 999 937 1000 938 s = _( "Connect to tracker via a pro_xy" ); 1001 w = new_check_button( s, PREF_KEY_PROXY_SERVER_ENABLED, core );939 w = new_check_button( s, TR_PREFS_KEY_PROXY_ENABLED, core ); 1002 940 g_signal_connect( w, "toggled", G_CALLBACK( onProxyToggled ), page ); 1003 941 hig_workarea_add_wide_control( t, &row, w ); 1004 942 1005 943 s = _( "Proxy _server:" ); 1006 w = new_entry( PREF_KEY_PROXY_SERVER, core );944 w = new_entry( TR_PREFS_KEY_PROXY, core ); 1007 945 page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); 1008 946 w = hig_workarea_add_row( t, &row, s, w, NULL ); 1009 947 page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); 1010 948 1011 w = new_spin_button( PREF_KEY_PROXY_PORT, core, 0, 65535, 1 );949 w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 0, 65535, 1 ); 1012 950 page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); 1013 951 w = hig_workarea_add_row( t, &row, _( "Proxy _port:" ), w, NULL ); … … 1019 957 r = gtk_cell_renderer_text_new( ); 1020 958 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( w ), r, TRUE ); 1021 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( 1022 w ), r, "text", 0, NULL ); 1023 gtk_combo_box_set_active( GTK_COMBO_BOX( w ), 1024 pref_int_get( PREF_KEY_PROXY_TYPE ) ); 959 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( w ), r, "text", 0, NULL ); 960 gtk_combo_box_set_active( GTK_COMBO_BOX( w ), pref_int_get( TR_PREFS_KEY_PROXY_TYPE ) ); 1025 961 g_signal_connect( w, "changed", G_CALLBACK( onProxyTypeChanged ), page ); 1026 962 g_object_unref( G_OBJECT( m ) ); … … 1030 966 1031 967 s = _( "_Authentication is required" ); 1032 w = new_check_button( s, PREF_KEY_PROXY_AUTH_ENABLED, core );968 w = new_check_button( s, TR_PREFS_KEY_PROXY_AUTH_ENABLED, core ); 1033 969 g_signal_connect( w, "toggled", G_CALLBACK( onProxyToggled ), page ); 1034 970 hig_workarea_add_wide_control( t, &row, w ); … … 1036 972 1037 973 s = _( "_Username:" ); 1038 w = new_entry( PREF_KEY_PROXY_USERNAME, core );974 w = new_entry( TR_PREFS_KEY_PROXY_USERNAME, core ); 1039 975 page->proxy_auth_widgets = g_slist_append( page->proxy_auth_widgets, w ); 1040 976 w = hig_workarea_add_row( t, &row, s, w, NULL ); … … 1042 978 1043 979 s = _( "Pass_word:" ); 1044 w = new_entry( PREF_KEY_PROXY_PASSWORD, core );980 w = new_entry( TR_PREFS_KEY_RPC_PASSWORD, core ); 1045 981 gtk_entry_set_visibility( GTK_ENTRY( w ), FALSE ); 1046 982 page->proxy_auth_widgets = g_slist_append( page->proxy_auth_widgets, w ); … … 1166 1102 1167 1103 s = _( "Limit _download speed (KB/s):" ); 1168 w = new_check_button( s, PREF_KEY_DL_LIMIT_ENABLED, core ); 1169 w2 = new_spin_button( PREF_KEY_DL_LIMIT, core, 0, INT_MAX, 5 ); 1170 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), 1171 pref_flag_get( PREF_KEY_DL_LIMIT_ENABLED ) ); 1104 w = new_check_button( s, TR_PREFS_KEY_DSPEED_ENABLED, core ); 1105 w2 = new_spin_button( TR_PREFS_KEY_DSPEED, core, 0, INT_MAX, 5 ); 1106 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ) ); 1172 1107 g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 ); 1173 1108 hig_workarea_add_row_w( t, &row, w, w2, NULL ); 1174 1109 1175 1110 s = _( "Limit _upload speed (KB/s):" ); 1176 w = new_check_button( s, PREF_KEY_UL_LIMIT_ENABLED, core ); 1177 w2 = new_spin_button( PREF_KEY_UL_LIMIT, core, 0, INT_MAX, 5 ); 1178 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), 1179 pref_flag_get( PREF_KEY_UL_LIMIT_ENABLED ) ); 1111 w = new_check_button( s, TR_PREFS_KEY_USPEED_ENABLED, core ); 1112 w2 = new_spin_button( TR_PREFS_KEY_USPEED, core, 0, INT_MAX, 5 ); 1113 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ) ); 1180 1114 g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 ); 1181 1115 hig_workarea_add_row_w( t, &row, w, w2, NULL ); … … 1202 1136 w = new_spin_button( PREF_KEY_SCHED_DL_LIMIT, core, 0, INT_MAX, 5 ); 1203 1137 page->sched_widgets = g_slist_append( page->sched_widgets, w ); 1204 l = hig_workarea_add_row( t, &row, _( 1205 "Limit d_ownload speed (KB/s):" ), w, 1206 NULL ); 1138 l = hig_workarea_add_row( t, &row, _( "Limit d_ownload speed (KB/s):" ), w, NULL ); 1207 1139 page->sched_widgets = g_slist_append( page->sched_widgets, l ); 1208 1140 1209 1141 w = new_spin_button( PREF_KEY_SCHED_UL_LIMIT, core, 0, INT_MAX, 5 ); 1210 1142 page->sched_widgets = g_slist_append( page->sched_widgets, w ); 1211 l = hig_workarea_add_row( t, &row, _( 1212 "Limit u_pload speed (KB/s):" ), w, NULL ); 1143 l = hig_workarea_add_row( t, &row, _( "Limit u_pload speed (KB/s):" ), w, NULL ); 1213 1144 page->sched_widgets = g_slist_append( page->sched_widgets, l ); 1214 1145 … … 1300 1231 gpointer gdata ) 1301 1232 { 1302 if( !strcmp( key, PREF_KEY_PORT ) )1233 if( !strcmp( key, TR_PREFS_KEY_PEER_PORT ) ) 1303 1234 { 1304 1235 struct network_page_data * ndata = gdata; … … 1355 1286 1356 1287 h = gtk_hbox_new( FALSE, GUI_PAD_BIG ); 1357 w2 = new_spin_button( PREF_KEY_PORT, core, 1, 65535, 1 );1288 w2 = new_spin_button( TR_PREFS_KEY_PEER_PORT, core, 1, 65535, 1 ); 1358 1289 gtk_box_pack_start( GTK_BOX( h ), w2, FALSE, FALSE, 0 ); 1359 1290 data->label = l = gtk_label_new( NULL ); … … 1365 1296 g_object_set_data( G_OBJECT( l ), "session", 1366 1297 tr_core_session( TR_CORE( core ) ) ); 1367 data->id = g_signal_connect( TR_CORE( 1368 core ), "prefs-changed", 1298 data->id = g_signal_connect( TR_CORE( core ), "prefs-changed", 1369 1299 G_CALLBACK( onCorePrefsChanged ), data ); 1370 onCorePrefsChanged( NULL, PREF_KEY_PORT, data );1300 onCorePrefsChanged( NULL, TR_PREFS_KEY_PEER_PORT, data ); 1371 1301 1372 1302 s = _( "Use UPnP or NAT-PMP port _forwarding from my router" ); 1373 w = new_check_button( s, PREF_KEY_PORT_FORWARDING, core );1303 w = new_check_button( s, TR_PREFS_KEY_PORT_FORWARDING, core ); 1374 1304 hig_workarea_add_wide_control( t, &row, w ); 1375 1305 -
trunk/gtk/tr-prefs.h
r6870 r7367 22 22 * default in tr_prefs_init_global( void ) */ 23 23 24 #define PREF_KEY_DL_LIMIT_ENABLED "download-limit-enabled"25 #define PREF_KEY_DL_LIMIT "download-limit"26 #define PREF_KEY_UL_LIMIT_ENABLED "upload-limit-enabled"27 #define PREF_KEY_UL_LIMIT "upload-limit"28 24 #define PREF_KEY_SCHED_LIMIT_ENABLED "sched-limit-enabled" 29 25 #define PREF_KEY_SCHED_BEGIN "sched-begin" … … 32 28 #define PREF_KEY_SCHED_UL_LIMIT "sched-upload-limit" 33 29 #define PREF_KEY_OPTIONS_PROMPT "show-options-window" 34 #define PREF_KEY_DOWNLOAD_DIR "download-dir"35 30 #define PREF_KEY_OPEN_DIALOG_FOLDER "open-dialog-dir" 36 31 #define PREF_KEY_INHIBIT_HIBERNATION "inhibit-desktop-hibernation" … … 40 35 #define PREF_KEY_START "start-added-torrents" 41 36 #define PREF_KEY_TRASH_ORIGINAL "trash-original-torrent-files" 42 #define PREF_KEY_PEER_SOCKET_TOS "peer-socket-tos"43 #define PREF_KEY_PORT "peer-port"44 #define PREF_KEY_PORT_FORWARDING "port-forwarding-enabled"45 #define PREF_KEY_PEX "pex-enabled"46 37 #define PREF_KEY_ASKQUIT "prompt-before-exit" 47 #define PREF_KEY_ENCRYPTION "encryption"48 #define PREF_KEY_MSGLEVEL "debug-message-level"49 #define PREF_KEY_LAZY_BITFIELD "lazy-bitfield-enabled"50 38 #define PREF_KEY_SORT_MODE "sort-mode" 51 39 #define PREF_KEY_SORT_REVERSED "sort-reversed" … … 55 43 #define PREF_KEY_STATUSBAR_STATS "statusbar-stats" 56 44 #define PREF_KEY_TOOLBAR "show-toolbar" 57 #define PREF_KEY_MAX_PEERS_GLOBAL "max-peers-global"58 #define PREF_KEY_MAX_PEERS_PER_TORRENT "max-peers-per-torrent"59 #define PREF_KEY_BLOCKLIST_ENABLED "blocklist-enabled"60 45 #define PREF_KEY_BLOCKLIST_UPDATES_ENABLED "blocklist-updates-enabled" 61 46 #define PREF_KEY_MAIN_WINDOW_HEIGHT "main-window-height" … … 63 48 #define PREF_KEY_MAIN_WINDOW_X "main-window-x" 64 49 #define PREF_KEY_MAIN_WINDOW_Y "main-window-y" 65 #define PREF_KEY_RPC_PORT "rpc-port"66 #define PREF_KEY_RPC_ENABLED "rpc-enabled"67 #define PREF_KEY_RPC_WHITELIST "rpc-whitelist"68 #define PREF_KEY_RPC_WHITELIST_ENABLED "rpc-whitelist-enabled"69 #define PREF_KEY_RPC_AUTH_ENABLED "rpc-authentication-required"70 #define PREF_KEY_RPC_PASSWORD "rpc-password"71 #define PREF_KEY_RPC_USERNAME "rpc-username"72 #define PREF_KEY_PROXY_SERVER "proxy-server"73 #define PREF_KEY_PROXY_PORT "proxy-port"74 #define PREF_KEY_PROXY_SERVER_ENABLED "proxy-server-enabled"75 #define PREF_KEY_PROXY_TYPE "proxy-type"76 #define PREF_KEY_PROXY_AUTH_ENABLED "proxy-authentication-required"77 #define PREF_KEY_PROXY_USERNAME "proxy-username"78 #define PREF_KEY_PROXY_PASSWORD "proxy-authentication"79 50 80 51 -
trunk/libtransmission/bandwidth.c
r7337 r7367 270 270 271 271 /* notify the io buffers that there's more bandwidth available */ 272 if( !b->band[dir].isLimited || ( b->band[dir].bytesLeft > 0 ) )273 272 { 274 273 int i; -
trunk/libtransmission/bencode.c
r7360 r7367 421 421 const int success = tr_bencIsInt( val ); 422 422 423 if( success )423 if( success && setme ) 424 424 *setme = val->val.i; 425 425 426 return success; 426 427 } … … 445 446 if( child ) 446 447 found = tr_bencGetInt( child, setme ); 448 447 449 return found; 448 450 } … … 454 456 const tr_bool success = tr_bencDictFindStr( dict, key, &str ); 455 457 456 if( success )458 if( success && setme ) 457 459 *setme = strtod( str, NULL ); 458 460 … … 468 470 if( child ) 469 471 { 470 *setme = child; 472 if( setme != NULL ) 473 *setme = child; 471 474 found = TRUE; 472 475 } … … 483 486 if( child ) 484 487 { 485 *setme = child; 488 if( setme != NULL ) 489 *setme = child; 486 490 found = TRUE; 487 491 } … … 498 502 if( child ) 499 503 { 500 *setme = child->val.s.s; 504 if( setme ) 505 *setme = child->val.s.s; 501 506 found = TRUE; 502 507 } … … 679 684 int64_t val ) 680 685 { 681 tr_benc * child = tr_bencDictAdd( dict, key ); 682 686 tr_benc * child; 687 688 /* see if it already exists, and if so, try to reuse it */ 689 if(( child = tr_bencDictFind( dict, key ))) { 690 if( !tr_bencIsInt( child ) ) { 691 tr_bencDictRemove( dict, key ); 692 child = NULL; 693 } 694 } 695 696 /* if it doesn't exist, create it */ 697 if( child == NULL ) 698 child = tr_bencDictAdd( dict, key ); 699 700 /* set it */ 683 701 tr_bencInitInt( child, val ); 702 684 703 return child; 685 704 } 686 705 687 706 tr_benc* 688 tr_bencDictAddStr( tr_benc * dict, 689 const char * key, 690 const char * val ) 691 { 692 tr_benc * child = tr_bencDictAdd( dict, key ); 693 707 tr_bencDictAddStr( tr_benc * dict, const char * key, const char * val ) 708 { 709 tr_benc * child; 710 711 /* see if it already exists, and if so, try to reuse it */ 712 if(( child = tr_bencDictFind( dict, key ))) { 713 if( tr_bencIsString( child ) ) 714 tr_free( child->val.s.s ); 715 else { 716 tr_bencDictRemove( dict, key ); 717 child = NULL; 718 } 719 } 720 721 /* if it doesn't exist, create it */ 722 if( child == NULL ) 723 child = tr_bencDictAdd( dict, key ); 724 725 /* set it */ 694 726 tr_bencInitStr( child, val, -1 ); 727 695 728 return child; 696 729 } -
trunk/libtransmission/bencode.h
r7359 r7367 183 183 **/ 184 184 185 void tr_bencMergeDicts( tr_benc * b1, const tr_benc * b2 );185 void tr_bencMergeDicts( tr_benc * target, const tr_benc * source ); 186 186 187 187 #endif -
trunk/libtransmission/platform.c
r7232 r7367 409 409 410 410 const char* 411 tr_getDefaultConfigDir( void)411 tr_getDefaultConfigDir( const char * appname ) 412 412 { 413 413 static char * s = NULL; 414 415 if( !appname || !*appname ) 416 appname = "Transmission"; 414 417 415 418 if( !s ) … … 422 425 { 423 426 #ifdef SYS_DARWIN 424 s = tr_buildPath( getHomeDir( ), "Library", 425 "Application Support", "Transmission", NULL );427 s = tr_buildPath( getHomeDir( ), "Library", "Application Support", 428 appname, NULL ); 426 429 #elif defined( WIN32 ) 427 430 char appdata[MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */ 428 431 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); 429 s = tr_buildPath( appdata, "Transmission", NULL );432 s = tr_buildPath( appdata, appname, NULL ); 430 433 #else 431 434 if( ( s = getenv( "XDG_CONFIG_HOME" ) ) ) 432 s = tr_buildPath( s, "transmission", NULL );435 s = tr_buildPath( s, appname, NULL ); 433 436 else 434 s = tr_buildPath( getHomeDir( ), ".config", "transmission", NULL );437 s = tr_buildPath( getHomeDir( ), ".config", appname, NULL ); 435 438 #endif 436 439 } -
trunk/libtransmission/rpc-server.c
r7224 r7367 697 697 s->session = session; 698 698 s->port = port; 699 s->whitelist = tr_strdup( whitelist && *whitelist 700 ? whitelist 701 : TR_DEFAULT_RPC_WHITELIST ); 699 s->whitelist = tr_strdup( whitelist && *whitelist ? whitelist : "127.0.0.1" ); 702 700 s->username = tr_strdup( username ); 703 701 s->password = tr_strdup( password ); -
trunk/libtransmission/session.c
r7366 r7367 23 23 #include "transmission.h" 24 24 #include "bandwidth.h" 25 #include "bencode.h" 25 26 #include "blocklist.h" 26 27 #include "fdlimit.h" … … 40 41 #include "crypto.h" 41 42 42 #define PORT_RANDOM_MIN 1024 43 #define PORT_RANDOM_MAX 65535 43 static tr_port 44 getRandomPort( tr_session * s ) 45 { 46 return tr_cryptoWeakRandInt( s->randomPortHigh - s->randomPortLow + 1) + s->randomPortLow; 47 } 44 48 45 49 /* Generate a peer id : "-TRxyzb-" + 12 random alphanumeric … … 198 202 ***/ 199 203 204 #ifdef TR_EMBEDDED 205 #define TR_DEFAULT_ENCRYPTION TR_CLEAR_PREFERRED 206 #else 207 #define TR_DEFAULT_ENCRYPTION TR_ENCRYPTION_PREFERRED 208 #endif 209 210 void 211 tr_sessionGetDefaultSettings( tr_benc * d ) 212 { 213 assert( tr_bencIsDict( d ) ); 214 215 tr_bencDictReserve( d, 30 ); 216 tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); 217 tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) ); 218 tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED, 100 ); 219 tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED, 0 ); 220 tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION ); 221 tr_bencDictAddInt( d, TR_PREFS_KEY_LAZY_BITFIELD, TRUE ); 222 tr_bencDictAddInt( d, TR_PREFS_KEY_MSGLEVEL, TR_MSG_INF ); 223 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, 240 ); 224 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, 60 ); 225 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT, atoi( TR_DEFAULT_PEER_PORT_STR ) ); 226 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ENABLED, FALSE ); 227 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, 1024 ); 228 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, 65535 ); 229 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi( TR_DEFAULT_PEER_SOCKET_TOS_STR ) ); 230 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, TRUE ); 231 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); 232 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, "" ); 233 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, FALSE ); 234 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_ENABLED, FALSE ); 235 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_PASSWORD, "" ); 236 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_PORT, 80 ); 237 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_TYPE, TR_PROXY_HTTP ); 238 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_USERNAME, "" ); 239 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, FALSE ); 240 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_ENABLED, TRUE ); 241 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_PASSWORD, "" ); 242 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_USERNAME, "" ); 243 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_WHITELIST, TR_DEFAULT_RPC_WHITELIST ); 244 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, TRUE ); 245 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_PORT, atoi( TR_DEFAULT_RPC_PORT_STR ) ); 246 tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED, 100 ); 247 tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED, 0 ); 248 } 249 250 void 251 tr_sessionGetSettings( tr_session * s, struct tr_benc * d ) 252 { 253 int i, n=0; 254 char * freeme[16]; 255 256 assert( tr_bencIsDict( d ) ); 257 258 tr_bencDictReserve( d, 30 ); 259 tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) ); 260 tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, s->downloadDir ); 261 tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED, tr_sessionGetSpeedLimit( s, TR_DOWN ) ); 262 tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimitEnabled( s, TR_DOWN ) ); 263 tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION, s->encryptionMode ); 264 tr_bencDictAddInt( d, TR_PREFS_KEY_LAZY_BITFIELD, s->useLazyBitfield ); 265 tr_bencDictAddInt( d, TR_PREFS_KEY_MSGLEVEL, tr_getMessageLevel( ) ); 266 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, tr_sessionGetPeerLimit( s ) ); 267 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, s->peerLimitPerTorrent ); 268 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( s ) ); 269 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ENABLED, s->isPortRandom ); 270 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, s->randomPortLow ); 271 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, s->randomPortHigh ); 272 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, s->peerSocketTOS ); 273 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, s->isPexEnabled ); 274 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled( s ) ); 275 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, s->proxy ); 276 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, s->isProxyAuthEnabled ); 277 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_ENABLED, s->isProxyEnabled ); 278 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_PASSWORD, s->proxyPassword ); 279 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_PORT, s->proxyPort ); 280 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_TYPE, s->proxyType ); 281 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_USERNAME, s->proxyUsername ); 282 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled( s ) ); 283 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_ENABLED, tr_sessionIsRPCEnabled( s ) ); 284 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_PASSWORD, freeme[n++] = tr_sessionGetRPCPassword( s ) ); 285 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_PORT, tr_sessionGetRPCPort( s ) ); 286 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_USERNAME, freeme[n++] = tr_sessionGetRPCUsername( s ) ); 287 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_WHITELIST, freeme[n++] = tr_sessionGetRPCWhitelist( s ) ); 288 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled( s ) ); 289 tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED, tr_sessionGetSpeedLimit( s, TR_UP ) ); 290 tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimitEnabled( s, TR_UP ) ); 291 292 for( i=0; i<n; ++i ) 293 tr_free( freeme[i] ); 294 } 295 296 void 297 tr_sessionLoadSettings( tr_benc * d, const char * configDir, const char * appName ) 298 { 299 char * filename; 300 tr_benc fileSettings; 301 302 assert( tr_bencIsDict( d ) ); 303 304 /* get the defaults */ 305 tr_sessionGetDefaultSettings( d ); 306 307 /* if caller didn't specify a config dir, use the default */ 308 if( !configDir || !*configDir ) 309 configDir = tr_getDefaultConfigDir( appName ); 310 311 /* file settings override the defaults */ 312 filename = tr_buildPath( configDir, "settings.json", NULL ); 313 if( !tr_bencLoadJSONFile( filename, &fileSettings ) ) { 314 tr_bencMergeDicts( d, &fileSettings ); 315 tr_bencFree( &fileSettings ); 316 } 317 318 /* cleanup */ 319 tr_free( filename ); 320 } 321 322 void 323 tr_sessionSaveSettings( tr_session * session, const char * configDir, tr_benc * settings ) 324 { 325 tr_benc fileSettings; 326 char * filename; 327 328 assert( tr_bencIsDict( settings ) ); 329 330 filename = tr_buildPath( configDir, "settings.json", NULL ); 331 332 tr_sessionGetSettings( session, settings ); 333 334 if( tr_bencLoadJSONFile( filename, &fileSettings ) ) { 335 tr_bencSaveJSONFile( filename, settings ); 336 } else { 337 tr_bencMergeDicts( &fileSettings, settings ); 338 tr_bencSaveJSONFile( filename, &fileSettings ); 339 tr_bencFree( &fileSettings ); 340 } 341 342 tr_inf( "saved \"%s\"", filename ); 343 tr_free( filename ); 344 } 345 200 346 static void metainfoLookupRescan( tr_handle * h ); 201 347 202 tr_handle * 203 tr_sessionInitFull( const char * configDir, 204 const char * tag, 205 const char * downloadDir, 206 int isPexEnabled, 207 int isPortForwardingEnabled, 208 int publicPort, 209 tr_encryption_mode encryptionMode, 210 int useLazyBitfield, 211 int useUploadLimit, 212 int uploadLimit, 213 int useDownloadLimit, 214 int downloadLimit, 215 int globalPeerLimit, 216 int messageLevel, 217 int isMessageQueueingEnabled, 218 int isBlocklistEnabled, 219 int peerSocketTOS, 220 int rpcIsEnabled, 221 tr_port rpcPort, 222 int rpcWhitelistIsEnabled, 223 const char * rpcWhitelist, 224 int rpcAuthIsEnabled, 225 const char * rpcUsername, 226 const char * rpcPassword, 227 int proxyIsEnabled, 228 const char * proxy, 229 int proxyPort, 230 tr_proxy_type proxyType, 231 int proxyAuthIsEnabled, 232 const char * proxyUsername, 233 const char * proxyPassword ) 234 { 235 tr_handle * h; 236 char * filename; 348 tr_session * 349 tr_sessionInit( const char * tag, 350 const char * configDir, 351 tr_bool messageQueuingEnabled, 352 tr_benc * clientSettings ) 353 { 354 int64_t i; 355 int64_t j; 356 tr_bool found; 357 const char * str; 358 tr_benc settings; 359 tr_session * session; 360 char * filename; 361 int64_t rpc_enabled, whitelist_enabled, rpc_auth_enabled, rpc_port; 362 const char * whitelist = NULL, *rpc_passwd = NULL, *rpc_username = NULL; 363 364 assert( tr_bencIsDict( clientSettings ) ); 365 366 session = tr_new0( tr_session, 1 ); 367 session->bandwidth = tr_bandwidthNew( session, NULL ); 368 session->lock = tr_lockNew( ); 369 session->tag = tr_strdup( tag ); 370 371 tr_bencInitDict( &settings, 0 ); 372 tr_sessionGetDefaultSettings( &settings ); 373 tr_bencMergeDicts( &settings, clientSettings ); 237 374 238 375 #ifndef WIN32 … … 242 379 243 380 tr_msgInit( ); 244 tr_setMessageLevel( messageLevel ); 245 tr_setMessageQueuing( isMessageQueueingEnabled ); 246 247 h = tr_new0( tr_handle, 1 ); 248 h->lock = tr_lockNew( ); 249 h->isPexEnabled = isPexEnabled ? 1 : 0; 250 h->encryptionMode = encryptionMode; 251 h->peerSocketTOS = peerSocketTOS; 252 h->downloadDir = tr_strdup( downloadDir ); 253 h->isProxyEnabled = proxyIsEnabled ? 1 : 0; 254 h->proxy = tr_strdup( proxy ); 255 h->proxyPort = proxyPort; 256 h->proxyType = proxyType; 257 h->isProxyAuthEnabled = proxyAuthIsEnabled != 0; 258 h->proxyUsername = tr_strdup( proxyUsername ); 259 h->proxyPassword = tr_strdup( proxyPassword ); 260 h->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */ 261 h->so_rcvbuf = 8192; 262 263 if( configDir == NULL ) 264 configDir = tr_getDefaultConfigDir( ); 265 tr_setConfigDir( h, configDir ); 381 382 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i ); 383 assert( found ); 384 session->peerLimitPerTorrent = i; 385 386 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_MSGLEVEL, &i ); 387 assert( found ); 388 tr_setMessageLevel( i ); 389 tr_setMessageQueuing( messageQueuingEnabled ); 390 391 392 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEX_ENABLED, &i ); 393 assert( found ); 394 session->isPexEnabled = i != 0; 395 396 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ENCRYPTION, &i ); 397 assert( found ); 398 session->encryptionMode = i; 399 400 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ); 401 assert( found ); 402 session->peerSocketTOS = i; 403 404 found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str ); 405 assert( found ); 406 session->downloadDir = tr_strdup( str ); 407 408 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_ENABLED, &i ); 409 assert( found ); 410 session->isProxyEnabled = i != 0; 411 412 found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY, &str ); 413 assert( found ); 414 session->proxy = tr_strdup( str ); 415 416 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_PORT, &i ); 417 assert( found ); 418 session->proxyPort = i; 419 420 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_TYPE, &i ); 421 assert( found ); 422 session->proxyType = i; 423 424 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_AUTH_ENABLED, &i ); 425 assert( found ); 426 session->isProxyAuthEnabled = i != 0; 427 428 found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY_USERNAME, &str ); 429 assert( found ); 430 session->proxyUsername = tr_strdup( str ); 431 432 found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY_PASSWORD, &str ); 433 assert( found ); 434 session->proxyPassword = tr_strdup( str ); 435 436 session->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */ 437 session->so_rcvbuf = 8192; 438 439 tr_setConfigDir( session, configDir ); 266 440 267 441 tr_netInit( ); /* must go before tr_eventInit */ 268 442 269 tr_eventInit( h);270 while( ! h->events )443 tr_eventInit( session ); 444 while( !session->events ) 271 445 tr_wait( 50 ); 272 446 273 h->tag = tr_strdup( tag ); 274 h->peerMgr = tr_peerMgrNew( h ); 275 276 h->useLazyBitfield = useLazyBitfield != 0; 447 session->peerMgr = tr_peerMgrNew( session ); 448 449 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_LAZY_BITFIELD, &i ); 450 assert( found ); 451 session->useLazyBitfield = i != 0; 277 452 278 453 /* Initialize rate and file descripts controls */ 279 454 280 tr_fdInit( globalPeerLimit ); 281 282 /* random port */ 283 if ( publicPort == -1 ) 284 publicPort = tr_cryptoWeakRandInt(PORT_RANDOM_MAX - PORT_RANDOM_MIN + 1) + PORT_RANDOM_MIN; 285 286 h->shared = tr_sharedInit( h, isPortForwardingEnabled, publicPort ); 287 h->isPortSet = publicPort >= 0; 288 289 h->bandwidth = tr_bandwidthNew( h, NULL ); 290 tr_sessionSetSpeedLimit ( h, TR_UP, uploadLimit ); 291 tr_sessionSetSpeedLimitEnabled( h, TR_UP, useUploadLimit ); 292 tr_sessionSetSpeedLimit ( h, TR_DOWN, downloadLimit ); 293 tr_sessionSetSpeedLimitEnabled( h, TR_DOWN, useDownloadLimit ); 294 455 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i ); 456 assert( found ); 457 tr_fdInit( i ); 458 459 /** 460 *** random port 461 **/ 462 463 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_ENABLED, &i ); 464 assert( found ); 465 session->isPortRandom = i != 0; 466 467 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, &i ); 468 assert( found ); 469 session->randomPortLow = i; 470 471 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, &i ); 472 assert( found ); 473 session->randomPortHigh = i; 474 475 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PORT_FORWARDING, &i ) 476 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &j ); 477 assert( found ); 478 session->peerPort = session->isPortRandom ? getRandomPort( session ) : j; 479 session->shared = tr_sharedInit( session, i, session->peerPort ); 480 session->isPortSet = session->isPortRandom || j>0; 481 session->bandwidth = tr_bandwidthNew( session, NULL ); 482 483 /** 484 **/ 485 486 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_USPEED, &i ) 487 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_USPEED_ENABLED, &j ); 488 assert( found ); 489 tr_sessionSetSpeedLimit( session, TR_UP, i ); 490 tr_sessionSetSpeedLimitEnabled( session, TR_UP, j ); 491 492 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_DSPEED, &i ) 493 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_DSPEED_ENABLED, &j ); 494 assert( found ); 495 tr_sessionSetSpeedLimit( session, TR_DOWN, i ); 496 tr_sessionSetSpeedLimitEnabled( session, TR_DOWN, j ); 497 295 498 /* first %s is the application name 296 499 second %s is the version number */ … … 298 501 299 502 /* initialize the blocklist */ 300 filename = tr_buildPath( h->configDir, "blocklists", NULL );503 filename = tr_buildPath( session->configDir, "blocklists", NULL ); 301 504 tr_mkdirp( filename, 0777 ); 302 505 tr_free( filename ); 303 h->isBlocklistEnabled = isBlocklistEnabled; 304 loadBlocklists( h ); 305 306 tr_statsInit( h ); 307 308 h->web = tr_webInit( h ); 309 h->rpcServer = tr_rpcInit( h, rpcIsEnabled, rpcPort, 310 rpcWhitelistIsEnabled, rpcWhitelist, 311 rpcAuthIsEnabled, rpcUsername, rpcPassword ); 312 313 metainfoLookupRescan( h ); 314 315 return h; 316 } 317 318 tr_handle * 319 tr_sessionInit( const char * configDir, 320 const char * tag ) 321 { 322 return tr_sessionInitFull( configDir, 323 TR_DEFAULT_DOWNLOAD_DIR, 324 tag, 325 TR_DEFAULT_PEX_ENABLED, 326 TR_DEFAULT_PORT_FORWARDING_ENABLED, 327 -1, /* public port */ 328 TR_DEFAULT_ENCRYPTION, /* encryption mode */ 329 TR_DEFAULT_LAZY_BITFIELD_ENABLED, 330 FALSE, /* use upload speed limit? */ 331 -1, /* upload speed limit */ 332 FALSE, /* use download speed limit? */ 333 -1, /* download speed limit */ 334 TR_DEFAULT_GLOBAL_PEER_LIMIT, 335 TR_MSG_INF, /* message level */ 336 FALSE, /* is message queueing enabled? */ 337 FALSE, /* is the blocklist enabled? */ 338 TR_DEFAULT_PEER_SOCKET_TOS, 339 TR_DEFAULT_RPC_ENABLED, 340 TR_DEFAULT_RPC_PORT, 341 TR_DEFAULT_RPC_WHITELIST_ENABLED, 342 TR_DEFAULT_RPC_WHITELIST, 343 FALSE, 344 "fnord", 345 "potzrebie", 346 TR_DEFAULT_PROXY_ENABLED, 347 TR_DEFAULT_PROXY, 348 TR_DEFAULT_PROXY_PORT, 349 TR_DEFAULT_PROXY_TYPE, 350 TR_DEFAULT_PROXY_AUTH_ENABLED, 351 TR_DEFAULT_PROXY_USERNAME, 352 TR_DEFAULT_PROXY_PASSWORD ); 506 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &i ); 507 assert( found ); 508 session->isBlocklistEnabled = i; 509 loadBlocklists( session ); 510 511 tr_statsInit( session ); 512 513 session->web = tr_webInit( session ); 514 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_ENABLED, &rpc_enabled ) 515 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_PORT, &rpc_port ) 516 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &whitelist_enabled ) 517 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &rpc_auth_enabled ) 518 && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, &whitelist ) 519 && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_USERNAME, &rpc_username ) 520 && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_PASSWORD, &rpc_passwd ); 521 assert( found ); 522 session->rpcServer = tr_rpcInit( session, rpc_enabled, rpc_port, whitelist_enabled, whitelist, 523 rpc_auth_enabled, rpc_username, rpc_passwd ); 524 525 metainfoLookupRescan( session ); 526 527 return session; 353 528 } 354 529 … … 421 596 } 422 597 423 void 424 tr_sessionSetPeerPort( tr_session * session, 425 tr_port port ) 598 static void 599 setPortImpl( tr_session * session, tr_port port ) 426 600 { 427 601 struct bind_port_data * data = tr_new( struct bind_port_data, 1 ); 428 429 602 data->session = session; 430 603 data->port = port; … … 432 605 } 433 606 607 void 608 tr_sessionSetPeerPort( tr_session * session, 609 tr_port port ) 610 { 611 session->isPortRandom = FALSE; 612 session->peerPort = port; 613 setPortImpl( session, session->peerPort ); 614 } 615 434 616 tr_port 435 617 tr_sessionSetPeerPortRandom( tr_session * session ) 436 618 { 437 const tr_port port = tr_cryptoWeakRandInt(PORT_RANDOM_MAX - PORT_RANDOM_MIN + 1) + PORT_RANDOM_MIN; 438 tr_sessionSetPeerPort( session, port); 439 return port; 619 session->isPortRandom = TRUE; 620 session->peerPort = getRandomPort( session ); 621 setPortImpl( session, session->peerPort ); 622 return session->peerPort; 440 623 } 441 624 442 625 tr_port 443 tr_sessionGetPeerPort( const tr_handle * h ) 444 { 445 assert( h ); 446 return tr_sharedGetPeerPort( h->shared ); 626 tr_sessionGetPeerPort( const tr_session * session ) 627 { 628 assert( session ); 629 630 return session->peerPort; 447 631 } 448 632 … … 523 707 524 708 uint16_t 525 tr_sessionGetPeerLimit( const tr_ handle * handleUNUSED )709 tr_sessionGetPeerLimit( const tr_session * session UNUSED ) 526 710 { 527 711 return tr_fdGetPeerLimit( ); … … 1057 1241 } 1058 1242 1059 int 1243 tr_bool 1060 1244 tr_sessionGetRPCWhitelistEnabled( const tr_session * session ) 1061 1245 { … … 1097 1281 } 1098 1282 1099 int 1283 tr_bool 1100 1284 tr_sessionIsRPCPasswordEnabled( const tr_session * session ) 1101 1285 { … … 1107 1291 ***/ 1108 1292 1109 int 1293 tr_bool 1110 1294 tr_sessionIsProxyEnabled( const tr_session * session ) 1111 1295 { … … 1139 1323 } 1140 1324 1141 int1325 tr_port 1142 1326 tr_sessionGetProxyPort( const tr_session * session ) 1143 1327 { … … 1163 1347 } 1164 1348 1165 int 1349 tr_bool 1166 1350 tr_sessionIsProxyAuthEnabled( const tr_session * session ) 1167 1351 { -
trunk/libtransmission/session.h
r7366 r7367 59 59 { 60 60 tr_bool isPortSet; 61 tr_bool isPortRandom; 61 62 tr_bool isPexEnabled; 62 63 tr_bool isBlocklistEnabled; … … 73 74 struct tr_event_handle * events; 74 75 76 uint16_t peerLimitPerTorrent; 77 78 tr_port peerPort; 79 tr_port randomPortLow; 80 tr_port randomPortHigh; 81 75 82 int proxyPort; 76 83 int peerSocketTOS; … … 80 87 81 88 char * tag; 82 83 89 char * configDir; 84 90 char * downloadDir; -
trunk/libtransmission/torrent-ctor.c
r7251 r7367 19 19 #include "utils.h" 20 20 21 #define DEFAULT_MAX_CONNECTED_PEERS 5022 23 21 struct optional_args 24 22 { … … 36 34 struct tr_ctor 37 35 { 38 const tr_ handle * handle;36 const tr_session * session; 39 37 tr_bool saveInOurTorrentsDir; 40 38 tr_bool doDelete; … … 140 138 const char * filename; 141 139 142 filename = tr_sessionFindTorrentFile( ctor-> handle, hashString );140 filename = tr_sessionFindTorrentFile( ctor->session, hashString ); 143 141 if( !filename ) 144 142 err = EINVAL; … … 299 297 300 298 tr_ctor* 301 tr_ctorNew( const tr_ handle * handle)299 tr_ctorNew( const tr_session * session ) 302 300 { 303 301 tr_ctor * ctor = tr_new0( struct tr_ctor, 1 ); 304 302 305 ctor-> handle = handle;306 tr_ctorSetPeerLimit( ctor, TR_FALLBACK, DEFAULT_MAX_CONNECTED_PEERS);303 ctor->session = session; 304 tr_ctorSetPeerLimit( ctor, TR_FALLBACK, session->peerLimitPerTorrent ); 307 305 tr_ctorSetPaused( ctor, TR_FALLBACK, FALSE ); 308 tr_ctorSetDownloadDir( ctor, TR_FALLBACK, handle->downloadDir );306 tr_ctorSetDownloadDir( ctor, TR_FALLBACK, session->downloadDir ); 309 307 tr_ctorSetSave( ctor, TRUE ); 310 308 return ctor; -
trunk/libtransmission/torrent.c
r7331 r7367 534 534 tr_peerMgrAddTorrent( h->peerMgr, tor ); 535 535 536 if( !h->isPortSet ) 537 tr_sessionSetPeerPort( h, TR_DEFAULT_PORT ); 536 assert( h->isPortSet ); 538 537 539 538 assert( !tor->downloadedCur ); -
trunk/libtransmission/transmission.h
r7366 r7367 65 65 * The default configuration directory is determined this way: 66 66 * 1. If the TRANSMISSION_HOME environmental variable is set, its value is used. 67 * 2. On Darwin, "${HOME}/Library/Application Support/ Transmission" is used.68 * 3. On Windows, "${CSIDL_APPDATA}/ Transmission" is used.69 * 4. If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/ transmission" is used.70 * 5. ${HOME}/.config/ transmission" is used as a last resort.71 */ 72 const char* tr_getDefaultConfigDir( void);67 * 2. On Darwin, "${HOME}/Library/Application Support/${appname}" is used. 68 * 3. On Windows, "${CSIDL_APPDATA}/${appname}" is used. 69 * 4. If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/${appname}" is used. 70 * 5. ${HOME}/.config/${appname}" is used as a last resort. 71 */ 72 const char* tr_getDefaultConfigDir( const char * appname ); 73 73 74 74 /** … … 92 92 * @addtogroup tr_session Session 93 93 * 94 * A libtransmission session is created by calling either tr_sessionInit Full()94 * A libtransmission session is created by calling either tr_sessionInit() 95 95 * or tr_sessionInit(). libtransmission creates a thread for itself so that 96 96 * it can operate independently of the caller's event loop. The session will … … 108 108 tr_proxy_type; 109 109 110 /** @see tr_sessionInitFull */111 #define TR_DEFAULT_CONFIG_DIR tr_getDefaultConfigDir( )112 /** @see tr_sessionInitFull */113 #define TR_DEFAULT_DOWNLOAD_DIR tr_getDefaultDownloadDir( )114 /** @see tr_sessionInitFull */115 #ifdef TR_EMBEDDED116 #define TR_DEFAULT_ENCRYPTION TR_CLEAR_PREFERRED117 #else118 #define TR_DEFAULT_ENCRYPTION TR_ENCRYPTION_PREFERRED119 #endif120 /** @see tr_sessionInitFull */121 #define TR_DEFAULT_PEX_ENABLED 1122 /** @see tr_sessionInitFull */123 #define TR_DEFAULT_PORT_FORWARDING_ENABLED 0124 /** @see tr_sessionInitFull */125 #define TR_DEFAULT_PORT 51413126 /** @see tr_sessionInitFull */127 #define TR_DEFAULT_PORT_STR "51413"128 /** @see tr_sessionInitFull */129 #define TR_DEFAULT_LAZY_BITFIELD_ENABLED 1130 /** @see tr_sessionInitFull */131 #define TR_DEFAULT_GLOBAL_PEER_LIMIT 200132 /** @see tr_sessionInitFull */133 #define TR_DEFAULT_PEER_SOCKET_TOS 8134 /** @see tr_sessionInitFull */135 #define TR_DEFAULT_PEER_SOCKET_TOS_STR "8"136 /** @see tr_sessionInitFull */137 #define TR_DEFAULT_BLOCKLIST_ENABLED 0138 /** @see tr_sessionInitFull */139 #define TR_DEFAULT_RPC_ENABLED 0140 /** @see tr_sessionInitFull */141 #define TR_DEFAULT_RPC_PORT 9091142 /** @see tr_sessionInitFull */143 #define TR_DEFAULT_RPC_PORT_STR "9091"144 /** @see tr_sessionInitFull */145 #define TR_DEFAULT_RPC_WHITELIST "127.0.0.1"146 /** @see tr_sessionInitFull */147 #define TR_DEFAULT_RPC_WHITELIST_ENABLED 0148 /** @see tr_sessionInitFull */149 #define TR_DEFAULT_PROXY_ENABLED 0150 /** @see tr_sessionInitFull */151 #define TR_DEFAULT_PROXY NULL152 /** @see tr_sessionInitFull */153 #define TR_DEFAULT_PROXY_PORT 80154 /** @see tr_sessionInitFull */155 #define TR_DEFAULT_PROXY_TYPE TR_PROXY_HTTP156 /** @see tr_sessionInitFull */157 #define TR_DEFAULT_PROXY_AUTH_ENABLED 0158 /** @see tr_sessionInitFull */159 #define TR_DEFAULT_PROXY_USERNAME NULL160 /** @see tr_sessionInitFull */161 #define TR_DEFAULT_PROXY_PASSWORD NULL162 163 110 typedef enum 164 111 { … … 169 116 tr_encryption_mode; 170 117 171 /** 172 * @brief Start a libtransmission session. 173 * @return an opaque handle to the new session 174 * 175 * @param configDir 176 * The config directory where libtransmission config subdirectories 177 * will be found, such as "torrents", "resume", and "blocklists". 178 * #TR_DEFAULT_CONFIG_DIR can be used as a default. 179 * 180 * @param downloadDir 181 * The default directory to save added torrents. 182 * This can be changed per-session with 183 * tr_sessionSetDownloadDir() and per-torrent with 184 * tr_ctorSetDownloadDir(). 185 * 186 * @param tag 187 * Obsolete. Only used now for locating legacy fastresume files. 188 * This will be removed at some point in the future. 189 * Valid tags: beos cli daemon gtk macos wx 190 * 191 * @param isPexEnabled 192 * whether or not PEX is allowed for non-private torrents. 193 * This can be changed per-session with 194 * tr_sessionSetPexEnabled(). 195 * #TR_DEFAULT_PEX_ENABLED is the default. 196 * 197 * @param isPortForwardingEnabled 198 * If true, libtransmission will attempt 199 * to find a local UPnP-enabled or NATPMP-enabled 200 * router and forward a port from there to the local 201 * machine. This is so remote peers can initiate 202 * connections with us. 203 * #TR_DEFAULT_PORT_FORWARDING_ENABLED is the default. 204 * 205 * @param publicPort 206 * Port number to open for incoming peer connections. 207 * -1 for random port. 208 * #TR_DEFAULT_PORT is the default. 209 * 210 * @param encryptionMode 211 * Must be one of #TR_CLEAR_PREFERRED, 212 * #TR_ENCRYPTION_PREFERRED, or #TR_ENCRYPTION_REQUIRED. 213 * 214 * @param isUploadLimitEnabled 215 * If true, libtransmission will limit the entire 216 * session's upload speed from "uploadLimit". 217 * 218 * @param uploadLimit 219 * The speed limit to use for the entire session when 220 * "isUploadLimitEnabled" is true. Units are KiB/s. 221 * 222 * @param isDownloadLimitEnabled 223 * If true, libtransmission will limit the entire 224 * session's download speed from "downloadLimit". 225 * 226 * @param downloadLimit 227 * The speed limit to use for the entire session when 228 * "isDownloadLimitEnabled" is true. Units are KiB/s. 229 * 230 * @param peerLimit 231 * The maximum number of peer connections allowed in a session. 232 * #TR_DEFAULT_GLOBAL_PEER_LIMIT can be used as a default. 233 * 234 * @param messageLevel 235 * Verbosity level of libtransmission's logging mechanism. 236 * Must be one of #TR_MSG_ERR, #TR_MSG_INF, #TR_MSG_DBG. 237 * 238 * @param isMessageQueueingEnabled 239 * If true, then messages will build up in a queue until 240 * processed by the client application. 241 * 242 * @param isBlocklistEnabled 243 * If true, then Transmission will not allow peer connections 244 * to the IP addressess specified in the blocklist. 245 * 246 * @param peerSocketTOS 247 * 248 * @param rpcIsEnabled 249 * If true, then libtransmission will open an http server port 250 * to listen for incoming RPC requests. 251 * 252 * @param rpcPort 253 * The port on which to listen for incoming RPC requests 254 * 255 * @param rpcWhitelist 256 * The list of IP addresses allowed to make RPC connections. 257 * @see tr_sessionSetRPCWhitelist() 258 * 259 * @see TR_DEFAULT_PEER_SOCKET_TOS 260 * @see TR_DEFAULT_BLOCKLIST_ENABLED 261 * @see TR_DEFAULT_RPC_ENABLED 262 * @see TR_DEFAULT_RPC_PORT 263 * @see TR_DEFAULT_RPC_WHITELIST 264 * @see TR_DEFAULT_RPC_WHITELIST_ENABLED 265 * @see tr_sessionClose() 266 */ 267 tr_session * tr_sessionInitFull( const char * configDir, 268 const char * tag, 269 const char * downloadDir, 270 int isPexEnabled, 271 int isPortForwardingEnabled, 272 int publicPort, 273 tr_encryption_mode encryptionMode, 274 int useLazyBitfield, 275 int useUploadLimit, 276 int uploadLimit, 277 int useDownloadLimit, 278 int downloadLimit, 279 int peerLimit, 280 int messageLevel, 281 int isMessageQueueingEnabled, 282 int isBlocklistEnabled, 283 int peerSocketTOS, 284 int rpcIsEnabled, 285 tr_port rpcPort, 286 int rpcWhitelistIsEnabled, 287 const char * rpcWhitelist, 288 int rpcPasswordIsEnabled, 289 const char * rpcUsername, 290 const char * rpcPassword, 291 int proxyIsEnabled, 292 const char * proxy, 293 int proxyPort, 294 tr_proxy_type proxyType, 295 int proxyAuthIsEnabled, 296 const char * proxyUsername, 297 const char * proxyPassword ); 298 299 300 /** @brief Shorter form of tr_sessionInitFull() 301 @deprecated Use tr_sessionInitFull() instead. */ 302 tr_session * tr_sessionInit( const char * configDir, 303 const char * tag ); 118 #define TR_DEFAULT_RPC_WHITELIST "127.0.0.1" 119 #define TR_DEFAULT_RPC_PORT_STR "9091" 120 #define TR_DEFAULT_PEER_PORT_STR "51413" 121 #define TR_DEFAULT_PEER_SOCKET_TOS_STR "8" 122 123 #define TR_PREFS_KEY_BLOCKLIST_ENABLED "blocklist-enabled" 124 #define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir" 125 #define TR_PREFS_KEY_DSPEED "download-limit" 126 #define TR_PREFS_KEY_DSPEED_ENABLED "download-limit-enabled" 127 #define TR_PREFS_KEY_ENCRYPTION "encryption" 128 #define TR_PREFS_KEY_LAZY_BITFIELD "lazy-bitfield-enabled" 129 #define TR_PREFS_KEY_MSGLEVEL "message-level" 130 #define TR_PREFS_KEY_MSGQUEUE_ENABLED "message-queue-enabled" 131 #define TR_PREFS_KEY_PEER_LIMIT_GLOBAL "peer-limit-global" 132 #define TR_PREFS_KEY_PEER_LIMIT_TORRENT "peer-limit-per-torrent" 133 #define TR_PREFS_KEY_PEER_PORT "peer-port" 134 #define TR_PREFS_KEY_PEER_PORT_RANDOM_ENABLED "peer-port-random-enabled" 135 #define TR_PREFS_KEY_PEER_PORT_RANDOM_LOW "peer-port-random-low" 136 #define TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH "peer-port-random-high" 137 #define TR_PREFS_KEY_PEER_SOCKET_TOS "peer-socket-tos" 138 #define TR_PREFS_KEY_PEX_ENABLED "pex-enabled" 139 #define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled" 140 #define TR_PREFS_KEY_PROXY_AUTH_ENABLED "proxy-auth-enabled" 141 #define TR_PREFS_KEY_PROXY_ENABLED "proxy-enabled" 142 #define TR_PREFS_KEY_PROXY_PASSWORD "proxy-auth-password" 143 #define TR_PREFS_KEY_PROXY_PORT "proxy-port" 144 #define TR_PREFS_KEY_PROXY "proxy" 145 #define TR_PREFS_KEY_PROXY_TYPE "proxy-type" 146 #define TR_PREFS_KEY_PROXY_USERNAME "proxy-auth-username" 147 #define TR_PREFS_KEY_RPC_AUTH_REQUIRED "rpc-authentication-required" 148 #define TR_PREFS_KEY_RPC_ENABLED "rpc-enabled" 149 #define TR_PREFS_KEY_RPC_PASSWORD "rpc-password" 150 #define TR_PREFS_KEY_RPC_PORT "rpc-port" 151 #define TR_PREFS_KEY_RPC_USERNAME "rpc-username" 152 #define TR_PREFS_KEY_RPC_WHITELIST_ENABLED "rpc-whitelist-enabled" 153 #define TR_PREFS_KEY_RPC_WHITELIST "rpc-whitelist" 154 #define TR_PREFS_KEY_USPEED_ENABLED "upload-limit-enabled" 155 #define TR_PREFS_KEY_USPEED "upload-limit" 156 157 struct tr_benc; 158 159 /** 160 * Add libtransmission's default settings to the benc dictionary. 161 * 162 * Example: 163 * @code 164 * tr_benc settings; 165 * int64_t i; 166 * 167 * tr_bencInitDict( &settings, 0 ); 168 * tr_sessionGetDefaultSettings( &settings ); 169 * if( tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &i ) ) 170 * fprintf( stderr, "the default peer port is %d\n", (int)i ); 171 * tr_bencFree( &settings ); 172 * @endcode 173 * 174 * @param initme pointer to a tr_benc dictionary 175 * @see tr_sessionLoadSettings() 176 * @see tr_sessionInit() 177 * @see tr_getDefaultConfigDir() 178 */ 179 void tr_sessionGetDefaultSettings( struct tr_benc * dictionary ); 180 181 /** 182 * Add the session's configuration settings to the benc dictionary. 183 * 184 * FIXME: this probably belongs in libtransmissionapp 185 * 186 * @param session 187 * @param dictionary 188 * @see tr_sessionGetDefaultSettings() 189 */ 190 void tr_sessionGetSettings( tr_session *, struct tr_benc * dictionary ); 191 192 /** 193 * Load settings from the configuration directory's settings.json file, 194 * using libtransmission's default settings as fallbacks for missing keys. 195 * 196 * FIXME: this belongs in libtransmissionapp 197 * 198 * @param configDir the configuration directory to find settings.json 199 * @param initme pointer to an uninitialized tr_benc 200 * @param appName examples: Transmission, transmission-daemon 201 * @see tr_sessionGetDefaultSettings() 202 * @see tr_sessionInit() 203 * @see tr_sessionSaveSettings() 204 */ 205 void tr_sessionLoadSettings( struct tr_benc * dictionary, 206 const char * configDir, 207 const char * appName ); 208 209 /** 210 * Add the session's configuration settings to the benc dictionary 211 * and save it to the configuration directory's settings.json file. 212 * 213 * FIXME: this belongs in libtransmissionapp 214 * 215 * @param session 216 * @param dictionary 217 * @see tr_sessionLoadSettings() 218 */ 219 void tr_sessionSaveSettings( tr_session * session, 220 const char * configDir, 221 struct tr_benc * dictonary ); 222 223 /** 224 * Initialize a libtransmission session. 225 * 226 * For example, this will instantiate a session with all the default values: 227 * @code 228 * tr_benc settings; 229 * tr_session * session; 230 * const char * configDir; 231 * 232 * tr_bencInitDict( &settings, 0 ); 233 * tr_sessionGetDefaultSettings( &settings ); 234 * configDir = tr_getDefaultConfigDir( "Transmission" ); 235 * session = tr_sessionInit( "mac", configDir, true, &settings ); 236 * 237 * tr_bencFree( &settings ); 238 * @encode 239 * 240 * @param tag "gtk", "mac", "daemon", etc... this is only for pre-1.30 resume files 241 * @param configDir where Transmission will look for resume files, blocklists, etc. 242 * @param messageQueueingEnabled if false, messages will be dumped to stderr 243 * @param settings libtransmission settings 244 * @see tr_sessionGetDefaultSettings() 245 * @see tr_sessionLoadSettings() 246 * @see tr_getDefaultConfigDir() 247 */ 248 tr_session * tr_sessionInit( const char * tag, 249 const char * configDir, 250 tr_bool messageQueueingEnabled, 251 struct tr_benc * settings ); 304 252 305 253 /** @brief End a libtransmission session 306 @see tr_sessionInit Full() */307 void 254 @see tr_sessionInit() */ 255 void tr_sessionClose( tr_session * ); 308 256 309 257 /** … … 317 265 /** 318 266 * @brief Set the per-session default download folder for new torrents. 319 * @see tr_sessionInit Full()267 * @see tr_sessionInit() 320 268 * @see tr_sessionGetDownloadDir() 321 269 * @see tr_ctorSetDownloadDir() … … 327 275 * @brief Get the default download folder for new torrents. 328 276 * 329 * This is set by tr_sessionInit Full() or tr_sessionSetDownloadDir(),277 * This is set by tr_sessionInit() or tr_sessionSetDownloadDir(), 330 278 * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir(). 331 279 */ … … 338 286 * for incoming http RPC requests as described in docs/rpc-spec.txt. 339 287 * 340 * This is intially set by tr_sessionInit Full() and can be288 * This is intially set by tr_sessionInit() and can be 341 289 * queried by tr_sessionIsRPCEnabled(). 342 290 */ … … 345 293 346 294 /** @brief Get whether or not RPC calls are allowed in this session. 347 @see tr_sessionInit Full()295 @see tr_sessionInit() 348 296 @see tr_sessionSetRPCEnabled() */ 349 297 int tr_sessionIsRPCEnabled( const tr_session * session ); 350 298 351 299 /** @brief Specify which port to listen for RPC requests on. 352 @see tr_sessionInit Full()300 @see tr_sessionInit() 353 301 @see tr_sessionGetRPCPort */ 354 302 void tr_sessionSetRPCPort( tr_session * session, … … 356 304 357 305 /** @brief Get which port to listen for RPC requests on. 358 @see tr_sessionInit Full()306 @see tr_sessionInit() 359 307 @see tr_sessionSetRPCPort */ 360 308 tr_port tr_sessionGetRPCPort( const tr_session * session ); … … 373 321 /** @brief get the Access Control List for allowing/denying RPC requests. 374 322 @return a comma-separated string of whitelist domains. tr_free() when done. 375 @see tr_sessionInit Full323 @see tr_sessionInit 376 324 @see tr_sessionSetRPCWhitelist */ 377 325 char* tr_sessionGetRPCWhitelist( const tr_session * ); … … 380 328 int isEnabled ); 381 329 382 inttr_sessionGetRPCWhitelistEnabled( const tr_session * session );330 tr_bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session ); 383 331 384 332 void tr_sessionSetRPCPassword( tr_session * session, … … 390 338 /** @brief get the password used to restrict RPC requests. 391 339 @return the password string. tr_free() when done. 392 @see tr_sessionInit Full()340 @see tr_sessionInit() 393 341 @see tr_sessionSetRPCPassword() */ 394 342 char* tr_sessionGetRPCPassword( const tr_session * session ); … … 399 347 int isEnabled ); 400 348 401 inttr_sessionIsRPCPasswordEnabled( const tr_session * session );349 tr_bool tr_sessionIsRPCPasswordEnabled( const tr_session * session ); 402 350 403 351 … … 448 396 **/ 449 397 450 inttr_sessionIsProxyEnabled( const tr_session * );451 452 inttr_sessionIsProxyAuthEnabled( const tr_session * );398 tr_bool tr_sessionIsProxyEnabled( const tr_session * ); 399 400 tr_bool tr_sessionIsProxyAuthEnabled( const tr_session * ); 453 401 454 402 const char* tr_sessionGetProxy( const tr_session * ); 455 403 456 inttr_sessionGetProxyPort( const tr_session * );404 tr_port tr_sessionGetProxyPort( const tr_session * ); 457 405 458 406 tr_proxy_type tr_sessionGetProxyType( const tr_session * ); … … 650 598 tr_msg_list; 651 599 652 void tr_setMessageQueuing( intisEnabled );653 654 inttr_getMessageQueuing( void );600 void tr_setMessageQueuing( tr_bool isEnabled ); 601 602 tr_bool tr_getMessageQueuing( void ); 655 603 656 604 tr_msg_list * tr_getQueuedMessages( void ); … … 757 705 /** Set the download folder for the torrent being added with this ctor. 758 706 @see tr_ctorSetDownloadDir() 759 @see tr_sessionInit Full() */707 @see tr_sessionInit() */ 760 708 void tr_ctorSetDownloadDir( tr_ctor * ctor, 761 709 tr_ctorMode mode, -
trunk/libtransmission/utils.c
r7232 r7367 50 50 static tr_lock * messageLock = NULL; 51 51 static int messageLevel = 0; 52 static intmessageQueuing = FALSE;52 static tr_bool messageQueuing = FALSE; 53 53 static tr_msg_list * messageQueue = NULL; 54 54 static tr_msg_list ** messageQueueTail = &messageQueue; … … 119 119 120 120 void 121 tr_setMessageQueuing( intenabled )121 tr_setMessageQueuing( tr_bool enabled ) 122 122 { 123 123 tr_msgInit( ); … … 127 127 } 128 128 129 int 129 tr_bool 130 130 tr_getMessageQueuing( void ) 131 131 {
Note: See TracChangeset
for help on using the changeset viewer.