Changeset 10239


Ignore:
Timestamp:
Feb 20, 2010, 3:57:05 PM (13 years ago)
Author:
charles
Message:

(trunk) #2938 "crash when adding a torrent by URL from an ftp source over RPC" -- fixed in trunk for 1.91

Location:
trunk/libtransmission
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r10238 r10239  
    134134    char * host = NULL;
    135135    char * ret;
    136     tr_httpParseURL( url, strlen( url ), &host, &port, NULL );
     136    tr_urlParse( url, strlen( url ), NULL, &host, &port, NULL );
    137137    ret = tr_strdup_printf( "%s:%d", ( host ? host : "invalid" ), port );
    138138    tr_free( host );
  • trunk/libtransmission/makemeta.c

    r10016 r10239  
    381381    /* allow an empty set, but if URLs *are* listed, verify them. #814, #971 */
    382382    for( i = 0; i < builder->trackerCount && !builder->result; ++i ) {
    383         if( !tr_httpIsValidURL( builder->trackers[i].announce ) ) {
     383        if( !tr_urlIsValidTracker( builder->trackers[i].announce ) ) {
    384384            tr_strlcpy( builder->errfile, builder->trackers[i].announce,
    385385                       sizeof( builder->errfile ) );
  • trunk/libtransmission/metainfo.c

    r10084 r10239  
    289289                {
    290290                    char * url = tr_strstrip( tr_strdup( str ) );
    291                     if( tr_httpIsValidURL( url ) )
     291                    if( tr_urlIsValidTracker( url ) )
    292292                    {
    293293                        tr_tracker_info * t = trackers + trackerCount;
     
    321321    {
    322322        char * url = tr_strstrip( tr_strdup( str ) );
    323         if( tr_httpIsValidURL( url ) )
     323        if( tr_urlIsValidTracker( url ) )
    324324        {
    325325            trackers = tr_new0( tr_tracker_info, 1 );
  • trunk/libtransmission/torrent.c

    r10203 r10239  
    20872087    /* look for bad URLs */
    20882088    for( i=0; ok && i<trackerCount; ++i )
    2089         if( !tr_httpIsValidURL( trackers[i].announce ) )
     2089        if( !tr_urlIsValidTracker( trackers[i].announce ) )
    20902090            ok = FALSE;
    20912091
  • trunk/libtransmission/utils-test.c

    r9707 r10239  
    325325{
    326326    int port;
     327    char * scheme;
    327328    char * host;
    328329    char * path;
     
    331332
    332333    url = "http://www.some-tracker.org/some/path";
    333     check( !tr_httpParseURL( url, -1, &host, &port, &path ) )
     334    check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) )
     335    check( !strcmp( scheme, "http" ) )
    334336    check( !strcmp( host, "www.some-tracker.org" ) )
    335337    check( !strcmp( path, "/some/path" ) )
    336338    check( port == 80 )
     339    tr_free( scheme );
    337340    tr_free( path );
    338341    tr_free( host );
    339342
    340343    url = "http://www.some-tracker.org:80/some/path";
    341     check( !tr_httpParseURL( url, -1, &host, &port, &path ) )
     344    check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) )
     345    check( !strcmp( scheme, "http" ) )
    342346    check( !strcmp( host, "www.some-tracker.org" ) )
    343347    check( !strcmp( path, "/some/path" ) )
    344348    check( port == 80 )
     349    tr_free( scheme );
    345350    tr_free( path );
    346351    tr_free( host );
  • trunk/libtransmission/utils.c

    r10135 r10239  
    914914***/
    915915
    916 tr_bool
    917 tr_httpIsValidURL( const char * url )
     916static tr_bool
     917isValidURLChars( const char * url )
    918918{
    919919    const char * c;
     
    934934            return FALSE;
    935935
    936     return tr_httpParseURL( url, -1, NULL, NULL, NULL ) == 0;
    937 }
    938 
    939 tr_bool tr_addressIsIP( const char * address )
     936    return TRUE;
     937}
     938
     939/** @brief return TRUE if the url is a http or https url that Transmission understands */
     940tr_bool
     941tr_urlIsValidTracker( const char * url )
     942{
     943    tr_bool valid;
     944    char * scheme = NULL;
     945
     946    valid = isValidURLChars( url )
     947         && !tr_urlParse( url, -1, &scheme, NULL, NULL, NULL )
     948         && ( scheme != NULL )
     949         && ( !strcmp(scheme,"http") || !strcmp(scheme,"https") );
     950
     951    tr_free( scheme );
     952    return valid;
     953}
     954
     955/** @brief return TRUE if the url is a http or https or ftp or sftp url that Transmission understands */
     956tr_bool
     957tr_urlIsValid( const char * url )
     958{
     959    tr_bool valid;
     960    char * scheme = NULL;
     961
     962    valid = isValidURLChars( url )
     963         && !tr_urlParse( url, -1, &scheme, NULL, NULL, NULL )
     964         && ( scheme != NULL )
     965         && ( !strcmp(scheme,"http") || !strcmp(scheme,"https") || !strcmp(scheme,"ftp") || !strcmp(scheme,"sftp") );
     966
     967    tr_free( scheme );
     968    return valid;
     969}
     970
     971tr_bool
     972tr_addressIsIP( const char * address )
    940973{
    941974    tr_address tempAddr;
     
    944977
    945978int
    946 tr_httpParseURL( const char * url_in,
    947                  int          len,
    948                  char **      setme_host,
    949                  int *        setme_port,
    950                  char **      setme_path )
     979tr_urlParse( const char * url_in,
     980             int          len,
     981             char **      setme_protocol,
     982             char **      setme_host,
     983             int *        setme_port,
     984             char **      setme_path )
    951985{
    952986    int          err;
     
    9851019    }
    9861020
    987     err = !host || !path || !protocol
    988           || ( strcmp( protocol, "http" ) && strcmp( protocol, "https" ) );
     1021    err = !host || !path || !protocol;
    9891022
    9901023    if( !err && !port )
    9911024    {
     1025        if( !strcmp( protocol, "ftp" ) ) port = 21;
     1026        if( !strcmp( protocol, "sftp" ) ) port = 22;
    9921027        if( !strcmp( protocol, "http" ) ) port = 80;
    9931028        if( !strcmp( protocol, "https" ) ) port = 443;
     
    9961031    if( !err )
    9971032    {
     1033        if( setme_protocol ) *setme_protocol = tr_strdup( protocol );
     1034
    9981035        if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host =
    9991036                              tr_strdup( host ); }
  • trunk/libtransmission/utils.h

    r10069 r10239  
    437437void tr_hex_to_sha1( uint8_t * out, const char * hex ) TR_GNUC_NONNULL(1,2);
    438438
    439 
    440 /** @brief return TRUE if the url is a http, https, or ftp url that Transmission understands */
    441 tr_bool tr_httpIsValidURL( const char * url ) TR_GNUC_NONNULL(1);
    442 
    443439/** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */
    444440tr_bool tr_addressIsIP( const char * address );
    445441
     442/** @brief return TRUE if the url is a http or https url that Transmission understands */
     443tr_bool tr_urlIsValidTracker( const char * url ) TR_GNUC_NONNULL(1);
     444
     445/** @brief return TRUE if the url is a [ http, https, ftp, ftps ] url that Transmission understands */
     446tr_bool tr_urlIsValid( const char * url ) TR_GNUC_NONNULL(1);
     447
    446448/** @brief parse a URL into its component parts
    447449    @return zero on success or an error number if an error occurred */
    448 int  tr_httpParseURL( const char * url,
    449                       int          url_len,
    450                       char      ** setme_host,
    451                       int        * setme_port,
    452                       char      ** setme_path ) TR_GNUC_NONNULL(1);
     450int  tr_urlParse( const char * url,
     451                  int          url_len,
     452                  char      ** setme_scheme,
     453                  char      ** setme_host,
     454                  int        * setme_port,
     455                  char      ** setme_path ) TR_GNUC_NONNULL(1);
    453456
    454457
  • trunk/libtransmission/web.c

    r10235 r10239  
    208208dns_cache_set_fail( struct tr_web_task * task, const char * host )
    209209{
    210     if( task->session->web != NULL )
     210    if( ( task->session->web != NULL ) && ( host != NULL ) )
    211211    {
    212212        struct dns_cache_item * item;
     
    464464    assert( task->resolved_host == NULL );
    465465
    466     if( !tr_httpParseURL( task->url, -1, &host, &port, NULL ) )
     466    if( !tr_urlParse( task->url, -1, NULL, &host, &port, NULL ) )
    467467    {
    468468        task->port = port;
Note: See TracChangeset for help on using the changeset viewer.