httpd/httpd-2.2.21-mod_proxy-change-state.patch

256 lines
11 KiB
Diff
Raw Normal View History

diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
index 1efe95c..5276cac 100644
--- a/modules/proxy/mod_proxy.c
+++ b/modules/proxy/mod_proxy.c
@@ -2242,14 +2242,7 @@ static int proxy_status_hook(request_rec *r, int flags)
char fbuf[50];
ap_rvputs(r, "<tr>\n<td>", worker->scheme, "</td>", NULL);
ap_rvputs(r, "<td>", worker->hostname, "</td><td>", NULL);
- if (worker->s->status & PROXY_WORKER_DISABLED)
- ap_rputs("Dis", r);
- else if (worker->s->status & PROXY_WORKER_IN_ERROR)
- ap_rputs("Err", r);
- else if (worker->s->status & PROXY_WORKER_INITIALIZED)
- ap_rputs("Ok", r);
- else
- ap_rputs("-", r);
+ ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
ap_rvputs(r, "</td><td>", worker->s->route, NULL);
ap_rvputs(r, "</td><td>", worker->s->redirect, NULL);
ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
index 4a4bf17..1b4ba6d 100644
--- a/modules/proxy/mod_proxy.h
+++ b/modules/proxy/mod_proxy.h
@@ -274,6 +274,16 @@ struct proxy_conn_pool {
#define PROXY_WORKER_IN_ERROR 0x0080
#define PROXY_WORKER_HOT_STANDBY 0x0100
+/* worker status flags */
+#define PROXY_WORKER_INITIALIZED_FLAG 'O'
+#define PROXY_WORKER_IGNORE_ERRORS_FLAG 'I'
+#define PROXY_WORKER_IN_SHUTDOWN_FLAG 'U'
+#define PROXY_WORKER_DISABLED_FLAG 'D'
+#define PROXY_WORKER_STOPPED_FLAG 'S'
+#define PROXY_WORKER_IN_ERROR_FLAG 'E'
+#define PROXY_WORKER_HOT_STANDBY_FLAG 'H'
+#define PROXY_WORKER_FREE_FLAG 'F'
+
#define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
@@ -776,6 +786,23 @@ PROXY_DECLARE(apr_status_t)
ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from,
apr_bucket_brigade *to);
+/**
+ * Set/unset the worker status bitfield depending on flag
+ * @param c flag
+ * @param set set or unset bit
+ * @param w worker to use
+ * @return APR_SUCCESS if valid flag
+ */
+PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(char c, int set, proxy_worker *w);
+
+/**
+ * Create readable representation of worker status bitfield
+ * @param p pool
+ * @param w worker to use
+ * @return string representation of status
+ */
+PROXY_DECLARE(char *) ap_proxy_parse_wstatus(apr_pool_t *p, proxy_worker *w);
+
#define PROXY_LBMETHOD "proxylbmethod"
/* The number of dynamic workers that can be added when reconfiguring.
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c
index 90f3d08..e58503f 100644
--- a/modules/proxy/mod_proxy_balancer.c
+++ b/modules/proxy/mod_proxy_balancer.c
@@ -675,6 +675,18 @@ static int balancer_init(apr_pool_t *p, apr_pool_t *plog,
return OK;
}
+static void create_radio(const char *name, unsigned int flag, proxy_worker *w,
+ request_rec *r)
+{
+ ap_rvputs(r, "<td>Set <input name='", name, "' value='1' type=radio", NULL);
+ if (w->s->status & flag)
+ ap_rputs(" checked", r);
+ ap_rvputs(r, "> <br/> Clear <input name='", name, "' value='0' type=radio", NULL);
+ if (!(w->s->status & flag))
+ ap_rputs(" checked", r);
+ ap_rputs("></td>\n", r);
+}
+
/* Manages the loadfactors and member status
*/
static int balancer_handler(request_rec *r)
@@ -770,11 +782,17 @@ static int balancer_handler(request_rec *r)
else
*wsel->s->redirect = '\0';
}
- if ((val = apr_table_get(params, "dw"))) {
- if (!strcasecmp(val, "Disable"))
- wsel->s->status |= PROXY_WORKER_DISABLED;
- else if (!strcasecmp(val, "Enable"))
- wsel->s->status &= ~PROXY_WORKER_DISABLED;
+ if ((val = apr_table_get(params, "status_I"))) {
+ ap_proxy_set_wstatus('I', atoi(val), wsel);
+ }
+ if ((val = apr_table_get(params, "status_N"))) {
+ ap_proxy_set_wstatus('N', atoi(val), wsel);
+ }
+ if ((val = apr_table_get(params, "status_D"))) {
+ ap_proxy_set_wstatus('D', atoi(val), wsel);
+ }
+ if ((val = apr_table_get(params, "status_H"))) {
+ ap_proxy_set_wstatus('H', atoi(val), wsel);
}
if ((val = apr_table_get(params, "ls"))) {
int ival = atoi(val);
@@ -784,10 +802,11 @@ static int balancer_handler(request_rec *r)
}
}
+
if (apr_table_get(params, "xml")) {
ap_set_content_type(r, "text/xml");
- ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n", r);
- ap_rputs("<httpd:manager xmlns:httpd=\"http://httpd.apache.org\">\n", r);
+ ap_rputs("<?xml version='1.0' encoding='UTF-8' ?>\n", r);
+ ap_rputs("<httpd:manager xmlns:httpd='http://httpd.apache.org'>\n", r);
ap_rputs(" <httpd:balancers>\n", r);
balancer = (proxy_balancer *)conf->balancers->elts;
for (i = 0; i < conf->balancers->nelts; i++) {
@@ -865,18 +884,7 @@ static int balancer_handler(request_rec *r)
ap_escape_html(r->pool, worker->s->redirect), NULL);
ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
ap_rprintf(r, "<td>%d</td><td>", worker->s->lbset);
- if (worker->s->status & PROXY_WORKER_DISABLED)
- ap_rputs("Dis ", r);
- if (worker->s->status & PROXY_WORKER_IN_ERROR)
- ap_rputs("Err ", r);
- if (worker->s->status & PROXY_WORKER_STOPPED)
- ap_rputs("Stop ", r);
- if (worker->s->status & PROXY_WORKER_HOT_STANDBY)
- ap_rputs("Stby ", r);
- if (PROXY_WORKER_IS_USABLE(worker))
- ap_rputs("Ok", r);
- if (!PROXY_WORKER_IS_INITIALIZED(worker))
- ap_rputs("-", r);
+ ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
ap_rputs("</td>", r);
ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td><td>", worker->s->elected);
ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
@@ -907,21 +915,20 @@ static int balancer_handler(request_rec *r)
ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->redirect),
NULL);
ap_rputs("\"></td></tr>\n", r);
- ap_rputs("<tr><td>Status:</td><td>Disabled: <input name=\"dw\" value=\"Disable\" type=radio", r);
- if (wsel->s->status & PROXY_WORKER_DISABLED)
- ap_rputs(" checked", r);
- ap_rputs("> | Enabled: <input name=\"dw\" value=\"Enable\" type=radio", r);
- if (!(wsel->s->status & PROXY_WORKER_DISABLED))
- ap_rputs(" checked", r);
- ap_rputs("></td></tr>\n", r);
- ap_rputs("<tr><td colspan=2><input type=submit value=\"Submit\"></td></tr>\n", r);
- ap_rvputs(r, "</table>\n<input type=hidden name=\"w\" ", NULL);
- ap_rvputs(r, "value=\"", ap_escape_uri(r->pool, wsel->name), "\">\n", NULL);
- ap_rvputs(r, "<input type=hidden name=\"b\" ", NULL);
- ap_rvputs(r, "value=\"", bsel->name + sizeof("balancer://") - 1,
- "\">\n", NULL);
- ap_rvputs(r, "<input type=hidden name=\"nonce\" value=\"",
- balancer_nonce, "\">\n", NULL);
+ ap_rputs("<tr><td>Status:</td>", r);
+ ap_rputs("<td><table border='1'><tr><th>Ign</th><th>Dis</th><th>Stby</th></tr>\n<tr>", r);
+ create_radio("status_I", PROXY_WORKER_IGNORE_ERRORS, wsel, r);
+ create_radio("status_D", PROXY_WORKER_DISABLED, wsel, r);
+ create_radio("status_H", PROXY_WORKER_HOT_STANDBY, wsel, r);
+ ap_rputs("</tr></table>\n", r);
+ ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
+ ap_rvputs(r, "</table>\n<input type=hidden name='w' ", NULL);
+ ap_rvputs(r, "value='", ap_escape_uri(r->pool, wsel->name), "'>\n", NULL);
+ ap_rvputs(r, "<input type=hidden name='b' ", NULL);
+ ap_rvputs(r, "value='", bsel->name + sizeof("balancer://") - 1,
+ "'>\n", NULL);
+ ap_rvputs(r, "<input type=hidden name='nonce' value='",
+ balancer_nonce, "'>\n", NULL);
ap_rvputs(r, "</form>\n", NULL);
ap_rputs("<hr />\n", r);
}
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
index 95f4a78..58f630b 100644
--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -2678,3 +2678,69 @@ ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from,
}
return rv;
}
+
+PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(const char c, int set, proxy_worker *w)
+{
+ char bit = toupper(c);
+ switch (bit) {
+ case PROXY_WORKER_DISABLED_FLAG :
+ if (set)
+ w->s->status |= PROXY_WORKER_DISABLED;
+ else
+ w->s->status &= ~PROXY_WORKER_DISABLED;
+ break;
+ case PROXY_WORKER_STOPPED_FLAG :
+ if (set)
+ w->s->status |= PROXY_WORKER_STOPPED;
+ else
+ w->s->status &= ~PROXY_WORKER_STOPPED;
+ break;
+ case PROXY_WORKER_IN_ERROR_FLAG :
+ if (set)
+ w->s->status |= PROXY_WORKER_IN_ERROR;
+ else
+ w->s->status &= ~PROXY_WORKER_IN_ERROR;
+ break;
+ case PROXY_WORKER_HOT_STANDBY_FLAG :
+ if (set)
+ w->s->status |= PROXY_WORKER_HOT_STANDBY;
+ else
+ w->s->status &= ~PROXY_WORKER_HOT_STANDBY;
+ break;
+ case PROXY_WORKER_IGNORE_ERRORS_FLAG :
+ if (set)
+ w->s->status |= PROXY_WORKER_IGNORE_ERRORS;
+ else
+ w->s->status &= ~PROXY_WORKER_IGNORE_ERRORS;
+ break;
+ default:
+ return APR_EINVAL;
+ break;
+ }
+ return APR_SUCCESS;
+}
+
+PROXY_DECLARE(char *) ap_proxy_parse_wstatus(apr_pool_t *p, proxy_worker *w)
+{
+ char *ret = NULL;
+ unsigned int status = w->s->status;
+ if (status & PROXY_WORKER_INITIALIZED)
+ ret = apr_pstrcat(p, "Init ", NULL);
+ else
+ ret = apr_pstrcat(p, "!Init ", NULL);
+ if (status & PROXY_WORKER_IGNORE_ERRORS)
+ ret = apr_pstrcat(p, ret, "Ign ", NULL);
+ if (status & PROXY_WORKER_IN_SHUTDOWN)
+ ret = apr_pstrcat(p, ret, "Shut ", NULL);
+ if (status & PROXY_WORKER_DISABLED)
+ ret = apr_pstrcat(p, ret, "Dis ", NULL);
+ if (status & PROXY_WORKER_STOPPED)
+ ret = apr_pstrcat(p, ret, "Stop ", NULL);
+ if (status & PROXY_WORKER_IN_ERROR)
+ ret = apr_pstrcat(p, ret, "Err ", NULL);
+ if (status & PROXY_WORKER_HOT_STANDBY)
+ ret = apr_pstrcat(p, ret, "Stby ", NULL);
+ if (PROXY_WORKER_IS_USABLE(w))
+ ret = apr_pstrcat(p, ret, "Ok ", NULL);
+ return ret;
+}