Created
May 7, 2013 08:00
-
-
Save Karm/5530970 to your computer and use it in GitHub Desktop.
IMHO updated with https://issues.jboss.org/browse/MODCLUSTER-328
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Find the best nodes for a request (check host and context (and balancer)) | |
* @param r the request_rec | |
* @param balancer the balancer (balancer to use in that case we check it). | |
* @param route from the sessionid if we have one. | |
* @param use_alias compare alias with server_name | |
* @return a pointer to a list of nodes. | |
*/ | |
static node_context *find_node_context_host(request_rec *r, proxy_balancer *balancer, const char *route, int use_alias, proxy_vhost_table* vhost_table, proxy_context_table* context_table) | |
{ | |
int sizecontext = context_table->sizecontext; | |
int *contexts; | |
int *length; | |
int *status; | |
int i, j, max; | |
node_context *best; | |
int nbest; | |
const char *uri = NULL; | |
+ const char *luri = NULL; | |
/* use r->uri (trans) or r->filename (after canon or rewrite) */ | |
if (r->filename) { | |
const char *scheme = strstr(r->filename, "://"); | |
if (scheme) | |
- uri = ap_strchr_c(scheme + 3, '/'); | |
+ luri = ap_strchr_c(scheme + 3, '/'); | |
} | |
- if (!uri) | |
+ if (!luri) | |
+ luri = r->uri; | |
+ uri = ap_strchr_c(luri, '?'); | |
+ if (uri) | |
+ uri = apr_pstrndup(r->pool, luri, uri - luri); | |
+ else | |
uri = r->uri; | |
/* read the contexts */ | |
if (sizecontext == 0) | |
return NULL; | |
contexts = apr_palloc(r->pool, sizeof(int)*sizecontext); | |
for (i=0; i < sizecontext; i++) | |
contexts[i] = i; | |
length = apr_pcalloc(r->pool, sizeof(int)*sizecontext); | |
status = apr_palloc(r->pool, sizeof(int)*sizecontext); | |
/* Check the virtual host */ | |
if (use_alias) { | |
/* read the hosts */ | |
int sizevhost; | |
int *contextsok = apr_pcalloc(r->pool, sizeof(int)*sizecontext); | |
const char *hostname = ap_get_server_name(r); | |
#if HAVE_CLUSTER_EX_DEBUG | |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, | |
"find_node_context_host: Host: %s", hostname); | |
#endif | |
sizevhost = vhost_table->sizevhost; | |
for (i=0; i<sizevhost; i++) { | |
hostinfo_t *vhost = vhost_table->vhost_info + i; | |
if (strcmp(hostname, vhost->host) == 0) { | |
/* add the contexts that match */ | |
for (j=0; j<sizecontext; j++) { | |
contextinfo_t *context = &context_table->context_info[j]; | |
if (context->vhost == vhost->vhost && context->node == vhost->node) | |
contextsok[j] = 1; | |
} | |
} | |
} | |
for (j=0; j<sizecontext; j++) { | |
if (!contextsok[j]) | |
contexts[j] = -1; | |
} | |
} | |
#if HAVE_CLUSTER_EX_DEBUG | |
for (j=0; j<sizecontext; j++) { | |
contextinfo_t *context; | |
if (contexts[j] == -1) continue; | |
context = &context_table->context_info[j]; | |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, | |
- "find_node_context_host: node: %d vhost: %d context: %s", | |
- context->node, context->vhost, context->context); | |
+ "find_node_context_host: %s node: %d vhost: %d context: %s", | |
+ uri, context->node, context->vhost, context->context); | |
} | |
#endif | |
/* Check the contexts */ | |
max = 0; | |
for (j=0; j<sizecontext; j++) { | |
contextinfo_t *context; | |
int len; | |
if (contexts[j] == -1) continue; | |
context = &context_table->context_info[j]; | |
/* keep only the contexts corresponding to our balancer */ | |
if (balancer != NULL) { | |
nodeinfo_t *node; | |
if (node_storage->read_node(context->node, &node) != APR_SUCCESS) | |
continue; | |
#if AP_MODULE_MAGIC_AT_LEAST(20101223,1) | |
if (strlen(balancer->s->name) > 11 && strcasecmp(&balancer->s->name[11], node->mess.balancer) != 0) | |
#else | |
if (strlen(balancer->name) > 11 && strcasecmp(&balancer->name[11], node->mess.balancer) != 0) | |
#endif | |
continue; | |
} | |
len = strlen(context->context); | |
if (strncmp(uri, context->context, len) == 0) { | |
if (uri[len] == '\0' || uri[len] == '/' || len==1) { | |
status[j] = context->status; | |
length[j] = len; | |
if (len > max) { | |
max = len; | |
} | |
} | |
} | |
} | |
if (max == 0) | |
return NULL; | |
/* find the best matching contexts */ | |
nbest = 1; | |
for (j=0; j<sizecontext; j++) | |
if (length[j] == max) | |
nbest++; | |
best = apr_palloc(r->pool, sizeof(node_context)*nbest); | |
nbest = 0; | |
for (j=0; j<sizecontext; j++) | |
if (length[j] == max) { | |
contextinfo_t *context; | |
int ok = 0; | |
context = &context_table->context_info[j]; | |
/* Check status */ | |
switch (status[j]) { | |
case ENABLED: | |
ok = -1; | |
break; | |
case DISABLED: | |
/* Only the request with sessionid ok for it */ | |
if (hassession_byname(r, context->node, route)) { | |
ok = -1; | |
} | |
break; | |
} | |
if (ok) { | |
best[nbest].node = context->node; | |
best[nbest].context = context->id; | |
nbest++; | |
} | |
} | |
if (nbest == 0) | |
return NULL; | |
best[nbest].node = -1; | |
return best; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix:
https://issues.jboss.org/browse/MODCLUSTER-335