Ignore:
Timestamp:
Sep 14, 2010, 6:23:48 AM (12 years ago)
Author:
Longinus00
Message:

switch trackerRemove and trackerReplace rpc calls to use tracker id instead of announce urls as identifiers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpcimpl.c

    r11194 r11209  
    848848
    849849static const char*
    850 replaceTrackerUrls( tr_torrent * tor, tr_benc * urls )
     850replaceTrackers( tr_torrent * tor, tr_benc * urls )
    851851{
    852852    int i;
     
    867867          ((pair[1] = tr_bencListChild(urls,i+1))))
    868868    {
    869         const char * oldval;
     869        int64_t pos;
    870870        const char * newval;
    871871
    872         if(    tr_bencGetStr( pair[0], &oldval )
     872        if(    tr_bencGetInt( pair[0], &pos )
    873873            && tr_bencGetStr( pair[1], &newval )
    874             && strcmp( oldval, newval )
    875874            && tr_urlIsValid( newval, -1 )
    876             && findAnnounceUrl( trackers, n, oldval, &i ) )
     875            && pos < n )
    877876        {
    878             tr_free( trackers[i].announce );
    879             trackers[i].announce = tr_strdup( newval );
     877            tr_free( trackers[pos].announce );
     878            trackers[pos].announce = tr_strdup( newval );
    880879            changed = TRUE;
    881880        }
     
    894893
    895894static const char*
    896 removeTrackerUrls( tr_torrent * tor, tr_benc * urls )
     895removeTrackers( tr_torrent * tor, tr_benc * ids )
    897896{
    898897    int i;
    899898    int n;
     899    int * tids;
     900    int t = 0;
    900901    tr_benc * val;
    901902    tr_tracker_info * trackers;
     
    906907    /* make a working copy of the existing announce list */
    907908    n = inf->trackerCount;
     909    tids = tr_new0( int, n );
    908910    trackers = tr_new0( tr_tracker_info, n );
    909911    copyTrackers( trackers, inf->trackers, n );
     
    911913    /* remove the ones specified in the urls list */
    912914    i = 0;
    913     while(( val = tr_bencListChild( urls, i++ )))
    914     {
    915         int pos;
    916         const char * url;
    917         if( tr_bencGetStr( val, &url ) && findAnnounceUrl( trackers, n, url, &pos ) )
    918         {
    919             tr_removeElementFromArray( trackers, pos, sizeof( tr_tracker_info ), n-- );
    920             changed = TRUE;
    921         }
     915    while(( val = tr_bencListChild( ids, i++ )))
     916    {
     917        int64_t pos;
     918        if( tr_bencGetInt( val, &pos ) && pos < n )
     919            tids[t++] = pos;
     920    }
     921
     922    /* sort trackerIds because tr_removeElementFromArray changes indices as it removes */
     923    qsort( tids, t, sizeof(int), compareInt );
     924
     925    /* remove from largest trackerId to smallest */
     926    while( t-- )
     927    {
     928        tr_removeElementFromArray( trackers, tids[t], sizeof( tr_tracker_info ), n-- );
     929        changed = TRUE;
    922930    }
    923931
     
    928936
    929937    freeTrackers( trackers, n );
     938    tr_free( tids );
    930939    return errmsg;
    931940}
     
    948957        double       d;
    949958        tr_benc *    files;
    950         tr_benc *    urls;
     959        tr_benc *    trackers;
    951960        tr_bool      boolVal;
    952961        tr_torrent * tor = torrents[i];
     
    985994        if( tr_bencDictFindInt( args_in, "seedRatioMode", &tmp ) )
    986995            tr_torrentSetRatioMode( tor, tmp );
    987         if( !errmsg && tr_bencDictFindList( args_in, "trackerAdd", &urls ) )
    988             errmsg = addTrackerUrls( tor, urls );
    989         if( !errmsg && tr_bencDictFindList( args_in, "trackerRemove", &urls ) )
    990             errmsg = removeTrackerUrls( tor, urls );
    991         if( !errmsg && tr_bencDictFindList( args_in, "trackerReplace", &urls ) )
    992             errmsg = replaceTrackerUrls( tor, urls );
     996        if( !errmsg && tr_bencDictFindList( args_in, "trackerAdd", &trackers ) )
     997            errmsg = addTrackerUrls( tor, trackers );
     998        if( !errmsg && tr_bencDictFindList( args_in, "trackerRemove", &trackers ) )
     999            errmsg = removeTrackers( tor, trackers );
     1000        if( !errmsg && tr_bencDictFindList( args_in, "trackerReplace", &trackers ) )
     1001            errmsg = replaceTrackers( tor, trackers );
    9931002        notify( session, TR_RPC_TORRENT_CHANGED, tor );
    9941003    }
Note: See TracChangeset for help on using the changeset viewer.