return 0;
}
+static int
+test_url( void )
+{
+ int port;
+ char * host;
+ char * path;
+ const char * url;
+
+ url = "http://www.some-tracker.org/some/path";
+ check( !tr_httpParseURL( url, -1, &host, &port, &path ) )
+ check( !strcmp( host, "www.some-tracker.org" ) )
+ check( !strcmp( path, "/some/path" ) )
+ check( port == 80 )
+
+ url = "http://www.some-tracker.org:80/some/path";
+ check( !tr_httpParseURL( url, -1, &host, &port, &path ) )
+ check( !strcmp( host, "www.some-tracker.org" ) )
+ check( !strcmp( path, "/some/path" ) )
+ check( port == 80 )
+
+
+ return 0;
+}
+
int
main( void )
{
return i;
if( ( i = test_array( ) ) )
return i;
+ if( ( i = test_url( ) ) )
+ return i;
/* test that tr_cryptoRandInt() stays in-bounds */
for( i = 0; i < 100000; ++i )
*pch = '\0';
protocol = tmp;
pch += 3;
-/*fprintf( stderr, "protocol is [%s]... what's left is [%s]\n", protocol, pch
- );*/
+/*fprintf( stderr, "protocol is [%s]... what's left is [%s]\n", protocol, pch);*/
if( ( n = strcspn( pch, ":/" ) ) )
{
const int havePort = pch[n] == ':';
if( !err )
{
if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host =
- tr_strdup( protocol ); }
- if( setme_path ){ ( (char*)path )[-1] = '/'; *setme_path =
- tr_strdup( path - 1 ); }
+ tr_strdup( host ); }
+ if( setme_path ){ if( path[0] == '/' ) *setme_path = tr_strdup( path );
+ else { ( (char*)path )[-1] = '/'; *setme_path = tr_strdup( path - 1 ); } }
if( setme_port ) *setme_port = port;
}