tr_closeAllConnections( void * vh )
{
tr_handle * h = vh;
- tr_torrent * t;
+ tr_torrent * tor;
tr_sharedShuttingDown( h->shared );
tr_trackerShuttingDown( h );
- for( t=h->torrentList; t!=NULL; ) {
- tr_torrent * tmp = t;
- t = t->next;
- tr_torrentClose( tmp );
- }
+ while(( tor = tr_torrentNext( h, NULL )))
+ tr_torrentClose( tor );
tr_peerMgrFree( h->peerMgr );
metainfoLookupResort( h );
}
}
+
+tr_torrent*
+tr_torrentNext( tr_handle * session, tr_torrent * tor )
+{
+ return tor ? tor->next : session->torrentList;
+}
***/
int
-tr_torrentExists( tr_handle * handle,
+tr_torrentExists( const tr_handle * handle,
const uint8_t * torrentHash )
{
- return tr_torrentFindFromHash( handle, torrentHash ) != NULL;
+ return tr_torrentFindFromHash( (tr_handle*)handle, torrentHash ) != NULL;
}
tr_torrent*
tr_torrentFindFromHash( tr_handle * handle,
const uint8_t * torrentHash )
{
- tr_torrent * tor;
+ tr_torrent * tor = NULL;
- for( tor = handle->torrentList; tor; tor = tor->next )
+ while(( tor = tr_torrentNext( handle, tor )))
if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
return tor;
tr_torrentFindFromObfuscatedHash( tr_handle * handle,
const uint8_t * obfuscatedTorrentHash )
{
- tr_torrent * tor;
+ tr_torrent * tor = NULL;
- for( tor = handle->torrentList; tor; tor = tor->next )
+ while(( tor = tr_torrentNext( handle, tor )))
if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash, SHA_DIGEST_LENGTH ) )
return tor;
torrentStart( tor, FALSE );
}
-static int
-hashExists( const tr_handle * h,
- const uint8_t * hash )
-{
- const tr_torrent * tor;
-
- for( tor=h->torrentList; tor; tor=tor->next )
- if( !memcmp( hash, tor->info.hash, SHA_DIGEST_LENGTH ) )
- return TRUE;
-
- return FALSE;
-}
-
int
tr_torrentParse( const tr_handle * handle,
const tr_ctor * ctor,
err = tr_metainfoParse( handle, setmeInfo, metainfo );
doFree = !err && ( setmeInfo == &tmp );
- if( !err && hashExists( handle, setmeInfo->hash ) )
+ if( !err && tr_torrentExists( handle, setmeInfo->hash ) )
err = TR_EDUPLICATE;
if( doFree )
void tr_torrentChangeMyPort ( tr_torrent * );
-int tr_torrentExists( tr_handle *, const uint8_t * );
+int tr_torrentExists( const tr_handle *, const uint8_t * );
tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );