httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@engelschall.com (Ralf S. Engelschall)
Subject Re: mod_rewrite/1631: support for case conversion added to mod_rewrite (fwd)
Date Sun, 08 Feb 1998 13:19:26 GMT
Hello Dean Gaudet, in a previous mail you wrote:

> I believe this is the last piece of the puzzle required to implement
> "virtual" virtual hosts... the ones where you don't even have
> <VirtualHost> directives, but instead use a few mod_rewrite rules to do
> all the mappings... and can support arbitrary numbers of vhosts easily.
> (The other piece was UseCanonicalName.)
> 
> I'm +1 on this feature. 
>[...]
> +    int (*fn)(int);                /* function pointer for internal map types */
>[...]

Yes, +1 for the feature but -1 for this patch itself. Because it assumes that
all conversion functions just translate on a char-to-char basis instead of the
more general str-to-str basis. Only the latter one is extendable in the
future, I think. So, I've revised the patch to meet this criteria and now I'm
happy, too ;-)

So, +1 on this feature and +1 for my appended version of the patch for
1.3b5-dev.

                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: mod_rewrite.h
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/modules/standard/mod_rewrite.h,v
retrieving revision 1.36
diff -u -r1.36 mod_rewrite.h
--- mod_rewrite.h	1998/01/07 16:46:56	1.36
+++ mod_rewrite.h	1998/02/08 13:14:28
@@ -184,6 +184,7 @@
 #define MAPTYPE_TXT                 1<<0
 #define MAPTYPE_DBM                 1<<1
 #define MAPTYPE_PRG                 1<<2
+#define MAPTYPE_INT                 1<<3
 
 #define ENGINE_DISABLED             1<<0
 #define ENGINE_ENABLED              1<<1
@@ -228,8 +229,10 @@
     char *datafile;                /* filename for map data files */
     char *checkfile;               /* filename to check for map existence */
     int   type;                    /* the type of the map */
-    int   fpin;                    /* in  filepointer for program maps */
-    int   fpout;                   /* out filepointer for program maps */
+    int   fpin;                    /* in  file pointer for program maps */
+    int   fpout;                   /* out file pointer for program maps */
+    char *(*func)(request_rec *,   /* function pointer for internal maps */
+                  char *);         
 } rewritemap_entry;
 
 typedef struct {
@@ -385,13 +388,16 @@
 static char *expand_tildepaths(request_rec *r, char *uri);
 static void  expand_map_lookups(request_rec *r, char *uri, int uri_len);
 
-    /* DBM hashfile support functions */
+    /* rewrite map support functions */
 static char *lookup_map(request_rec *r, char *name, char *key);
 static char *lookup_map_txtfile(request_rec *r, char *file, char *key);
 #if HAS_NDBM_LIB
 static char *lookup_map_dbmfile(request_rec *r, char *file, char *key);
 #endif
 static char *lookup_map_program(request_rec *r, int fpin, int fpout, char *key);
+static char *lookup_map_internal(request_rec *r, char *(*func)(request_rec *r, char *key),
char *key);
+static char *rewrite_mapfunc_toupper(request_rec *r, char *key);
+static char *rewrite_mapfunc_tolower(request_rec *r, char *key);
 
     /* rewriting logfile support */
 static void  open_rewritelog(server_rec *s, pool *p);
Index: mod_rewrite.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.66
diff -u -r1.66 mod_rewrite.c
--- mod_rewrite.c	1998/02/02 22:33:40	1.66
+++ mod_rewrite.c	1998/02/08 13:13:43
@@ -93,6 +93,7 @@
 #include <time.h>
 #include <signal.h>
 #include <errno.h>
+#include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #ifdef WIN32
@@ -435,6 +436,7 @@
     new = push_array(sconf->rewritemaps);
 
     new->name = a1;
+    new->func = NULL;
     if (strncmp(a2, "txt:", 4) == 0) {
         new->type      = MAPTYPE_TXT;
         new->datafile  = a2+4;
@@ -455,6 +457,18 @@
         new->datafile = a2+4;
         new->checkfile = a2+4;
     }
+    else if (strncmp(a2, "int:", 4) == 0) {
+        new->type      = MAPTYPE_INT;
+        new->datafile  = NULL;
+        new->checkfile = NULL;
+        if (strcmp(a2+4, "tolower") == 0) 
+            new->func = rewrite_mapfunc_tolower;
+        else if (strcmp(a2+4, "toupper") == 0)
+            new->func = rewrite_mapfunc_toupper;
+        else if (sconf->state == ENGINE_ENABLED)
+            return pstrcat(cmd->pool, "RewriteMap: internal map not found:",
+                           a2+4, NULL);     
+    }
     else {
         new->type      = MAPTYPE_TXT;
         new->datafile  = a2;
@@ -2499,6 +2513,17 @@
                                s->name, key);
                 }
             }
+            else if (s->type == MAPTYPE_INT) {
+                if ((value = lookup_map_internal(r, s->func, key)) != NULL) {
+                    rewritelog(r, 5, "map lookup OK: map=%s key=%s -> val=%s", 
+                               s->name, key, value);
+                    return value;
+                }
+                else {
+                    rewritelog(r, 5, "map lookup FAILED: map=%s key=%s", 
+                               s->name, key);
+                }
+           }
         }
     }
     return NULL;
@@ -2605,8 +2630,32 @@
         return pstrdup(r->pool, buf);
 }
 
+static char *lookup_map_internal(request_rec *r,
+                                 char *(*func)(request_rec *, char *),
+                                 char *key)
+{
+    /* currently we just let the function convert 
+       the key to a corresponding value */
+    return func(r, key);
+}
+
+static char *rewrite_mapfunc_toupper(request_rec *r, char *key)
+{
+    char *value, *cp;
 
+    for (cp = value = pstrdup(r->pool, key); cp != NULL && *cp != '\0'; cp++)
+        *cp = toupper(*cp);
+    return value;
+}
 
+static char *rewrite_mapfunc_tolower(request_rec *r, char *key)
+{
+    char *value, *cp;
+
+    for (cp = value = pstrdup(r->pool, key); cp != NULL && *cp != '\0'; cp++)
+        *cp = tolower(*cp);
+    return value;
+}
 
 /*
 ** +-------------------------------------------------------+

Mime
View raw message