mturk 2002/10/21 11:05:13 Modified: jk/native2/common jk_uriMap.c jk_uriEnv.c Log: Add pcre to the uriMap. This is conditional using HAS_PCRE flag. The mapping is done using '$' as a delimiter. This means that all uris having dollar in the name will be parsed as a regular expressions without that dollar sign. [uri:$/examples/(?!\w*\.(gif|jpg)$)] will be parsed as regex without first $. Revision Changes Path 1.56 +59 -1 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.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- jk_uriMap.c 15 Oct 2002 12:27:56 -0000 1.55 +++ jk_uriMap.c 21 Oct 2002 18:05:13 -0000 1.56 @@ -75,6 +75,11 @@ #include "jk_uriMap.h" #include "jk_registry.h" +#ifdef HAS_PCRE +#include "pcre.h" +#include "pcreposix.h" +#endif + static INLINE const char *jk2_findExtension(jk_env_t *env, const char *uri); static int jk2_uriMap_checkUri(jk_env_t *env, jk_uriMap_t *uriMap, @@ -319,6 +324,35 @@ return uriMap->vhosts->get(env, uriMap->vhosts, "*"); } +#ifdef HAS_PCRE +static jk_uriEnv_t *jk2_uriMap_regexpMap(jk_env_t *env, jk_uriMap_t *uriMap, + jk_map_t *mapTable, const char *uri) +{ + int i; + int sz = mapTable->size(env, mapTable); + + for (i = 0; i < sz; i++) { + jk_uriEnv_t *uwr = mapTable->valueAt(env, mapTable, i); + + if (uwr->regexp) { + regex_t *r = (regex_t *)uwr->regexp; + regmatch_t regm[10]; + if (!regexec(r, uri, r->re_nsub + 1, regm, 0)) { + return uwr; + } + } + } + return NULL; + +} +#else +static jk_uriEnv_t *jk2_uriMap_regexpMap(jk_env_t *env, jk_uriMap_t *uriMap, + jk_map_t *mapTable, const char *uri) +{ + return NULL; +} +#endif + static void jk2_uriMap_createHosts(jk_env_t *env, jk_uriMap_t *uriMap) { int i; @@ -412,6 +446,7 @@ jk2_map_default_create(env, &uriEnv->exactMatch, uriMap->pool); jk2_map_default_create(env, &uriEnv->prefixMatch, uriMap->pool); jk2_map_default_create(env, &uriEnv->suffixMatch, uriMap->pool); + jk2_map_default_create(env, &uriEnv->regexpMatch, uriMap->pool); } } @@ -469,6 +504,7 @@ jk2_map_default_create(env, &ctxEnv->exactMatch, uriMap->pool); jk2_map_default_create(env, &ctxEnv->prefixMatch, uriMap->pool); jk2_map_default_create(env, &ctxEnv->suffixMatch, uriMap->pool); + jk2_map_default_create(env, &ctxEnv->regexpMatch, uriMap->pool); } } @@ -511,6 +547,9 @@ ctxEnv = jk2_uriMap_exactMap(env, uriMap, hostEnv->webapps, uriEnv->contextPath, uriEnv->ctxt_len); + else if (uriEnv->match_type == MATCH_TYPE_REGEXP) { + ctxEnv = hostEnv->webapps->get(env, hostEnv->webapps, "/"); + } /* Next find by uri prefix */ if (ctxEnv == NULL) ctxEnv = jk2_uriMap_prefixMap(env, uriMap, hostEnv->webapps, uri, @@ -540,6 +579,10 @@ case MATCH_TYPE_PREFIX: ctxEnv->prefixMatch->add(env, ctxEnv->prefixMatch, uri, uriEnv); break; + case MATCH_TYPE_REGEXP: + if (uriEnv->regexp) + ctxEnv->regexpMatch->add(env, ctxEnv->regexpMatch, uri, uriEnv); + break; } } return JK_OK; @@ -577,7 +620,8 @@ newEnv->worker = mapEnv->worker; newEnv->workerName = mapEnv->workerName; newEnv->workerEnv = mapEnv->workerEnv; - + newEnv->regexp = mapEnv->regexp; + return newEnv; } @@ -617,6 +661,7 @@ jk2_map_default_create(env, &newEnv->exactMatch, uriMap->pool); jk2_map_default_create(env, &newEnv->prefixMatch, uriMap->pool); jk2_map_default_create(env, &newEnv->suffixMatch, uriMap->pool); + jk2_map_default_create(env, &newEnv->regexpMatch, uriMap->pool); return newEnv; } @@ -896,6 +941,19 @@ if (uriMap->mbean->debug > 1) env->l->jkLog(env, env->l, JK_LOG_DEBUG, "uriMap.mapUri() found ctx %s\n", ctxEnv->uri); + + match = jk2_uriMap_regexpMap(env, uriMap, ctxEnv->regexpMatch, uri); + if (match != NULL) { + /* restore */ + if (url_rewrite) + *url_rewrite = origChar; + if (uriMap->mbean->debug > 0) + env->l->jkLog(env, env->l, JK_LOG_DEBUG, + "uriMap.mapUri() regexp match %s %s\n", + uri, match->workerName); + return match; + } + /* As per Servlet spec, do exact match first */ match = jk2_uriMap_exactMap(env, uriMap, ctxEnv->exactMatch, uri, uriLen); 1.39 +62 -4 jakarta-tomcat-connectors/jk/native2/common/jk_uriEnv.c Index: jk_uriEnv.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_uriEnv.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- jk_uriEnv.c 13 Oct 2002 07:39:28 -0000 1.38 +++ jk_uriEnv.c 21 Oct 2002 18:05:13 -0000 1.39 @@ -69,6 +69,10 @@ #include "jk_uriMap.h" #include "jk_registry.h" +#ifdef HAS_PCRE +#include "pcre.h" +#include "pcreposix.h" +#endif /** Parse the name: VHOST/PATH @@ -83,16 +87,31 @@ char *uri = NULL; char *colon; char host[1024]; + int pcre = 0; + + if (*name == '$') { + ++name; + uriEnv->uri = uriEnv->pool->pstrdup(env, uriEnv->pool, name); + uriEnv->match_type = MATCH_TYPE_REGEXP; + env->l->jkLog(env, env->l, JK_LOG_INFO, + "uriEnv.parseName() parsing %s regexp\n", + name); + return JK_OK; + } strcpy(host, name); colon = strchr(host, ':'); + uri = strchr(host, '$'); + if (uri) + pcre = 1; if (colon != NULL) { ++colon; - uri = strchr(colon, '/'); + if (!uri) + uri = strchr(colon, '/'); } - else + else if (!uri) uri = strchr(host, '/'); - + if (!uri) { /* That's a virtual host definition ( no actual mapping, just global * settings like aliases, etc @@ -104,6 +123,7 @@ uriEnv->virtual = uriEnv->pool->pstrdup(env, uriEnv->pool, host); return JK_OK; } + *uri = '\0'; if (colon) uriEnv->port = atoi(colon); @@ -115,8 +135,34 @@ } else uriEnv->virtual = "*"; + *uri = '/'; - uriEnv->uri = uriEnv->pool->pstrdup(env, uriEnv->pool, uri); + if (pcre) { + ++uri; + uriEnv->match_type = MATCH_TYPE_REGEXP; +#ifdef HAS_PCRE + uriEnv->uri = uriEnv->pool->pstrdup(env, uriEnv->pool, uri); + env->l->jkLog(env, env->l, JK_LOG_DEBUG, + "uriEnv.parseName() parsing regexp %s\n", + uri); + { + regex_t *preg = (regex_t *)uriEnv->pool->calloc( env, uriEnv->pool, sizeof(regex_t)); + if (regcomp(preg, uriEnv->uri, REG_EXTENDED)) { + env->l->jkLog(env, env->l, JK_LOG_DEBUG, + "uriEnv.parseName() error compiling regexp %s\n", + uri); + return JK_ERR; + } + uriEnv->regexp = preg; + } +#else + env->l->jkLog(env, env->l, JK_LOG_INFO, + "uriEnv.parseName() parsing regexp %s not supported\n", + uri); +#endif + } + else + uriEnv->uri = uriEnv->pool->pstrdup(env, uriEnv->pool, uri); return JK_OK; } @@ -261,6 +307,18 @@ if( uri==NULL ) return JK_ERR; + if (uriEnv->match_type == MATCH_TYPE_REGEXP) { + uriEnv->prefix = uri; + uriEnv->prefix_len = strlen( uriEnv->prefix ); + uriEnv->suffix = NULL; + if( uriEnv->mbean->debug > 0 ) { + env->l->jkLog(env, env->l, JK_LOG_DEBUG, + "uriEnv.init() regexp mapping %s=%s \n", + uriEnv->prefix, uriEnv->workerName); + + } + return JK_OK; + } if ('/' != uri[0]) { /* * JFC: please check...
-- To unsubscribe, e-mail: <mailto:tomcat-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:tomcat-dev-help@;jakarta.apache.org>