Changeset 9630


Ignore:
Timestamp:
Nov 29, 2009, 5:49:58 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2631 "Add webseed support to magnet links"

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/magnet-test.c

    r9531 r9630  
    4545          "&dn=Display%20Name"
    4646          "&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
    47           "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce";
     47          "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"
     48          "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile";
    4849    info = tr_magnetParse( uri );
    4950    check( info != NULL )
    50     check( info->announceCount == 2 );
    51     check( !strcmp( info->announceURLs[0], "http://tracker.openbittorrent.com/announce" ) )
    52     check( !strcmp( info->announceURLs[1], "http://tracker.opentracker.org/announce" ) )
     51    check( info->trackerCount == 2 );
     52    check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) )
     53    check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) )
     54    check( info->webseedCount == 1 );
     55    check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) )
    5356    check( !strcmp( info->displayName, "Display Name" ) )
    5457    for( i=0; i<20; ++i )
     
    6265          "&dn=Display%20Name"
    6366          "&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
     67          "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"
    6468          "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce";
    6569    info = tr_magnetParse( uri );
    6670    check( info != NULL )
    67     check( info->announceCount == 2 );
    68     check( !strcmp( info->announceURLs[0], "http://tracker.openbittorrent.com/announce" ) )
    69     check( !strcmp( info->announceURLs[1], "http://tracker.opentracker.org/announce" ) )
     71    check( info->trackerCount == 2 );
     72    check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) )
     73    check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) )
     74    check( info->webseedCount == 1 );
     75    check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) )
    7076    check( !strcmp( info->displayName, "Display Name" ) )
    7177    for( i=0; i<20; ++i )
  • trunk/libtransmission/magnet.c

    r9548 r9630  
    9494
    9595#define MAX_TRACKERS 64
     96#define MAX_WEBSEEDS 64
    9697
    9798tr_magnet_info *
     
    99100{
    100101    tr_bool got_checksum = FALSE;
    101     int announceCount = 0;
    102     char * announceURLs[MAX_TRACKERS];
     102    int trCount = 0;
     103    int wsCount = 0;
     104    char * tr[MAX_TRACKERS];
     105    char * ws[MAX_WEBSEEDS];
    103106    char * displayName = NULL;
    104107    uint8_t sha1[SHA_DIGEST_LENGTH];
     
    150153
    151154            if( ( keylen==2 ) && !memcmp( key, "tr", 2 ) )
    152                 announceURLs[announceCount++] = tr_http_unescape( val, vallen );
     155                tr[trCount++] = tr_http_unescape( val, vallen );
     156
     157            if( ( keylen==2 ) && !memcmp( key, "ws", 2 ) )
     158                ws[wsCount++] = tr_http_unescape( val, vallen );
    153159
    154160            walk = next != NULL ? next + 1 : NULL;
     
    160166        info = tr_new0( tr_magnet_info, 1 );
    161167        info->displayName = displayName;
    162         info->announceCount = announceCount;
    163         info->announceURLs = tr_memdup( announceURLs, sizeof(char*) * announceCount );
     168        info->trackerCount = trCount;
     169        info->trackers = tr_memdup( tr, sizeof(char*) * trCount );
     170        info->webseedCount = wsCount;
     171        info->webseeds = tr_memdup( ws, sizeof(char*) * wsCount );
    164172        memcpy( info->hash, sha1, sizeof(uint8_t) * SHA_DIGEST_LENGTH );
    165173    }
     
    175183        int i;
    176184
    177         for( i=0; i<info->announceCount; ++i )
    178             tr_free( info->announceURLs[i] );
     185        for( i=0; i<info->trackerCount; ++i )
     186            tr_free( info->trackers[i] );
     187        tr_free( info->trackers );
    179188
    180         tr_free( info->announceURLs );
     189        for( i=0; i<info->webseedCount; ++i )
     190            tr_free( info->webseeds[i] );
     191        tr_free( info->webseeds );
     192
    181193        tr_free( info->displayName );
    182194        tr_free( info );
  • trunk/libtransmission/magnet.h

    r9544 r9630  
    1919{
    2020    uint8_t hash[20];
     21
    2122    char * displayName;
    22     char ** announceURLs;
    23     int announceCount;
     23
     24    int trackerCount;
     25    char ** trackers;
     26
     27    int webseedCount;
     28    char ** webseeds;
    2429}
    2530tr_magnet_info;
  • trunk/libtransmission/metainfo.c

    r9568 r9630  
    586586
    587587    /* trackers */
    588     if( m->announceCount > 0 )
     588    if(( inf->trackerCount = m->trackerCount ))
    589589    {
    590590        int i;
    591         const int n = m->announceCount;
    592 
    593         inf->trackerCount = n;
     591        const int n = m->trackerCount;
     592
    594593        inf->trackers = tr_new0( tr_tracker_info, n );
    595594        for( i=0; i<n; ++i ) {
    596             const char * url = m->announceURLs[i];
     595            const char * url = m->trackers[i];
    597596            inf->trackers[i].tier = i;
    598597            inf->trackers[i].announce = tr_strdup( url );
     
    600599        }
    601600    }
    602 }
     601
     602    /* webseeds */
     603    if(( inf->webseedCount = m->webseedCount ))
     604    {
     605        int i;
     606        const int n = m->webseedCount;
     607
     608        inf->webseeds = tr_new0( char*, n );
     609        for( i=0; i<n; ++i )
     610            inf->webseeds[i] = tr_strdup( m->webseeds[i] );
     611    }
     612}
Note: See TracChangeset for help on using the changeset viewer.