Author: jfrederic.clere(a)jboss.com
Date: 2008-03-27 07:37:57 -0400 (Thu, 27 Mar 2008)
New Revision: 1474
Modified:
sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Add logic to support DISABLED.
Modified: sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-03-27 10:25:04 UTC
(rev 1473)
+++ sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-03-27 11:37:57 UTC
(rev 1474)
@@ -144,7 +144,96 @@
}
}
+/* Retrieve the parameter with the given name
+ * Something like 'JSESSIONID=12345...N'
+ * XXX: Should use the mod_proxy_balancer ones.
+ */
+static char *get_path_param(apr_pool_t *pool, char *url,
+ const char *name)
+{
+ char *path = NULL;
+
+ for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
+ path += strlen(name);
+ if (*path == '=') {
+ /*
+ * Session path was found, get it's value
+ */
+ ++path;
+ if (strlen(path)) {
+ char *q;
+ path = apr_strtok(apr_pstrdup(pool, path), "?&", &q);
+ return path;
+ }
+ }
+ }
+ return NULL;
+}
+
+static char *get_cookie_param(request_rec *r, const char *name)
+{
+ const char *cookies;
+ const char *start_cookie;
+
+ if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
+ for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
+ start_cookie = ap_strstr_c(start_cookie + 1, name)) {
+ if (start_cookie == cookies ||
+ start_cookie[-1] == ';' ||
+ start_cookie[-1] == ',' ||
+ isspace(start_cookie[-1])) {
+
+ start_cookie += strlen(name);
+ while(*start_cookie && isspace(*start_cookie))
+ ++start_cookie;
+ if (*start_cookie == '=' && start_cookie[1]) {
+ /*
+ * Session cookie was found, get it's value
+ */
+ char *end_cookie, *cookie;
+ ++start_cookie;
+ cookie = apr_pstrdup(r->pool, start_cookie);
+ if ((end_cookie = strchr(cookie, ';')) != NULL)
+ *end_cookie = '\0';
+ if((end_cookie = strchr(cookie, ',')) != NULL)
+ *end_cookie = '\0';
+ return cookie;
+ }
+ }
+ }
+ }
+ return NULL;
+}
/*
+ * Check that the request has a sessionid (even invalid)
+ */
+static int hassession(request_rec *r, proxy_balancer *balancer)
+{
+ char *route;
+ char *uri = r->filename + 6;
+ char *sticky_path, *sticky, *path;
+
+ if (balancer->sticky == NULL)
+ return 0;
+
+ /* for 2.2.x the sticky parameter may contain 2 values */
+ sticky = sticky_path = apr_pstrdup(r->pool, balancer->sticky);
+ if ((path = strchr(sticky, '|'))) {
+ *path++ = '\0';
+ sticky_path = path;
+ }
+ route = get_path_param(r->pool, uri , sticky_path);
+ if (route == NULL)
+ route = get_cookie_param(r, sticky);
+ if (route) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "mod_proxy_cluster: found route %s", route);
+ return 1;
+ }
+ return 0;
+}
+
+/*
* Check that the worker will handle the host/context.
* The id of the worker is used to find the (slot) node in the shared
* memory.
@@ -183,14 +272,21 @@
continue;
/* check for /context[/] in the URL */
- ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r->server,
- "iscontext_host_ok: %s %s", context->context,
- r->uri);
int len = strlen(context->context);
if (strncmp(r->uri, context->context, len) == 0) {
if (r->uri[len] == '\0' || r->uri[len] == '/')
{
- /* XXX: Check status */
- return 1;
+ /* Check status */
+ switch (context->status)
+ {
+ case ENABLED:
+ return 1;
+ break;
+ case DISABLED:
+ /* Only the request with sessionid ok for it */
+ if (hassession(r, balancer))
+ return 1;
+ break;
+ }
}
}
}