double gtr_pref_double_get( const char * key ) { double d = 0.0; tr_bencDictFindReal( getPrefs( ), key, &d ); return d; }
static uint64_t loadRatioLimits( tr_benc * dict, tr_torrent * tor ) { tr_benc * d; uint64_t ret = 0; if( tr_bencDictFindDict( dict, KEY_RATIOLIMIT, &d ) ) { int64_t i; double dratio; if( tr_bencDictFindReal( d, KEY_RATIOLIMIT_RATIO, &dratio ) ) tr_torrentSetRatioLimit( tor, dratio ); if( tr_bencDictFindInt( d, KEY_RATIOLIMIT_MODE, &i ) ) tr_torrentSetRatioMode( tor, i ); ret = TR_FR_RATIOLIMIT; } return ret; }
static int testParse2( void ) { tr_benc top; tr_benc top2; int64_t intVal; const char * strVal; double realVal; bool boolVal; int len; char * benc; const uint8_t * end; tr_bencInitDict( &top, 0 ); tr_bencDictAddBool( &top, "this-is-a-bool", true ); tr_bencDictAddInt( &top, "this-is-an-int", 1234 ); tr_bencDictAddReal( &top, "this-is-a-real", 0.5 ); tr_bencDictAddStr( &top, "this-is-a-string", "this-is-a-string" ); benc = tr_bencToStr( &top, TR_FMT_BENC, &len ); check_streq( "d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-inti1234ee", benc ); check( !tr_bencParse( benc, benc+len, &top2, &end ) ); check( (char*)end == benc + len ); check( tr_bencIsDict( &top2 ) ); check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) ); check_int_eq (1234, intVal); check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) ); check( boolVal == true ); check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) ); check_streq ("this-is-a-string", strVal); check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) ); check_int_eq (50, (int)(realVal*100)); tr_bencFree( &top2 ); tr_free( benc ); tr_bencFree( &top ); return 0; }