Changeset 1293
- Timestamp:
- Dec 27, 2006, 5:16:12 AM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/http.c
r1141 r1293 306 306 307 307 int 308 tr_httpIsUrl( const char * url, int len ) 309 { 310 if( 0 > len ) 311 { 312 len = strlen( url ); 313 } 314 315 /* check for protocol */ 316 if( 7 > len || 0 != tr_strncasecmp( url, "http://", 7 ) ) 317 { 318 return 0; 319 } 320 321 return 7; 322 } 323 324 int 308 325 tr_httpParseUrl( const char * url, int len, 309 326 char ** host, int * port, char ** path ) … … 318 335 } 319 336 320 /* check for protocol */321 if( 7 > len || 0 != tr_strncasecmp( url, "http://", 7 ))337 ii = tr_httpIsUrl( url, len ); 338 if( 0 >= ii ) 322 339 { 323 340 tr_err( "Invalid HTTP URL" ); 324 341 return 1; 325 342 } 326 url += 7;327 len -= 7;343 url += ii; 344 len -= ii; 328 345 329 346 /* find the hostname and port */ … … 446 463 tr_httpClose( http ); 447 464 return NULL; 465 } 466 467 tr_http_t * 468 tr_httpClientUrl( int method, const char * fmt, ... ) 469 { 470 char * url, * host, * path; 471 int port; 472 va_list ap; 473 tr_http_t * ret; 474 475 va_start( ap, fmt ); 476 url = NULL; 477 vasprintf( &url, fmt, ap ); 478 va_end( ap ); 479 480 if( tr_httpParseUrl( url, -1, &host, &port, &path ) ) 481 { 482 free( url ); 483 return NULL; 484 } 485 free( url ); 486 487 ret = tr_httpClient( method, host, port, "%s", path ); 488 free( host ); 489 free( path ); 490 491 return ret; 448 492 } 449 493 -
trunk/libtransmission/http.h
r1242 r1293 51 51 char * tr_httpParse( const char * data, int len, tr_http_header_t *headers ); 52 52 53 int tr_httpIsUrl( const char *, int ); 53 54 int tr_httpParseUrl( const char *, int, char **, int *, char ** ); 54 55 … … 60 61 tr_http_t * tr_httpClient( int, const char *, int, const char *, ... ) 61 62 PRINTF( 4, 5 ); 63 tr_http_t * tr_httpClientUrl( int, const char *, ... ) 64 PRINTF( 2, 3 ); 62 65 /* only add headers or body before first pulse */ 63 66 void tr_httpAddHeader( tr_http_t *, const char *, const char * ); -
trunk/libtransmission/upnp.c
r1292 r1293 125 125 static int 126 126 parseRoot( const char *buf, int len, char ** soap, char ** scpd ); 127 static void 128 addUrlbase( const char * base, char ** path ); 127 129 static int 128 130 parseScpd( const char *buf, int len, tr_upnp_action_t * getcmd, … … 702 704 else 703 705 { 706 tr_dbg( "upnp device %s: found scpd \"%s\" and soap \"%s\"", 707 dev->root, dev->scpd, dev->soap ); 704 708 tr_dbg( "upnp device %s: parsed root, state root -> scpd", 705 709 dev->host ); … … 827 831 828 832 static tr_http_t * 833 makeHttp( int method, const char * host, int port, const char * path ) 834 { 835 if( tr_httpIsUrl( path, -1 ) ) 836 { 837 return tr_httpClientUrl( method, "%s", path ); 838 } 839 else 840 { 841 return tr_httpClient( method, host, port, "%s", path ); 842 } 843 } 844 845 static tr_http_t * 829 846 devicePulseGetHttp( tr_upnp_device_t * dev, tr_fd_t * fdlimit ) 830 847 { … … 843 860 if( !dev->soapretry ) 844 861 { 845 ret = tr_httpClient( TR_HTTP_GET, dev->host, 846 dev->port, "%s", dev->root ); 862 ret = makeHttp( TR_HTTP_GET, dev->host, dev->port, dev->root ); 847 863 } 848 864 break; … … 850 866 if( !dev->soapretry ) 851 867 { 852 ret = tr_httpClient( TR_HTTP_GET, dev->host, 853 dev->port, "%s", dev->scpd ); 868 ret = makeHttp( TR_HTTP_GET, dev->host, dev->port, dev->scpd ); 854 869 } 855 870 break; … … 974 989 { 975 990 const char * end, * ii, * jj, * kk, * urlbase; 976 char * joined;991 char * basedup; 977 992 978 993 *soap = NULL; … … 1028 1043 } 1029 1044 1045 basedup = tr_xmlDupContents( urlbase, end ); 1046 addUrlbase( basedup, soap ); 1047 addUrlbase( basedup, scpd ); 1048 free( basedup ); 1049 1030 1050 if( NULL != *soap && NULL != *scpd ) 1031 1051 { 1032 if( '/' != **soap || '/' != **scpd )1033 {1034 urlbase = tr_xmlDupContents( urlbase, end );1035 if( NULL != urlbase )1036 {1037 if( '/' != **soap )1038 {1039 joined = joinstrs( urlbase, "/", *soap );1040 free( *soap );1041 *soap = joined;1042 }1043 if( '/' != **scpd )1044 {1045 joined = joinstrs( urlbase, "/", *scpd );1046 free( *scpd );1047 *scpd = joined;1048 }1049 free( (char*)urlbase );1050 }1051 }1052 1052 return 0; 1053 1053 } 1054 1054 1055 1055 return 1; 1056 } 1057 1058 static void 1059 addUrlbase( const char * base, char ** path ) 1060 { 1061 const char * middle; 1062 int len; 1063 char * joined; 1064 1065 if( NULL == base || NULL == *path || 1066 '/' == **path || tr_httpIsUrl( *path, -1 ) ) 1067 { 1068 return; 1069 } 1070 1071 len = strlen( base ); 1072 middle = ( 0 >= len || '/' != base[len-1] ? "/" : "" ); 1073 joined = joinstrs( base, middle, *path ); 1074 free( *path ); 1075 *path = joined; 1056 1076 } 1057 1077 … … 1221 1241 1222 1242 method = ( retry ? TR_HTTP_M_POST : TR_HTTP_POST ); 1223 http = tr_httpClient( method, host, port, "%s", path );1243 http = makeHttp( method, host, port, path ); 1224 1244 if( NULL != http ) 1225 1245 {
Note: See TracChangeset
for help on using the changeset viewer.