]> granicus.if.org Git - transmission/commitdiff
(trunk libT) fix errors in tr_httpParseURL()
authorCharles Kerr <charles@transmissionbt.com>
Thu, 10 Dec 2009 09:13:08 +0000 (09:13 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 10 Dec 2009 09:13:08 +0000 (09:13 +0000)
libtransmission/utils-test.c
libtransmission/utils.c

index 95ba3abc9f3932e242c4471c3ae0ce65331ecd7c..7dde56f278db1e6cef7e24151803c2438c8e7e34 100644 (file)
@@ -319,6 +319,30 @@ test_array( void )
     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 )
 {
@@ -365,6 +389,8 @@ 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 )
index a20c1adfb51ad1af6955d6d33bd177fd69e1207d..49a8ba818bce53bff19e4a415e4493473bf7437f 100644 (file)
@@ -984,8 +984,7 @@ tr_httpParseURL( const char * url_in,
         *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] == ':';
@@ -1017,9 +1016,9 @@ tr_httpParseURL( const char * url_in,
     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;
     }