Return-Path: Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 2876 invoked by uid 500); 6 May 2002 03:10:25 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 2865 invoked by uid 500); 6 May 2002 03:10:25 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Date: 6 May 2002 03:10:24 -0000 Message-ID: <20020506031024.28689.qmail@icarus.apache.org> From: jwoolley@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0/modules/mappers mod_rewrite.c mod_rewrite.h X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jwoolley 02/05/05 20:10:24 Modified: . CHANGES modules/mappers mod_rewrite.c mod_rewrite.h Log: Added an optional function (ap_register_rewrite_mapfunc) which allows third-party modules to extend mod_rewrite's "int:" internal RewriteMap functionality. Concept by: Tahiry Ramanamampanoharana Revision Changes Path 1.759 +4 -0 httpd-2.0/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/httpd-2.0/CHANGES,v retrieving revision 1.758 retrieving revision 1.759 diff -u -d -u -r1.758 -r1.759 --- CHANGES 4 May 2002 06:14:04 -0000 1.758 +++ CHANGES 6 May 2002 03:10:22 -0000 1.759 @@ -1,5 +1,9 @@ Changes with Apache 2.0.37 + *) Allow mod_rewrite's set of "int:" internal RewriteMap functions + to be extended by third-party modules via an optional function. + [Tahiry Ramanamampanoharana , Cliff Woolley] + *) Fix mod_include expression parser's handling of unquoted strings followed immediately by a closing paren. PR 8462. [Brian Pane] 1.108 +36 -28 httpd-2.0/modules/mappers/mod_rewrite.c Index: mod_rewrite.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v retrieving revision 1.107 retrieving revision 1.108 diff -u -d -u -r1.107 -r1.108 --- mod_rewrite.c 22 Apr 2002 10:27:01 -0000 1.107 +++ mod_rewrite.c 6 May 2002 03:10:24 -0000 1.108 @@ -90,6 +90,7 @@ #include "apr.h" #include "apr_strings.h" +#include "apr_hash.h" #include "apr_user.h" #include "apr_lib.h" #include "apr_signal.h" @@ -180,6 +181,9 @@ /* the module (predeclaration) */ module AP_MODULE_DECLARE_DATA rewrite_module; + /* rewritemap int: handler function registry */ +static apr_hash_t *mapfunc_hash; + /* the cache */ static cache *cachep; @@ -458,19 +462,8 @@ newmap->type = MAPTYPE_INT; newmap->datafile = NULL; newmap->checkfile = NULL; - if (strcmp(a2+4, "tolower") == 0) { - newmap->func = rewrite_mapfunc_tolower; - } - else if (strcmp(a2+4, "toupper") == 0) { - newmap->func = rewrite_mapfunc_toupper; - } - else if (strcmp(a2+4, "escape") == 0) { - newmap->func = rewrite_mapfunc_escape; - } - else if (strcmp(a2+4, "unescape") == 0) { - newmap->func = rewrite_mapfunc_unescape; - } - else if (sconf->state == ENGINE_ENABLED) { + newmap->func = apr_hash_get(mapfunc_hash, a2+4, strlen(a2+4)); + if ((sconf->state == ENGINE_ENABLED) && (newmap->func == NULL)) { return apr_pstrcat(cmd->pool, "RewriteMap: internal map not found:", a2+4, NULL); } @@ -921,15 +914,31 @@ /* ** ** Global Module Initialization -** [called from read_config() after all -** config commands were already called] ** */ -static int init_module(apr_pool_t *p, - apr_pool_t *plog, - apr_pool_t *ptemp, - server_rec *s) +static int pre_config(apr_pool_t *pconf, + apr_pool_t *plog, + apr_pool_t *ptemp) +{ + APR_OPTIONAL_FN_TYPE(ap_register_rewrite_mapfunc) *map_pfn_register; + + /* register int: rewritemap handlers */ + mapfunc_hash = apr_hash_make(pconf); + map_pfn_register = APR_RETRIEVE_OPTIONAL_FN(ap_register_rewrite_mapfunc); + if (map_pfn_register) { + map_pfn_register("tolower", rewrite_mapfunc_tolower); + map_pfn_register("toupper", rewrite_mapfunc_toupper); + map_pfn_register("escape", rewrite_mapfunc_escape); + map_pfn_register("unescape", rewrite_mapfunc_unescape); + } + return OK; +} + +static int post_config(apr_pool_t *p, + apr_pool_t *plog, + apr_pool_t *ptemp, + server_rec *s) { apr_status_t rv; void *data; @@ -2781,7 +2790,7 @@ } } else if (s->type == MAPTYPE_INT) { - if ((value = lookup_map_internal(r, s->func, key)) != NULL) { + if ((value = s->func(r, key)) != NULL) { rewritelog(r, 5, "map lookup OK: map=%s key=%s -> val=%s", s->name, key, value); return value; @@ -2982,13 +2991,9 @@ } } -static char *lookup_map_internal(request_rec *r, - char *(*func)(request_rec *, char *), - char *key) +static void ap_register_rewrite_mapfunc(char *name, rewrite_mapfunc_t *func) { - /* currently we just let the function convert - the key to a corresponding value */ - return func(r, key); + apr_hash_set(mapfunc_hash, name, strlen(name), (const void *)func); } static char *rewrite_mapfunc_toupper(request_rec *r, char *key) @@ -4187,8 +4192,11 @@ static void register_hooks(apr_pool_t *p) { + APR_REGISTER_OPTIONAL_FN(ap_register_rewrite_mapfunc); + ap_hook_handler(handler_redirect, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_config(init_module, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_pre_config(pre_config, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_child_init(init_child, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_fixups(hook_fixup, NULL, NULL, APR_HOOK_FIRST); 1.31 +15 -7 httpd-2.0/modules/mappers/mod_rewrite.h Index: mod_rewrite.h =================================================================== RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -u -r1.30 -r1.31 --- mod_rewrite.h 5 Apr 2002 20:01:20 -0000 1.30 +++ mod_rewrite.h 6 May 2002 03:10:24 -0000 1.31 @@ -115,6 +115,7 @@ #if APR_HAS_THREADS #include "apr_thread_mutex.h" #endif +#include "apr_optional.h" #include "ap_config.h" /* Include from the Apache server ... */ @@ -384,10 +385,13 @@ char *key, char *val); /* initialisation */ -static int init_module(apr_pool_t *p, - apr_pool_t *plog, - apr_pool_t *ptemp, - server_rec *s); +static int pre_config(apr_pool_t *pconf, + apr_pool_t *plog, + apr_pool_t *ptemp); +static int post_config(apr_pool_t *pconf, + apr_pool_t *plog, + apr_pool_t *ptemp, + server_rec *s); static void init_child(apr_pool_t *p, server_rec *s); /* runtime hooks */ @@ -425,13 +429,17 @@ #endif static char *lookup_map_program(request_rec *r, apr_file_t *fpin, apr_file_t *fpout, char *key); -static char *lookup_map_internal(request_rec *r, - char *(*func)(request_rec *r, char *key), - char *key); + +typedef char *(rewrite_mapfunc_t)(request_rec *r, char *key); +static void ap_register_rewrite_mapfunc(char *name, rewrite_mapfunc_t *func); +APR_DECLARE_OPTIONAL_FN(void, ap_register_rewrite_mapfunc, + (char *name, rewrite_mapfunc_t *func)); + static char *rewrite_mapfunc_toupper(request_rec *r, char *key); static char *rewrite_mapfunc_tolower(request_rec *r, char *key); static char *rewrite_mapfunc_escape(request_rec *r, char *key); static char *rewrite_mapfunc_unescape(request_rec *r, char *key); + static char *select_random_value_part(request_rec *r, char *value); static void rewrite_rand_init(void); static int rewrite_rand(int l, int h);