Changeset 10826


Ignore:
Timestamp:
Jun 23, 2010, 4:06:15 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #2581 "RPC extended to manage tracker lists" -- add safeguards in tr_torrentSetAnnounceList() to handle the case of tracker arrays not being sorted by tier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r10816 r10826  
    21462146***/
    21472147
     2148static int
     2149compareTrackerByTier( const void * va, const void * vb )
     2150{
     2151    const tr_tracker_info * a = va;
     2152    const tr_tracker_info * b = vb;
     2153
     2154    /* sort by tier */
     2155    if( a->tier != b->tier )
     2156        return a->tier - b->tier;
     2157
     2158    /* get the effects of a stable sort by comparing the two elements' addresses */
     2159    return a - b;
     2160}
     2161
    21482162tr_bool
    21492163tr_torrentSetAnnounceList( tr_torrent             * tor,
    2150                            const tr_tracker_info  * trackers,
     2164                           const tr_tracker_info  * trackers_in,
    21512165                           int                      trackerCount )
    21522166{
     
    21542168    tr_benc metainfo;
    21552169    tr_bool ok = TRUE;
     2170    tr_tracker_info * trackers;
     2171
    21562172    tr_torrentLock( tor );
    21572173
    21582174    assert( tr_isTorrent( tor ) );
     2175
     2176    /* ensure the trackers' tiers are in ascending order */
     2177    trackers = tr_memdup( trackers_in, sizeof( tr_tracker_info ) * trackerCount );
     2178    qsort( trackers, trackerCount, sizeof( tr_tracker_info ), compareTrackerByTier );
    21592179
    21602180    /* look for bad URLs */
     
    22372257
    22382258    tr_torrentUnlock( tor );
     2259
     2260    tr_free( trackers );
    22392261    return ok;
    22402262}
Note: See TracChangeset for help on using the changeset viewer.