mturk 2002/10/03 03:32:29 Modified: jk/native2/common jk_uriMap.c Log: Fix and rewrite the hostMap. It was a real mess. There was also a bug in the code that casused host mapping to be sensitive to the order of directives in the config. Revision Changes Path 1.50 +34 -16 jakarta-tomcat-connectors/jk/native2/common/jk_uriMap.c Index: jk_uriMap.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_uriMap.c,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- jk_uriMap.c 3 Oct 2002 01:33:14 -0000 1.49 +++ jk_uriMap.c 3 Oct 2002 10:32:29 -0000 1.50 @@ -254,44 +254,62 @@ static jk_uriEnv_t *jk2_uriMap_hostMap(jk_env_t *env, jk_uriMap_t *uriMap, const char *vhost, int port) { - int i, j; + int i, j, n; char *name; - char vs[1024] = {0}; - char vv[1024] = {0}; + char hostame[1024] = {0}; - int n = uriMap->vhosts->size(env, uriMap->vhosts); if (port) { - if (vhost && strchr(vhost, ':')) - strcpy(vs, vhost); + if (vhost) { + if (strchr(vhost, ':')) + strcpy(hostame, vhost); + else + sprintf(hostame, "%s:%d", vhost, port); + } else - sprintf(vs, "%s:%d", vhost ? vhost : "*", port); - sprintf(vv, "*:%d", port); + sprintf(hostame, "*:%d", port); } - else - strcpy(vs, vhost ? vhost : "*"); - + else if (vhost) + strcpy(hostame, vhost); + else /* Return default host if vhost and port wasn't suplied */ + return uriMap->vhosts->get(env, uriMap->vhosts, "*"); + + n = uriMap->vhosts->size(env, uriMap->vhosts); + /* Check the hostnames first */ for (i = 0 ; i < n ; i++) { jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i); name = uriMap->vhosts->nameAt(env, uriMap->vhosts, i); /* Host name is not case sensitive */ - if (strcasecmp(name, vs) == 0) { + if (strcasecmp(name, hostame) == 0) { if (port == 0 || port == uriEnv->port) return uriEnv; } - else if (uriEnv->aliases) { + } + /* Then for each vhost, check the aliases */ + for (i = 0 ; i < n ; i++) { + jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i); + name = uriMap->vhosts->nameAt(env, uriMap->vhosts, i); + if (uriEnv->aliases && vhost) { int m = uriEnv->aliases->size(env, uriEnv->aliases); for (j = 0; j < m; j++) { name = uriEnv->aliases->nameAt(env, uriEnv->aliases, j); - if (strcasecmp(name, vhost) == 0) { + if (strcasecmp(name, hostame) == 0) { if (port == 0 || port == uriEnv->port) return uriEnv; } } } - else if (port && strcasecmp(name, vv) == 0) { - return uriEnv; + } + /* Finally, check aginst *:port hostname */ + if (port) { + for (i = 0 ; i < n ; i++) { + jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i); + name = uriMap->vhosts->nameAt(env, uriMap->vhosts, i); + if ((strncmp(name, "*:", 2) == 0) && uriEnv->port == port) { + return uriEnv; + } } } + /* Return default host if none found */ return uriMap->vhosts->get(env, uriMap->vhosts, "*"); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>