From f538b08fb3d63f2a615a3816dc9d168aaf2c2491 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Jun 2009 18:12:36 +0000 Subject: [PATCH] (trunk libT) tracker.c was using tr_benc's private fields --- libtransmission/bencode.c | 8 +-- libtransmission/bencode.h | 2 + libtransmission/tracker.c | 106 +++++++++++++++++++------------------- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index 4219f1e3a..658efe2d4 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -1456,8 +1456,8 @@ tr_bencDictSize( const tr_benc * dict ) return count; } -static tr_bool -tr_bencDictChild( const tr_benc * dict, size_t n, const char ** key, const tr_benc ** val ) +tr_bool +tr_bencDictChild( tr_benc * dict, size_t n, const char ** key, tr_benc ** val ) { tr_bool success = 0; @@ -1486,10 +1486,10 @@ tr_bencMergeDicts( tr_benc * target, const tr_benc * source ) for( i=0; iretryAnnounceIntervalSec = FIRST_SCRAPE_RETRY_INTERVAL_SEC; - if( ( tr_bencDictFindStr( &benc, "failure reason", &str ) ) ) + if( tr_bencDictFindStr( &benc, "failure reason", &str ) ) { publishMessage( t, str, TR_TRACKER_ERROR ); success = FALSE; } - if( ( tr_bencDictFindStr( &benc, "warning message", &str ) ) ) + if( tr_bencDictFindStr( &benc, "warning message", &str ) ) publishWarning( t, str ); - if( ( tr_bencDictFindInt( &benc, "interval", &i ) ) ) + if( tr_bencDictFindInt( &benc, "interval", &i ) ) { dbgmsg( t->name, "setting interval to %d", (int)i ); t->announceIntervalSec = i; } - if( ( tr_bencDictFindInt( &benc, "min interval", &i ) ) ) + if( tr_bencDictFindInt( &benc, "min interval", &i ) ) { dbgmsg( t->name, "setting min interval to %d", (int)i ); t->announceMinIntervalSec = i; } - if( ( tr_bencDictFindStr( &benc, "tracker id", &str ) ) ) + if( tr_bencDictFindStr( &benc, "tracker id", &str ) ) t->trackerID = tr_strdup( str ); - if( ( tr_bencDictFindInt( &benc, "complete", &i ) ) ) + if( tr_bencDictFindInt( &benc, "complete", &i ) ) { ++scrapeFields; t->seederCount = i; } - if( ( tr_bencDictFindInt( &benc, "incomplete", &i ) ) ) + if( tr_bencDictFindInt( &benc, "incomplete", &i ) ) { ++scrapeFields; t->leecherCount = incomplete = i; } - if( ( tr_bencDictFindInt( &benc, "downloaded", &i ) ) ) + if( tr_bencDictFindInt( &benc, "downloaded", &i ) ) { ++scrapeFields; t->timesDownloaded = i; } - if( ( tmp = tr_bencDictFind( &benc, "peers" ) ) ) + if( tr_bencDictFindRaw( &benc, "peers", &raw, &rawlen ) ) { + /* "compact" extension */ const int allAreSeeds = incomplete == 0; - - if( tr_bencIsString( tmp ) ) /* "compact" extension */ - { - publishNewPeersCompact( t, allAreSeeds, tmp->val.s.s, - tmp->val.s.i ); - } - else if( tr_bencIsList( tmp ) ) /* original protocol */ - { - size_t byteCount = 0; - uint8_t * array = parseOldPeers( tmp, &byteCount ); - publishNewPeers( t, allAreSeeds, array, byteCount ); - tr_free( array ); - } + publishNewPeersCompact( t, allAreSeeds, raw, rawlen ); } - - if( ( tmp = tr_bencDictFind( &benc, "peers6" ) ) ) + else if( tr_bencDictFindList( &benc, "peers", &tmp ) ) { + /* original version of peers */ const int allAreSeeds = incomplete == 0; - - if( tr_bencIsString( tmp ) ) /* "compact" extension */ - { - publishNewPeersCompact6( t, allAreSeeds, tmp->val.s.s, - tmp->val.s.i ); - } + size_t byteCount = 0; + uint8_t * array = parseOldPeers( tmp, &byteCount ); + publishNewPeers( t, allAreSeeds, array, byteCount ); + tr_free( array ); + } + + if( tr_bencDictFindRaw( &benc, "peers6", &raw, &rawlen ) ) + { + /* "compact" extension */ + const int allAreSeeds = incomplete == 0; + publishNewPeersCompact6( t, allAreSeeds, raw, rawlen ); } } @@ -624,34 +622,34 @@ onScrapeResponse( tr_session * session, &benc, NULL ); if( bencLoaded && tr_bencDictFindDict( &benc, "files", &files ) ) { - size_t i; - for( i = 0; i < files->val.l.count; i += 2 ) + const char * key; + tr_benc * val; + int i = 0; + while( tr_bencDictChild( files, i++, &key, &val )) { - int64_t itmp; - const uint8_t* hash = - (const uint8_t*) files->val.l.vals[i].val.s.s; - tr_benc * flags; - tr_benc * tordict = &files->val.l.vals[i + 1]; - if( memcmp( t->hash, hash, SHA_DIGEST_LENGTH ) ) + int64_t intVal; + tr_benc * flags; + + if( memcmp( t->hash, key, SHA_DIGEST_LENGTH ) ) continue; publishErrorClear( t ); - if( ( tr_bencDictFindInt( tordict, "complete", &itmp ) ) ) - t->seederCount = itmp; + if( ( tr_bencDictFindInt( val, "complete", &intVal ) ) ) + t->seederCount = intVal; - if( ( tr_bencDictFindInt( tordict, "incomplete", &itmp ) ) ) - t->leecherCount = itmp; + if( ( tr_bencDictFindInt( val, "incomplete", &intVal ) ) ) + t->leecherCount = intVal; - if( ( tr_bencDictFindInt( tordict, "downloaded", &itmp ) ) ) - t->timesDownloaded = itmp; + if( ( tr_bencDictFindInt( val, "downloaded", &intVal ) ) ) + t->timesDownloaded = intVal; - if( ( tr_bencDictFindInt( tordict, "downloaders", &itmp ) ) ) - t->downloaderCount = itmp; + if( ( tr_bencDictFindInt( val, "downloaders", &intVal ) ) ) + t->downloaderCount = intVal; - if( tr_bencDictFindDict( tordict, "flags", &flags ) ) - if( ( tr_bencDictFindInt( flags, "min_request_interval", &itmp ) ) ) - t->scrapeIntervalSec = itmp; + if( tr_bencDictFindDict( val, "flags", &flags ) ) + if( ( tr_bencDictFindInt( flags, "min_request_interval", &intVal ) ) ) + t->scrapeIntervalSec = intVal; /* as per ticket #1045, safeguard against trackers returning * a very low min_request_interval... */