Ticket #1559: session_init2.patch
File session_init2.patch, 29.2 KB (added by KyleK, 12 years ago) |
---|
-
daemon/daemon.c
diff -aBbur -x'autom4te*' -x.svn -x'*.o' -x'*.a' -x'*.in' -x'*.am' -x'config*' -x'Make*' Transmission-svn/daemon/daemon.c Transmission/daemon/daemon.c
old new 166 166 const char * password, 167 167 int blocklistEnabled ) 168 168 { 169 170 169 171 tr_benc state, *dict = NULL; 170 int peerPort = -1, peers = -1;171 int whitelistEnabled = -1;172 int pexEnabled = -1;173 int fwdEnabled = -1;174 int upLimit = -1, upLimited = -1, downLimit = -1,175 downLimited = -1;176 int encryption = -1;177 int useLazyBitfield = -1;178 172 tr_ctor * ctor; 179 173 tr_torrent ** torrents; 174 int64_t numval; 175 176 // 1. get benclist with only default values 177 178 tr_benc * sessionConfig = tr_getDefaultSettings(); 180 179 181 if( !tr_bencLoadJSONFile( myConfigFilename, &state ) ) 180 // 2. overwrite defaults with preferences from settings file 181 if( !tr_bencLoadJSONFile( myConfigFilename, &state ) ) { 182 182 dict = &state; 183 tr_bencMergeDicts( sessionConfig, dict); 184 } 185 186 // 3. overwrite settings with preferences from the command line 187 if(rpcPort != -1 ) { 188 replaceInt( sessionConfig, TR_PREFS_KEY_RPC_PORT, rpcPort ); 189 } 190 if(whitelist && *whitelist) { 191 replaceStr( sessionConfig, TR_PREFS_KEY_WHITELIST, whitelist ); 192 replaceInt( sessionConfig, TR_PREFS_KEY_WHITELIST_ENABLED, TRUE ); 193 } 194 if(authRequired != -1 && username && password) { 195 replaceInt( sessionConfig, TR_PREFS_KEY_RPC_AUTH_REQUIRED, authRequired ); 196 replaceStr( sessionConfig, TR_PREFS_KEY_RPC_USERNAME, username ); 197 replaceStr( sessionConfig, TR_PREFS_KEY_RPC_PASSWORD, password ); 198 } 199 if(blocklistEnabled != -1) { 200 replaceInt( sessionConfig, TR_PREFS_KEY_BLOCKLIST, blocklistEnabled ); 201 } 202 if(downloadDir != NULL) { 203 replaceStr( sessionConfig, TR_PREFS_KEY_DOWNLOAD_DIR, downloadDir ); 204 } 183 205 184 /*** 185 **** Decide on which values to pass into tr_sessionInitFull(). 186 **** The command-line arguments are given precedence and 187 **** the state file from the previous session is used as a fallback. 188 **** If neither of those can be found, the TR_DEFAULT fields are used . 189 ***/ 190 191 getConfigStr( dict, KEY_DOWNLOAD_DIR, &downloadDir, 192 TR_DEFAULT_DOWNLOAD_DIR ); 193 getConfigInt( dict, KEY_PEX_ENABLED, &pexEnabled, 194 TR_DEFAULT_PEX_ENABLED ); 195 getConfigInt( dict, KEY_PORT_FORWARDING, &fwdEnabled, 196 TR_DEFAULT_PORT_FORWARDING_ENABLED ); 197 getConfigInt( dict, KEY_PEER_PORT, &peerPort, 198 TR_DEFAULT_PORT ); 199 getConfigInt( dict, KEY_DSPEED, &downLimit, 100 ); 200 getConfigInt( dict, KEY_DSPEED_ENABLED, &downLimited, FALSE ); 201 getConfigInt( dict, KEY_USPEED, &upLimit, 100 ); 202 getConfigInt( dict, KEY_USPEED_ENABLED, &upLimited, FALSE ); 203 getConfigInt( dict, KEY_LAZY_BITFIELD, &useLazyBitfield, 204 TR_DEFAULT_LAZY_BITFIELD_ENABLED ); 205 getConfigInt( dict, KEY_PEER_LIMIT, &peers, 206 TR_DEFAULT_GLOBAL_PEER_LIMIT ); 207 getConfigInt( dict, KEY_BLOCKLIST, &blocklistEnabled, 208 TR_DEFAULT_BLOCKLIST_ENABLED ); 209 getConfigInt( dict, KEY_RPC_PORT, &rpcPort, 210 TR_DEFAULT_RPC_PORT ); 211 getConfigInt( dict, KEY_WHITELIST_ENABLED, &whitelistEnabled, 212 TR_DEFAULT_RPC_WHITELIST_ENABLED ); 213 getConfigStr( dict, KEY_WHITELIST, &whitelist, 214 TR_DEFAULT_RPC_WHITELIST ); 215 getConfigInt( dict, KEY_AUTH_REQUIRED, &authRequired, FALSE ); 216 getConfigStr( dict, KEY_USERNAME, &username, NULL ); 217 getConfigStr( dict, KEY_PASSWORD, &password, NULL ); 218 getConfigInt( dict, KEY_ENCRYPTION, &encryption, 219 TR_DEFAULT_ENCRYPTION ); 220 221 /*** 222 **** 223 ***/ 206 if(configDir && *configDir) { 207 replaceStr( sessionConfig, TR_PREFS_KEY_CONFIG_DIR, configDir ); 208 } 224 209 225 210 /* start the session */ 226 mySession = tr_sessionInitFull( configDir, "daemon", downloadDir, 227 pexEnabled, fwdEnabled, peerPort, 228 encryption, 229 useLazyBitfield, 230 upLimited, upLimit, 231 downLimited, downLimit, 232 peers, 233 TR_MSG_INF, 0, 234 blocklistEnabled, 235 TR_DEFAULT_PEER_SOCKET_TOS, 236 TRUE, rpcPort, 237 whitelistEnabled, whitelist, 238 authRequired, username, password, 239 TR_DEFAULT_PROXY_ENABLED, 240 TR_DEFAULT_PROXY, 241 TR_DEFAULT_PROXY_PORT, 242 TR_DEFAULT_PROXY_TYPE, 243 TR_DEFAULT_PROXY_AUTH_ENABLED, 244 TR_DEFAULT_PROXY_USERNAME, 245 TR_DEFAULT_PROXY_PASSWORD ); 246 211 mySession = tr_sessionInitFull( sessionConfig ); 247 212 248 if( authRequired ) 213 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &numval ) ); 214 if( numval != 0) 249 215 tr_ninf( MY_NAME, "requiring authentication" ); 250 216 251 217 /* load the torrents */ … … 254 220 tr_free( torrents ); 255 221 tr_ctorFree( ctor ); 256 222 223 tr_bencFree( sessionConfig ); 224 257 225 if( dict ) 258 226 tr_bencFree( &state ); 259 227 } -
libtransmission/bencode.c
diff -aBbur -x'autom4te*' -x.svn -x'*.o' -x'*.a' -x'*.in' -x'*.am' -x'config*' -x'Make*' Transmission-svn/libtransmission/bencode.c Transmission/libtransmission/bencode.c
old new 1316 1316 **** 1317 1317 ***/ 1318 1318 1319 struct mergeWalk 1320 { 1321 const char* key; 1322 tr_bool key_set; 1323 struct tr_benc * b; 1324 }; 1325 1326 1327 static void 1328 replaceInt( tr_benc * dict, const char * key, int64_t value ) { 1329 tr_bencDictRemove( dict, key ); 1330 tr_bencDictAddInt( dict, key, value ); 1331 } 1332 1333 static void 1334 replaceStr( tr_benc * dict, const char * key, const char* value ) { 1335 tr_bencDictRemove( dict, key ); 1336 tr_bencDictAddStr( dict, key, value ); 1337 } 1338 1339 static void 1340 mergeIntFunc( const tr_benc * val, void * vdata) { 1341 struct mergeWalk * data = vdata; 1342 assert(data->key_set == 1); 1343 replaceInt(data->b, data->key, (int64_t)val->val.i); 1344 data->key = NULL; 1345 data->key_set = 0; 1346 } 1347 1348 static void 1349 mergeStrFunc( const tr_benc * key, void * vdata ) { 1350 struct mergeWalk * data = vdata; 1351 assert(key != NULL); 1352 if(data->key_set && key) { 1353 replaceStr(data->b, data->key, key->val.s.s); 1354 data->key = NULL; 1355 data->key_set = 0; 1356 } else { 1357 data->key = key->val.s.s; 1358 data->key_set = 1; 1359 } 1360 } 1361 1362 static void 1363 mergeDummyFunc( const tr_benc * val UNUSED, void * vdata UNUSED ) { 1364 } 1365 1366 void 1367 tr_bencMergeDicts( tr_benc * b1, const tr_benc * b2) { 1368 struct WalkFuncs walkFuncs; 1369 struct mergeWalk data; 1370 1371 assert(b1 && b2); 1372 walkFuncs.intFunc = mergeIntFunc; 1373 walkFuncs.stringFunc = mergeStrFunc; 1374 walkFuncs.dictBeginFunc = mergeDummyFunc; 1375 walkFuncs.listBeginFunc = mergeDummyFunc; 1376 walkFuncs.containerEndFunc = mergeDummyFunc; 1377 1378 data.key_set = 0; 1379 data.key = NULL; 1380 data.b = b1; 1381 1382 bencWalk( b2, &walkFuncs, &data ); 1383 } 1384 1385 /*** 1386 **** 1387 ***/ 1388 1319 1389 static int 1320 1390 saveFile( const char * filename, 1321 1391 const char * content, -
libtransmission/bencode.h
diff -aBbur -x'autom4te*' -x.svn -x'*.o' -x'*.a' -x'*.in' -x'*.am' -x'config*' -x'Make*' Transmission-svn/libtransmission/bencode.h Transmission/libtransmission/bencode.h
old new 13 13 #ifndef TR_BENCODE_H 14 14 #define TR_BENCODE_H 1 15 15 16 #include <stdlib.h> 16 17 #include <inttypes.h> /* for int64_t */ 17 18 18 19 enum … … 225 226 const uint8_t ** setme_str, 226 227 size_t * setme_strlen ); 227 228 229 /*** 230 **** 231 ***/ 232 233 void tr_bencMergeDicts( tr_benc * b1, const tr_benc * b2); 234 235 228 236 #endif -
libtransmission/bencode-test.c
Only in Transmission/libtransmission: bencode-test-2.c diff -aBbur -x'autom4te*' -x.svn -x'*.o' -x'*.a' -x'*.in' -x'*.am' -x'config*' -x'Make*' Transmission-svn/libtransmission/bencode-test.c Transmission/libtransmission/bencode-test.c
old new 362 362 } 363 363 364 364 static int 365 testMerge( void ) { 366 tr_benc dest, src; 367 int64_t i; 368 const char * s; 369 370 //initial dictionary (default values) 371 372 tr_bencInitDict(&dest, 10); 373 tr_bencDictAddInt(&dest, "i1", 1); 374 tr_bencDictAddInt(&dest, "i2", 2); 375 tr_bencDictAddInt(&dest, "i4", -35); // remains untouched 376 tr_bencDictAddStr(&dest, "s5", "abc"); 377 tr_bencDictAddStr(&dest, "s6", "def"); 378 tr_bencDictAddStr(&dest, "s7", "127.0.0.1"); // remains untouched 379 380 //new dictionary, will overwrite items in dest 381 382 tr_bencInitDict(&src, 10); 383 tr_bencDictAddInt(&src, "i1", 1); //same value 384 tr_bencDictAddInt(&src, "i2", 4); //new value 385 tr_bencDictAddInt(&src, "i3", 3); //new key:value 386 tr_bencDictAddStr(&src, "s5", "abc"); //same value 387 tr_bencDictAddStr(&src, "s6", "xyz"); //new value 388 tr_bencDictAddStr(&src, "s8", "ghi"); //new key:value 389 390 tr_bencMergeDicts( &dest, /*const*/ &src); 391 392 check( tr_bencDictFindInt( &dest, "i1", &i ) ); 393 check( i == 1); 394 check( tr_bencDictFindInt( &dest, "i2", &i ) ); 395 check( i == 4); 396 check( tr_bencDictFindInt( &dest, "i3", &i ) ); 397 check( i == 3); 398 check( tr_bencDictFindInt( &dest, "i4", &i ) ); 399 check( i == -35); 400 check( tr_bencDictFindStr( &dest, "s5", &s ) ); 401 check(strcmp("abc", s) == 0); 402 check( tr_bencDictFindStr( &dest, "s6", &s ) ); 403 check(strcmp("xyz", s) == 0); 404 check( tr_bencDictFindStr( &dest, "s7", &s ) ); 405 check(strcmp("127.0.0.1", s) == 0); 406 check( tr_bencDictFindStr( &dest, "s8", &s ) ); 407 check(strcmp("ghi", s) == 0); 408 409 tr_bencFree(&dest); 410 tr_bencFree(&src); 411 return 0; 412 } 413 414 static int 365 415 testStackSmash( int depth ) 366 416 { 367 417 int i; … … 408 458 if( ( i = testJSON( ) ) ) 409 459 return i; 410 460 461 if( ( i = testMerge( ) ) ) 462 return i; 463 411 464 #ifndef WIN32 412 465 i = testStackSmash( 1000000 ); 413 466 #else -
libtransmission/session.c
Only in Transmission/libtransmission: my-bencode-test.c diff -aBbur -x'autom4te*' -x.svn -x'*.o' -x'*.a' -x'*.in' -x'*.am' -x'config*' -x'Make*' Transmission-svn/libtransmission/session.c Transmission/libtransmission/session.c
old new 194 194 **** 195 195 ***/ 196 196 197 tr_benc * tr_getDefaultSettings( void ) { 198 199 tr_benc * d = tr_new0( tr_benc, 1 ); 200 201 tr_bencInitDict( d, 16 ); 202 tr_bencDictAddInt( d, TR_PREFS_KEY_MSGLEVEL, TR_DEFAULT_MSG_LEVEL ); 203 tr_bencDictAddInt( d, TR_PREFS_KEY_MSGQUEUE_ENABLED, TR_DEFAULT_MSGQUEUE_ENABLED ); 204 tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST, TR_DEFAULT_BLOCKLIST_ENABLED ); 205 tr_bencDictAddStr( d, TR_PREFS_KEY_CONFIG_DIR, TR_DEFAULT_CONFIG_DIR ); 206 tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, TR_DEFAULT_DOWNLOAD_DIR ); 207 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT, TR_DEFAULT_GLOBAL_PEER_LIMIT ); 208 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT, TR_DEFAULT_PORT ); 209 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, TR_DEFAULT_PORT_FORWARDING_ENABLED ); 210 tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, TR_DEFAULT_PEER_SOCKET_TOS ); 211 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, TR_DEFAULT_PEX_ENABLED ); 212 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_ENABLED, TR_DEFAULT_RPC_ENABLED ); 213 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_PORT, TR_DEFAULT_RPC_PORT ); 214 tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, TR_DEFAULT_RPC_AUTH_ENABLED ); 215 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_USERNAME, NULL ); 216 tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_PASSWORD, NULL ); 217 tr_bencDictAddStr( d, TR_PREFS_KEY_WHITELIST, TR_DEFAULT_RPC_WHITELIST ); 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_USPEED, 100 ); 221 tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED, 0 ); 222 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_ENABLED, TR_DEFAULT_PROXY_ENABLED ); 223 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, TR_DEFAULT_PROXY ); 224 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_PORT, TR_DEFAULT_PROXY_PORT ); 225 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_TYPE, TR_DEFAULT_PROXY_TYPE ); 226 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, TR_DEFAULT_ENCRYPTION ); 227 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_USERNAME, TR_DEFAULT_PROXY_USERNAME ); 228 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_PASSWORD, TR_DEFAULT_PROXY_PASSWORD ); 229 230 return d; 231 } 232 197 233 static void metainfoLookupRescan( tr_handle * h ); 198 234 199 235 tr_handle * 200 tr_sessionInitFull( const char * configDir, 201 const char * tag, 202 const char * downloadDir, 203 int isPexEnabled, 204 int isPortForwardingEnabled, 205 int publicPort, 206 tr_encryption_mode encryptionMode, 207 int useLazyBitfield, 208 int useUploadLimit, 209 int uploadLimit, 210 int useDownloadLimit, 211 int downloadLimit, 212 int globalPeerLimit, 213 int messageLevel, 214 int isMessageQueueingEnabled, 215 int isBlocklistEnabled, 216 int peerSocketTOS, 217 int rpcIsEnabled, 218 tr_port rpcPort, 219 int rpcWhitelistIsEnabled, 220 const char * rpcWhitelist, 221 int rpcAuthIsEnabled, 222 const char * rpcUsername, 223 const char * rpcPassword, 224 int proxyIsEnabled, 225 const char * proxy, 226 int proxyPort, 227 tr_proxy_type proxyType, 228 int proxyAuthIsEnabled, 229 const char * proxyUsername, 230 const char * proxyPassword ) 236 tr_sessionInitFull( tr_benc * sessionConfig ) 231 237 { 232 238 tr_handle * h; 233 239 char * filename; 240 int64_t numval, publicPort; 241 int64_t rpc_enabled, whitelist_enabled, rpc_auth_enabled, rpc_port; 242 const char * whitelist = NULL, *rpc_passwd = NULL, *rpc_username = NULL; 243 const char * str = NULL; 234 244 235 245 #ifndef WIN32 236 246 /* Don't exit when writing on a broken socket */ … … 238 248 #endif 239 249 240 250 tr_msgInit( ); 241 tr_setMessageLevel( messageLevel ); 242 tr_setMessageQueuing( isMessageQueueingEnabled ); 251 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_MSGLEVEL, &numval ) ); 252 tr_setMessageLevel( numval ); 253 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_MSGQUEUE_ENABLED, &numval ) ); 254 tr_setMessageQueuing( numval ); 243 255 244 256 h = tr_new0( tr_handle, 1 ); 245 257 h->lock = tr_lockNew( ); 246 h->isPexEnabled = isPexEnabled ? 1 : 0; 247 h->encryptionMode = encryptionMode; 248 h->peerSocketTOS = peerSocketTOS; 249 h->downloadDir = tr_strdup( downloadDir ); 250 h->isProxyEnabled = proxyIsEnabled ? 1 : 0; 251 h->proxy = tr_strdup( proxy ); 252 h->proxyPort = proxyPort; 253 h->proxyType = proxyType; 254 h->isProxyAuthEnabled = proxyAuthIsEnabled != 0; 255 h->proxyUsername = tr_strdup( proxyUsername ); 256 h->proxyPassword = tr_strdup( proxyPassword ); 258 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PEX_ENABLED, &numval) ); 259 h->isPexEnabled = numval != 0; 260 assert(tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_ENCRYPTION, &numval ) ); 261 h->encryptionMode = numval; 262 assert(tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PEER_SOCKET_TOS, &numval ) ); 263 h->peerSocketTOS = numval; 264 assert(tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_DOWNLOAD_DIR, &str ) ); 265 h->downloadDir = tr_strdup( str ); 266 assert(tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PROXY_ENABLED, &numval ) ); 267 h->isProxyEnabled = numval != 0; 268 assert(tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_PROXY, &str ) ); 269 h->proxy = tr_strdup( str ); 270 assert(tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PROXY_PORT, &numval ) ); 271 h->proxyPort = numval; 272 assert(tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PROXY_TYPE, &numval ) ); 273 h->proxyType = numval; 274 assert(tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PROXY_AUTH_ENABLED, &numval ) ); 275 h->isProxyAuthEnabled = numval != 0; 276 assert(tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_PROXY_USERNAME, &str ) ); 277 h->proxyUsername = tr_strdup( str ); 278 assert(tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_PROXY_PASSWORD, &str ) ); 279 h->proxyPassword = tr_strdup( str ); 257 280 h->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */ 258 281 h->so_rcvbuf = 8192; 259 282 260 if( configDir == NULL ) 261 configDir = tr_getDefaultConfigDir( ); 262 tr_setConfigDir( h, configDir ); 283 assert( tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_CONFIG_DIR, &str ) ); 284 tr_setConfigDir( h, str ); 263 285 264 286 tr_netInit( ); /* must go before tr_eventInit */ 265 287 … … 267 289 while( !h->events ) 268 290 tr_wait( 50 ); 269 291 270 h->tag = tr_strdup( tag ); 292 assert( tr_bencDictFindStr( sessionConfig, "tag", &str ) ); 293 h->tag = tr_strdup( str ); 271 294 h->peerMgr = tr_peerMgrNew( h ); 272 295 273 h->useLazyBitfield = useLazyBitfield != 0; 296 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_LAZY_BITFIELD, &numval ) ); 297 h->useLazyBitfield = numval != 0; 274 298 275 299 /* Initialize rate and file descripts controls */ 276 300 277 tr_fdInit( globalPeerLimit ); 278 h->shared = tr_sharedInit( h, isPortForwardingEnabled, publicPort ); 279 h->isPortSet = publicPort >= 0; 301 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PEER_LIMIT, &numval ) ); 302 tr_fdInit( numval ); 303 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PORT_FORWARDING, &numval ) ); 304 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_PEER_PORT, &publicPort ) ); 305 h->shared = tr_sharedInit( h, numval, publicPort ); 306 h->isPortSet = (publicPort >= 0); 280 307 281 308 h->bandwidth = tr_bandwidthNew( h, NULL ); 282 tr_bandwidthSetDesiredSpeed( h->bandwidth, TR_UP, uploadLimit ); 283 tr_bandwidthSetDesiredSpeed( h->bandwidth, TR_DOWN, downloadLimit ); 284 tr_bandwidthSetLimited( h->bandwidth, TR_UP, useUploadLimit ); 285 tr_bandwidthSetLimited( h->bandwidth, TR_DOWN, useDownloadLimit ); 309 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_USPEED, &numval) ); 310 tr_bandwidthSetDesiredSpeed( h->bandwidth, TR_UP, numval ); 311 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_DSPEED, &numval) ); 312 tr_bandwidthSetDesiredSpeed( h->bandwidth, TR_DOWN, numval ); 313 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_USPEED_ENABLED, &numval) ); 314 tr_bandwidthSetLimited( h->bandwidth, TR_UP, numval); 315 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_DSPEED_ENABLED, &numval) ); 316 tr_bandwidthSetLimited( h->bandwidth, TR_DOWN, numval); 286 317 287 318 /* first %s is the application name 288 319 second %s is the version number */ … … 292 323 filename = tr_buildPath( h->configDir, "blocklists", NULL ); 293 324 tr_mkdirp( filename, 0777 ); 294 325 tr_free( filename ); 295 h->isBlocklistEnabled = isBlocklistEnabled; 326 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_BLOCKLIST, &numval) ); 327 h->isBlocklistEnabled = numval; 296 328 loadBlocklists( h ); 297 329 298 330 tr_statsInit( h ); 299 331 300 332 h->web = tr_webInit( h ); 301 h->rpcServer = tr_rpcInit( h, rpcIsEnabled, rpcPort, 302 rpcWhitelistIsEnabled, rpcWhitelist, 303 rpcAuthIsEnabled, rpcUsername, rpcPassword ); 333 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_RPC_ENABLED, &rpc_enabled ) ); 334 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_RPC_PORT, &rpc_port ) ); 335 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_WHITELIST_ENABLED, &whitelist_enabled ) ); 336 assert( tr_bencDictFindInt( sessionConfig, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &rpc_auth_enabled ) ); 337 338 assert( tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_WHITELIST, &whitelist ) ); 339 assert( tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_RPC_USERNAME, &rpc_username ) ); 340 assert( tr_bencDictFindStr( sessionConfig, TR_PREFS_KEY_RPC_PASSWORD, &rpc_passwd ) ); 341 342 343 344 h->rpcServer = tr_rpcInit( h, rpc_enabled, rpc_port, whitelist_enabled, whitelist, 345 rpc_auth_enabled, rpc_username, rpc_passwd ); 304 346 305 347 metainfoLookupRescan( h ); 306 348 307 349 return h; 308 350 } 309 351 310 tr_handle *311 tr_sessionInit( const char * configDir,312 const char * tag )313 {314 return tr_sessionInitFull( configDir,315 TR_DEFAULT_DOWNLOAD_DIR,316 tag,317 TR_DEFAULT_PEX_ENABLED,318 TR_DEFAULT_PORT_FORWARDING_ENABLED,319 -1, /* public port */320 TR_DEFAULT_ENCRYPTION, /* encryption mode */321 TR_DEFAULT_LAZY_BITFIELD_ENABLED,322 FALSE, /* use upload speed limit? */323 -1, /* upload speed limit */324 FALSE, /* use download speed limit? */325 -1, /* download speed limit */326 TR_DEFAULT_GLOBAL_PEER_LIMIT,327 TR_MSG_INF, /* message level */328 FALSE, /* is message queueing enabled? */329 FALSE, /* is the blocklist enabled? */330 TR_DEFAULT_PEER_SOCKET_TOS,331 TR_DEFAULT_RPC_ENABLED,332 TR_DEFAULT_RPC_PORT,333 TR_DEFAULT_RPC_WHITELIST_ENABLED,334 TR_DEFAULT_RPC_WHITELIST,335 FALSE,336 "fnord",337 "potzrebie",338 TR_DEFAULT_PROXY_ENABLED,339 TR_DEFAULT_PROXY,340 TR_DEFAULT_PROXY_PORT,341 TR_DEFAULT_PROXY_TYPE,342 TR_DEFAULT_PROXY_AUTH_ENABLED,343 TR_DEFAULT_PROXY_USERNAME,344 TR_DEFAULT_PROXY_PASSWORD );345 }346 347 352 /*** 348 353 **** 349 354 ***/ -
libtransmission/transmission.h
diff -aBbur -x'autom4te*' -x.svn -x'*.o' -x'*.a' -x'*.in' -x'*.am' -x'config*' -x'Make*' Transmission-svn/libtransmission/transmission.h Transmission/libtransmission/transmission.h
old new 37 37 #endif 38 38 39 39 #include "version.h" 40 #include "bencode.h" 40 41 41 42 #include <inttypes.h> /* uintN_t */ 42 43 #ifndef PRId64 … … 119 120 #endif 120 121 /** @see tr_sessionInitFull */ 121 122 #define TR_DEFAULT_PEX_ENABLED 1 123 #define TR_DEFAULT_MSG_LEVEL TR_MSG_INF 124 #define TR_DEFAULT_MSGQUEUE_ENABLED 0 122 125 /** @see tr_sessionInitFull */ 123 126 #define TR_DEFAULT_PORT_FORWARDING_ENABLED 0 124 127 /** @see tr_sessionInitFull */ … … 136 139 /** @see tr_sessionInitFull */ 137 140 #define TR_DEFAULT_BLOCKLIST_ENABLED 0 138 141 /** @see tr_sessionInitFull */ 139 #define TR_DEFAULT_RPC_ENABLED 0 142 #define TR_DEFAULT_RPC_ENABLED 1 143 /** @see tr_sessionInitFull */ 144 #define TR_DEFAULT_RPC_AUTH_ENABLED 0 140 145 /** @see tr_sessionInitFull */ 141 146 #define TR_DEFAULT_RPC_PORT 9091 142 147 /** @see tr_sessionInitFull */ … … 168 173 } 169 174 tr_encryption_mode; 170 175 176 177 #define TR_PREFS_KEY_MSGLEVEL "message-level" 178 #define TR_PREFS_KEY_MSGQUEUE_ENABLED "message-queue-enabled" 179 #define TR_PREFS_KEY_BLOCKLIST "blocklist-enabled" 180 #define TR_PREFS_KEY_CONFIG_DIR "config-dir" 181 #define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir" 182 #define TR_PREFS_KEY_ENCRYPTION "encryption" 183 #define TR_PREFS_KEY_LAZY_BITFIELD "lazy-bitfield-enabled" 184 #define TR_PREFS_KEY_PEER_LIMIT "max-peers-global" 185 #define TR_PREFS_KEY_PEER_PORT "peer-port" 186 #define TR_PREFS_KEY_PEER_SOCKET_TOS "peer-socket-tos" 187 #define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled" 188 #define TR_PREFS_KEY_PEX_ENABLED "pex-enabled" 189 #define TR_PREFS_KEY_WHITELIST "rpc-whitelist" 190 #define TR_PREFS_KEY_WHITELIST_ENABLED "rpc-whitelist-enabled" 191 #define TR_PREFS_KEY_RPC_ENABLED "rpc-enabled" 192 #define TR_PREFS_KEY_RPC_PORT "rpc-port" 193 #define TR_PREFS_KEY_RPC_AUTH_REQUIRED "rpc-authentication-required" 194 #define TR_PREFS_KEY_RPC_USERNAME "rpc-username" 195 #define TR_PREFS_KEY_RPC_PASSWORD "rpc-password" 196 #define TR_PREFS_KEY_DSPEED "download-limit" 197 #define TR_PREFS_KEY_DSPEED_ENABLED "download-limit-enabled" 198 #define TR_PREFS_KEY_USPEED "upload-limit" 199 #define TR_PREFS_KEY_USPEED_ENABLED "upload-limit-enabled" 200 #define TR_PREFS_KEY_PROXY_ENABLED "proxy-enabled" 201 #define TR_PREFS_KEY_PROXY "proxy" 202 #define TR_PREFS_KEY_PROXY_PORT "proxy-port" 203 #define TR_PREFS_KEY_PROXY_TYPE "proxy-type" 204 #define TR_PREFS_KEY_PROXY_AUTH_ENABLED "proxy-auth-enabled" 205 #define TR_PREFS_KEY_PROXY_USERNAME "proxy-auth-username" 206 #define TR_PREFS_KEY_PROXY_PASSWORD "proxy-auth-password" 207 208 tr_benc * tr_getDefaultSettings( void ); 209 171 210 /** 172 211 * @brief Start a libtransmission session. 173 212 * @return an opaque handle to the new session … … 263 302 * @see TR_DEFAULT_RPC_WHITELIST_ENABLED 264 303 * @see tr_sessionClose() 265 304 */ 266 tr_session * tr_sessionInitFull( const char * configDir, 267 const char * tag, 268 const char * downloadDir, 269 int isPexEnabled, 270 int isPortForwardingEnabled, 271 int publicPort, 272 tr_encryption_mode encryptionMode, 273 int useLazyBitfield, 274 int useUploadLimit, 275 int uploadLimit, 276 int useDownloadLimit, 277 int downloadLimit, 278 int peerLimit, 279 int messageLevel, 280 int isMessageQueueingEnabled, 281 int isBlocklistEnabled, 282 int peerSocketTOS, 283 int rpcIsEnabled, 284 tr_port rpcPort, 285 int rpcWhitelistIsEnabled, 286 const char * rpcWhitelist, 287 int rpcPasswordIsEnabled, 288 const char * rpcUsername, 289 const char * rpcPassword, 290 int proxyIsEnabled, 291 const char * proxy, 292 int proxyPort, 293 tr_proxy_type proxyType, 294 int proxyAuthIsEnabled, 295 const char * proxyUsername, 296 const char * proxyPassword ); 297 298 299 /** @brief Shorter form of tr_sessionInitFull() 300 @deprecated Use tr_sessionInitFull() instead. */ 301 tr_session * tr_sessionInit( const char * configDir, 302 const char * tag ); 305 tr_session * tr_sessionInitFull( tr_benc * sessionConfig ); 306 303 307 304 308 /** @brief End a libtransmission session 305 309 @see tr_sessionInitFull() */