Make parse_url preserve its input string
authorDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 12 May 2010 21:10:29 +0000 (22:10 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 12 May 2010 21:10:31 +0000 (22:10 +0100)
It still screws with it as it parses it, but at least it puts it back now.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
http.c

diff --git a/http.c b/http.c
index 9b4779b..d3bdc3b 100644 (file)
--- a/http.c
+++ b/http.c
@@ -538,11 +538,8 @@ int parse_url(char *url, char **res_proto, char **res_host, int *res_port,
        }
 
        path = strchr(host, '/');
-       if (path) {
+       if (path)
                *(path++) = 0;
-               if (!*path)
-                       path = NULL;
-       }
 
        port_str = strrchr(host, ':');
        if (port_str) {
@@ -562,7 +559,13 @@ int parse_url(char *url, char **res_proto, char **res_host, int *res_port,
        if (res_port)
                *res_port = port;
        if (res_path)
-               *res_path = path ? strdup(path) : NULL;
+               *res_path = (path && *path) ? strdup(path) : NULL;
+
+       /* Undo the damage we did to the original string */
+       if (path)
+               *(path - 1) = '/';
+       if (proto)
+               *(host - 3) = ':';
        return 0;
 }