From: Jim Jagielski Date: Mon, 28 Nov 2011 20:11:44 +0000 (+0000) Subject: Pull this out as a sep function to allow for full vhosting X-Git-Tag: 2.5.0-alpha~7794 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef5be92f5e40ce053b806577ca3dc704fc854169;p=apache Pull this out as a sep function to allow for full vhosting adjustment between get and define balancers... git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1207562 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 234bfed088..6ac8dc88fa 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -644,6 +644,17 @@ PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p, proxy_server_conf *conf, const char *url); +/** + * Update the balancer's vhost related fields + * @param p memory pool used for temporary storage while finding balancer + * @param balancer balancer to be updated + * @param url url to find vhost info + * @return error string or NULL if OK + */ +PROXY_DECLARE(char *) ap_proxy_update_balancer(apr_pool_t *p, + proxy_balancer *balancer, + const char *url); + /** * Define and Allocate space for the balancer to proxy configuration * @param p memory pool to allocate balancer from diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index a89a8db233..6ae1253937 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1316,6 +1316,26 @@ PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p, return NULL; } + +PROXY_DECLARE(char *) ap_proxy_update_balancer(apr_pool_t *p, + proxy_balancer *balancer, + const char *url) +{ + apr_uri_t puri; + if (apr_uri_parse(p, url, &puri) != APR_SUCCESS) { + return apr_psprintf(p, "unable to parse: %s", url); + } + if (puri.path && PROXY_STRNCPY(balancer->s->vpath, puri.path) != APR_SUCCESS) { + return apr_psprintf(p, "balancer %s front-end virtual-path (%s) too long", + balancer->s->name, puri.path); + } + if (puri.hostname && PROXY_STRNCPY(balancer->s->vhost, puri.hostname) != APR_SUCCESS) { + return apr_psprintf(p, "balancer %s front-end vhost name (%s) too long", + balancer->s->name, puri.hostname); + } + return NULL; +} + PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, proxy_balancer **balancer, proxy_server_conf *conf, @@ -1329,7 +1349,6 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, proxy_balancer_shared *bshared; char *c, *q, *uri = apr_pstrdup(p, url); const char *sname; - apr_uri_t puri; /* We should never get here without a valid BALANCER_PREFIX... */ @@ -1344,8 +1363,6 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, *balancer = apr_array_push(conf->balancers); memset(*balancer, 0, sizeof(proxy_balancer)); - apr_uri_parse(p, alias, &puri); - /* * NOTE: The default method is byrequests, which we assume * exists! @@ -1378,9 +1395,6 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, if (PROXY_STRNCPY(bshared->sname, sname) != APR_SUCCESS) { return apr_psprintf(p, "balancer safe-name (%s) too long", sname); } - if (PROXY_STRNCPY(bshared->vpath, puri.path) != APR_SUCCESS) { - return apr_psprintf(p, "balancer front-end virtual-path (%s) too long", puri.path); - } bshared->hash = ap_proxy_hashfunc(bshared->name, PROXY_HASHFUNC_DEFAULT); (*balancer)->hash = bshared->hash; @@ -1394,7 +1408,7 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, (*balancer)->s = bshared; - return NULL; + return ap_proxy_update_balancer(p, *balancer, alias); } /*