]> granicus.if.org Git - apache/commitdiff
- Use apr_uri_t to parse the proxy URL, instead of munging it by hand. Original code...
authorPaul Querna <pquerna@apache.org>
Wed, 25 May 2005 06:42:33 +0000 (06:42 +0000)
committerPaul Querna <pquerna@apache.org>
Wed, 25 May 2005 06:42:33 +0000 (06:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@178391 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/proxy_util.c

index 6a9165ce1196d543013a2055ce24cb7a4cf63c5b..86335b44ac35f48158352038a62a8a88e45d8537 100644 (file)
@@ -1243,35 +1243,22 @@ PROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker,
                                                 proxy_server_conf *conf,
                                                 const char *url)
 {
-    char *c, *q, *uri = apr_pstrdup(p, url);
-    int port;
-    
-    c = strchr(uri, ':');   
-    if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0')
-       return "Bad syntax for a remote proxy server";
-    /* remove path from uri */
-    if ((q = strchr(c + 3, '/')))
-        *q = '\0';
+    int rv;
+    apr_uri_t uri;
 
-    q = strchr(c + 3, ':');
-    if (q != NULL) {
-        if (sscanf(q + 1, "%u", &port) != 1 || port > 65535) {
-            return "Bad syntax for a remote proxy server (bad port number)";
-        }
+    rv = apr_uri_parse(p, url, &uri);
+
+    if (rv != APR_SUCCESS) {
+        return "Unable to parse URL";
     }
-    else
-        port = -1;
-    ap_str_tolower(uri);
+
+    ap_str_tolower(uri.hostname);
     *worker = apr_array_push(conf->workers);
     memset(*worker, 0, sizeof(proxy_worker));
-    (*worker)->name = apr_pstrdup(p, uri);
-    *c = '\0';
-    (*worker)->scheme = uri;
-    (*worker)->hostname = c + 3;
-
-    if (port == -1)
-        port = apr_uri_port_of_scheme((*worker)->scheme);
-    (*worker)->port = port;
+    (*worker)->name = apr_uri_unparse(p, &uri, APR_URI_UNP_REVEALPASSWORD);
+    (*worker)->scheme = uri.scheme;
+    (*worker)->hostname = uri.hostname;
+    (*worker)->port = uri.port;
     (*worker)->id   = proxy_lb_workers;
     /* Increase the total worker count */
     proxy_lb_workers++;