1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00

(trunk libT) #2489: tr_torrentSetAnnounceList() should check for invalid and duplicate announce URLs

This commit is contained in:
Charles Kerr 2009-10-10 19:16:21 +00:00
parent 0fd817b757
commit 2a22e1782f
2 changed files with 30 additions and 4 deletions

View file

@ -2011,15 +2011,29 @@ tr_torrentGetMTimes( const tr_torrent * tor,
****
***/
void
tr_announce_list_err
tr_torrentSetAnnounceList( tr_torrent * tor,
const tr_tracker_info * trackers,
int trackerCount )
{
int i, j;
tr_benc metainfo;
assert( tr_isTorrent( tor ) );
/* look for bad URLs */
for( i=0; i<trackerCount; ++i )
if( !tr_httpIsValidURL( trackers[i].announce ) )
return TR_ANNOUNCE_LIST_HAS_BAD;
/* look for duplicates */
for( i=0; i<trackerCount; ++i )
for( j=0; j<trackerCount; ++j )
if( ( i != j )
&& ( trackers[i].tier == trackers[j].tier)
&& ( !strcmp( trackers[i].announce, trackers[j].announce ) ) )
return TR_ANNOUNCE_LIST_HAS_DUPLICATES;
/* save to the .torrent file */
if( !tr_bencLoadFile( &metainfo, TR_FMT_BENC, tor->info.torrent ) )
{
@ -2068,6 +2082,8 @@ tr_torrentSetAnnounceList( tr_torrent * tor,
/* tell the announcer to reload this torrent's tracker list */
tr_announcerResetTorrent( tor->session->announcer, tor );
}
return TR_ANNOUNCE_LIST_OK;
}
/**

View file

@ -1101,6 +1101,15 @@ typedef struct tr_tracker_info
}
tr_tracker_info;
typedef enum
{
TR_ANNOUNCE_LIST_OK,
TR_ANNOUNCE_LIST_HAS_DUPLICATES,
TR_ANNOUNCE_LIST_HAS_BAD
}
tr_announce_list_err;
/**
* @brief Modify a torrent's tracker list.
*
@ -1113,7 +1122,8 @@ tr_tracker_info;
* libtransmission derives `scrape' from `announce'.
* @param trackerCount size of the `trackers' array
*/
void tr_torrentSetAnnounceList( tr_torrent * torrent,
tr_announce_list_err
tr_torrentSetAnnounceList( tr_torrent * torrent,
const tr_tracker_info * trackers,
int trackerCount );