Changeset 10239
- Timestamp:
- Feb 20, 2010, 3:57:05 PM (13 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/announcer.c
r10238 r10239 134 134 char * host = NULL; 135 135 char * ret; 136 tr_ httpParseURL( url, strlen( url ), &host, &port, NULL );136 tr_urlParse( url, strlen( url ), NULL, &host, &port, NULL ); 137 137 ret = tr_strdup_printf( "%s:%d", ( host ? host : "invalid" ), port ); 138 138 tr_free( host ); -
trunk/libtransmission/makemeta.c
r10016 r10239 381 381 /* allow an empty set, but if URLs *are* listed, verify them. #814, #971 */ 382 382 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 ) ) { 384 384 tr_strlcpy( builder->errfile, builder->trackers[i].announce, 385 385 sizeof( builder->errfile ) ); -
trunk/libtransmission/metainfo.c
r10084 r10239 289 289 { 290 290 char * url = tr_strstrip( tr_strdup( str ) ); 291 if( tr_ httpIsValidURL( url ) )291 if( tr_urlIsValidTracker( url ) ) 292 292 { 293 293 tr_tracker_info * t = trackers + trackerCount; … … 321 321 { 322 322 char * url = tr_strstrip( tr_strdup( str ) ); 323 if( tr_ httpIsValidURL( url ) )323 if( tr_urlIsValidTracker( url ) ) 324 324 { 325 325 trackers = tr_new0( tr_tracker_info, 1 ); -
trunk/libtransmission/torrent.c
r10203 r10239 2087 2087 /* look for bad URLs */ 2088 2088 for( i=0; ok && i<trackerCount; ++i ) 2089 if( !tr_ httpIsValidURL( trackers[i].announce ) )2089 if( !tr_urlIsValidTracker( trackers[i].announce ) ) 2090 2090 ok = FALSE; 2091 2091 -
trunk/libtransmission/utils-test.c
r9707 r10239 325 325 { 326 326 int port; 327 char * scheme; 327 328 char * host; 328 329 char * path; … … 331 332 332 333 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" ) ) 334 336 check( !strcmp( host, "www.some-tracker.org" ) ) 335 337 check( !strcmp( path, "/some/path" ) ) 336 338 check( port == 80 ) 339 tr_free( scheme ); 337 340 tr_free( path ); 338 341 tr_free( host ); 339 342 340 343 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" ) ) 342 346 check( !strcmp( host, "www.some-tracker.org" ) ) 343 347 check( !strcmp( path, "/some/path" ) ) 344 348 check( port == 80 ) 349 tr_free( scheme ); 345 350 tr_free( path ); 346 351 tr_free( host ); -
trunk/libtransmission/utils.c
r10135 r10239 914 914 ***/ 915 915 916 tr_bool917 tr_httpIsValidURL( const char * url )916 static tr_bool 917 isValidURLChars( const char * url ) 918 918 { 919 919 const char * c; … … 934 934 return FALSE; 935 935 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 */ 940 tr_bool 941 tr_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 */ 956 tr_bool 957 tr_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 971 tr_bool 972 tr_addressIsIP( const char * address ) 940 973 { 941 974 tr_address tempAddr; … … 944 977 945 978 int 946 tr_httpParseURL( const char * url_in, 947 int len, 948 char ** setme_host, 949 int * setme_port, 950 char ** setme_path ) 979 tr_urlParse( const char * url_in, 980 int len, 981 char ** setme_protocol, 982 char ** setme_host, 983 int * setme_port, 984 char ** setme_path ) 951 985 { 952 986 int err; … … 985 1019 } 986 1020 987 err = !host || !path || !protocol 988 || ( strcmp( protocol, "http" ) && strcmp( protocol, "https" ) ); 1021 err = !host || !path || !protocol; 989 1022 990 1023 if( !err && !port ) 991 1024 { 1025 if( !strcmp( protocol, "ftp" ) ) port = 21; 1026 if( !strcmp( protocol, "sftp" ) ) port = 22; 992 1027 if( !strcmp( protocol, "http" ) ) port = 80; 993 1028 if( !strcmp( protocol, "https" ) ) port = 443; … … 996 1031 if( !err ) 997 1032 { 1033 if( setme_protocol ) *setme_protocol = tr_strdup( protocol ); 1034 998 1035 if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host = 999 1036 tr_strdup( host ); } -
trunk/libtransmission/utils.h
r10069 r10239 437 437 void tr_hex_to_sha1( uint8_t * out, const char * hex ) TR_GNUC_NONNULL(1,2); 438 438 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 443 439 /** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */ 444 440 tr_bool tr_addressIsIP( const char * address ); 445 441 442 /** @brief return TRUE if the url is a http or https url that Transmission understands */ 443 tr_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 */ 446 tr_bool tr_urlIsValid( const char * url ) TR_GNUC_NONNULL(1); 447 446 448 /** @brief parse a URL into its component parts 447 449 @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); 450 int 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); 453 456 454 457 -
trunk/libtransmission/web.c
r10235 r10239 208 208 dns_cache_set_fail( struct tr_web_task * task, const char * host ) 209 209 { 210 if( task->session->web != NULL)210 if( ( task->session->web != NULL ) && ( host != NULL ) ) 211 211 { 212 212 struct dns_cache_item * item; … … 464 464 assert( task->resolved_host == NULL ); 465 465 466 if( !tr_ httpParseURL( task->url, -1, &host, &port, NULL ) )466 if( !tr_urlParse( task->url, -1, NULL, &host, &port, NULL ) ) 467 467 { 468 468 task->port = port;
Note: See TracChangeset
for help on using the changeset viewer.