Changeset 12848


Ignore:
Timestamp:
Sep 6, 2011, 4:45:48 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) #4437 "Multi file webseeds don't work" -- handle multifile torrents with web seed urls that incorrectly don't end with a slash.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo.c

    r12416 r12848  
    355355}
    356356
     357/**
     358 * @brief Ensure that the URLs for multfile torrents end in a slash.
     359 *
     360 * See http://bittorrent.org/beps/bep_0019.html#metadata-extension
     361 * for background on how the trailing slash is used for "url-list"
     362 * fields.
     363 *
     364 * This function is to workaround some .torrent generators, such as
     365 * mktorrent and very old versions of utorrent, that don't add the
     366 * trailing slash for multifile torrents if omitted by the end user.
     367 */
     368static char*
     369fix_webseed_url( const tr_info * inf, const char * url )
     370{
     371    char * ret = NULL;
     372    const size_t len = strlen( url );
     373
     374    if( tr_urlIsValid( url, len ) )
     375    {
     376        if( ( inf->fileCount > 1 ) && ( len > 0 ) && ( url[len-1] != '/' ) )
     377            ret = tr_strdup_printf( "%*.*s/", (int)len, (int)len, url );
     378        else
     379            ret = tr_strndup( url, len );
     380    }
     381
     382    return ret;
     383}
     384
    357385static void
    358386geturllist( tr_info * inf,
     
    374402            if( tr_bencGetStr( tr_bencListChild( urls, i ), &url ) )
    375403            {
    376                 const size_t len = strlen( url );
    377 
    378                 if( tr_urlIsValid( url, len  ) )
    379                     inf->webseeds[inf->webseedCount++] = tr_strndup( url, len );
     404                char * fixed_url = fix_webseed_url( inf, url );
     405
     406                if( fixed_url != NULL )
     407                    inf->webseeds[inf->webseedCount++] = fixed_url;
    380408            }
    381409        }
     
    383411    else if( tr_bencDictFindStr( meta, "url-list", &url ) ) /* handle single items in webseeds */
    384412    {
    385         const size_t len = strlen( url );
    386 
    387         if( tr_urlIsValid( url, len  ) )
     413        char * fixed_url = fix_webseed_url( inf, url );
     414
     415        if( fixed_url != NULL )
    388416        {
    389417            inf->webseedCount = 1;
    390418            inf->webseeds = tr_new0( char*, 1 );
    391             inf->webseeds[0] = tr_strndup( url, len );
     419            inf->webseeds[0] = fixed_url;
    392420        }
    393421    }
Note: See TracChangeset for help on using the changeset viewer.