Changeset 5796


Ignore:
Timestamp:
May 10, 2008, 12:19:00 AM (14 years ago)
Author:
charles
Message:

new utility for iterating through torrents: tr_torrentNext()

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/port-forwarding.c

    r5754 r5796  
    206206tr_sharedSetPort( tr_shared * s, int port )
    207207{
    208     tr_torrent * tor;
     208    tr_torrent * tor = NULL;
    209209
    210210    s->publicPort = port;
    211211
    212     for( tor = s->h->torrentList; tor; tor = tor->next )
     212    while(( tor = tr_torrentNext( s->h, tor )))
    213213        tr_torrentChangeMyPort( tor );
    214214}
  • trunk/libtransmission/session.c

    r5726 r5796  
    389389{
    390390    tr_handle * h = vh;
    391     tr_torrent * t;
     391    tr_torrent * tor;
    392392
    393393    tr_sharedShuttingDown( h->shared );
    394394    tr_trackerShuttingDown( h );
    395395
    396     for( t=h->torrentList; t!=NULL; ) {
    397         tr_torrent * tmp = t;
    398         t = t->next;
    399         tr_torrentClose( tmp );
    400     }
     396    while(( tor = tr_torrentNext( h, NULL )))
     397        tr_torrentClose( tor );
    401398
    402399    tr_peerMgrFree( h->peerMgr );
     
    683680    }
    684681}
     682
     683tr_torrent*
     684tr_torrentNext( tr_handle * session, tr_torrent * tor )
     685{
     686    return tor ? tor->next : session->torrentList;
     687}
  • trunk/libtransmission/torrent.c

    r5781 r5796  
    5555
    5656int
    57 tr_torrentExists( tr_handle      * handle,
     57tr_torrentExists( const tr_handle * handle,
    5858                  const uint8_t   * torrentHash )
    5959{
    60     return tr_torrentFindFromHash( handle, torrentHash ) != NULL;
     60    return tr_torrentFindFromHash( (tr_handle*)handle, torrentHash ) != NULL;
    6161}
    6262
     
    6565                        const uint8_t  * torrentHash )
    6666{
    67     tr_torrent * tor;
    68 
    69     for( tor = handle->torrentList; tor; tor = tor->next )
     67    tr_torrent * tor = NULL;
     68
     69    while(( tor = tr_torrentNext( handle, tor )))
    7070        if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
    7171            return tor;
     
    7878                                  const uint8_t  * obfuscatedTorrentHash )
    7979{
    80     tr_torrent * tor;
    81 
    82     for( tor = handle->torrentList; tor; tor = tor->next )
     80    tr_torrent * tor = NULL;
     81
     82    while(( tor = tr_torrentNext( handle, tor )))
    8383        if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash, SHA_DIGEST_LENGTH ) )
    8484            return tor;
     
    483483}
    484484
    485 static int
    486 hashExists( const tr_handle   * h,
    487             const uint8_t     * hash )
    488 {
    489     const tr_torrent * tor;
    490 
    491     for( tor=h->torrentList; tor; tor=tor->next )
    492         if( !memcmp( hash, tor->info.hash, SHA_DIGEST_LENGTH ) )
    493             return TRUE;
    494 
    495     return FALSE;
    496 }
    497 
    498485int
    499486tr_torrentParse( const tr_handle  * handle,
     
    516503    doFree = !err && ( setmeInfo == &tmp );
    517504
    518     if( !err && hashExists( handle, setmeInfo->hash ) )
     505    if( !err && tr_torrentExists( handle, setmeInfo->hash ) )
    519506        err = TR_EDUPLICATE;
    520507
  • trunk/libtransmission/torrent.h

    r5748 r5796  
    4949void tr_torrentChangeMyPort  ( tr_torrent * );
    5050
    51 int tr_torrentExists( tr_handle *, const uint8_t * );
     51int tr_torrentExists( const tr_handle *, const uint8_t * );
    5252tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
    5353tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
  • trunk/libtransmission/transmission.h

    r5673 r5796  
    249249int tr_torrentCount( const tr_handle * h );
    250250
     251/**
     252 * Iterate through the torrents.
     253 * Pass in in a NULL pointer to get the first torrent.
     254 */
     255tr_torrent* tr_torrentNext( tr_handle *, tr_torrent * );
     256
    251257/***********************************************************************
    252258*** Speed Limits
Note: See TracChangeset for help on using the changeset viewer.