]> granicus.if.org Git - apache/commitdiff
add the ability to specify the dbm type (e.g., gdbm, ndbm) for
authorJeff Trawick <trawick@apache.org>
Fri, 23 Aug 2002 12:49:08 +0000 (12:49 +0000)
committerJeff Trawick <trawick@apache.org>
Fri, 23 Aug 2002 12:49:08 +0000 (12:49 +0000)
dbm rewrite maps

use dbm:filename for the default type

use dbm=TYPE:filename for a non-default type

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96493 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/mappers/mod_rewrite.c
modules/mappers/mod_rewrite.h

diff --git a/CHANGES b/CHANGES
index d1ed37e6780898bcf7a40f4162205458b386f944..b9905b6f7d177fb70dda94649b1c6d849d45b09d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,7 +1,8 @@
 Changes with Apache 2.0.41
 
   *) Change mod_rewrite to use apr-util's dbm support for dbm rewrite
-     maps.  PR 10644  [Jeff Trawick]
+     maps.  The dbm type (e.g., ndbm, gdbm) can be specified on the
+     RewriteMap directive.  PR 10644  [Jeff Trawick]
 
   *) Fixed mod_rewrite's RewriteMap prg: support so that request/response
      pairs will no longer get out of sync with each other.  PR 9534
index 9363e5651c5d130d70ad83d2cc8902b023c6b942..e246df85bca5640867a688f5d82b938d6269deb3 100644 (file)
 #include "unixd.h"
 #endif
 
-#define DBM_MAP_TYPE "SDBM"
-
 /*
 ** +-------------------------------------------------------+
 ** |                                                       |
@@ -428,13 +426,41 @@ static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, const char *a1,
         newmap->datafile  = a2+4;
         newmap->checkfile = a2+4;
     }
-    else if (strncmp(a2, "dbm:", 4) == 0) {
+    else if (strncmp(a2, "dbm", 3) == 0) {
         const char *ignored_fname;
+        int bad = 0;
+        apr_status_t rv;
 
-        newmap->type      = MAPTYPE_DBM;
-        newmap->datafile  = a2+4;
-        apr_dbm_get_usednames_ex(cmd->pool, DBM_MAP_TYPE, newmap->datafile, 
-                                 &newmap->checkfile, &ignored_fname);
+        if (a2[3] == ':') {
+            newmap->dbmtype    = "default";
+            newmap->datafile   = a2+4;
+        }
+        else if (a2[3] == '=') {
+            const char *colon = ap_strchr_c(a2 + 4, ':');
+            
+            if (colon) {
+                newmap->dbmtype = apr_pstrndup(cmd->pool, a2 + 4, colon - (a2 + 3) - 1);
+                newmap->datafile = colon + 1;
+            }
+            else {
+                ++bad;
+            }
+        }
+        else {
+            ++bad;
+        }
+
+        if (bad) {
+            return apr_pstrcat(cmd->pool, "RewriteMap: bad map:",
+                               a2, NULL);
+        }
+    
+        rv = apr_dbm_get_usednames_ex(cmd->pool, newmap->dbmtype, newmap->datafile,
+                                      &newmap->checkfile, &ignored_fname);
+        if (rv != APR_SUCCESS) {
+            return apr_pstrcat(cmd->pool, "RewriteMap: dbm type ", newmap->dbmtype,
+                               " is invalid", NULL);
+        }
     }
     else if (strncmp(a2, "prg:", 4) == 0) {
         newmap->type      = MAPTYPE_PRG;
@@ -466,8 +492,8 @@ static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, const char *a1,
         && (apr_stat(&st, newmap->checkfile, APR_FINFO_MIN, 
                      cmd->pool) != APR_SUCCESS)) {
         return apr_pstrcat(cmd->pool,
-                          "RewriteMap: map file not found:",
-                          newmap->checkfile, NULL);
+                          "RewriteMap: file for map ", newmap->name,
+                           " not found:", newmap->checkfile, NULL);
     }
 
     return NULL;
@@ -2787,7 +2813,7 @@ static char *lookup_map(request_rec *r, char *name, char *key)
                     rewritelog(r, 6,
                                "cache lookup FAILED, forcing new map lookup");
                     if ((value =
-                         lookup_map_dbmfile(r, s->datafile, key)) != NULL) {
+                         lookup_map_dbmfile(r, s->datafile, s->dbmtype, key)) != NULL) {
                         rewritelog(r, 5, "map lookup OK: map=%s[dbm] key=%s "
                                    "-> val=%s", s->name, key, value);
                         set_cache_string(cachep, s->name, CACHEMODE_TS,
@@ -2925,7 +2951,8 @@ static char *lookup_map_txtfile(request_rec *r, const char *file, char *key)
     return value;
 }
 
-static char *lookup_map_dbmfile(request_rec *r, const char *file, char *key)
+static char *lookup_map_dbmfile(request_rec *r, const char *file, 
+                                const char *dbmtype, char *key)
 {
     apr_dbm_t *dbmfp = NULL;
     apr_datum_t dbmkey;
@@ -2936,7 +2963,7 @@ static char *lookup_map_dbmfile(request_rec *r, const char *file, char *key)
 
     dbmkey.dptr  = key;
     dbmkey.dsize = strlen(key);
-    if ((rv = apr_dbm_open_ex(&dbmfp, DBM_MAP_TYPE, file, APR_DBM_READONLY, 
+    if ((rv = apr_dbm_open_ex(&dbmfp, dbmtype, file, APR_DBM_READONLY, 
                               0 /* irrelevant when reading */, r->pool)) == APR_SUCCESS) {
         rv = apr_dbm_fetch(dbmfp, dbmkey, &dbmval);
         if (rv == APR_SUCCESS) {
index 0f173beea389bc40f776155985e9a155fcd20b63..7ca91f3661b0971617bbee0d85ea142ac69dbcad 100644 (file)
 typedef struct {
     const char *name;              /* the name of the map */
     const char *datafile;          /* filename for map data files */
+    const char *dbmtype;           /* dbm type for dbm map data files */
     const char *checkfile;         /* filename to check for map existence */
     int   type;                    /* the type of the map */
     apr_file_t *fpin;               /* in  file pointer for program maps */
@@ -408,7 +409,8 @@ static char *expand_tildepaths(request_rec *r, char *uri);
     /* rewrite map support functions */
 static char *lookup_map(request_rec *r, char *name, char *key);
 static char *lookup_map_txtfile(request_rec *r, const char *file, char *key);
-static char *lookup_map_dbmfile(request_rec *r, const char *file, char *key);
+static char *lookup_map_dbmfile(request_rec *r, const char *file, 
+                                const char *dbmtype, char *key);
 static char *lookup_map_program(request_rec *r, apr_file_t *fpin,
                                 apr_file_t *fpout, char *key);