Commit e3ec1485 authored by Paul Querna's avatar Paul Querna
Browse files

- Use apr_uri_t to parse the proxy URL, instead of munging it by hand....

- Use apr_uri_t to parse the proxy URL, instead of munging it by hand. Original code did not handle IPv6 Addresses correctly.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@178391 13f79535-47bb-0310-9956-ffa450edef68
parent 804250ce
Loading
Loading
Loading
Loading
+12 −25
Original line number Diff line number Diff line
@@ -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;
    int rv;
    apr_uri_t uri;

    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';
    rv = apr_uri_parse(p, url, &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)";
        }
    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++;