apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Holsman <i...@cnet.com>
Subject Mutli-DBM patch
Date Tue, 27 Nov 2001 23:47:29 GMT
(inline as well as attached)
This is my first foray into AutoConf.. so this is why I'm posting the patch
it defines there new #defines APU_HAVE_XDBM.
there is also a new dbm open function _open_ex(...) to specify the DBM
later all also add a specific open call for each DBM 

So .. please comment..
..Ian

Index: build/apu-conf.m4
===================================================================
RCS file: /home/cvspublic/apr-util/build/apu-conf.m4,v
retrieving revision 1.15
diff -u -r1.15 apu-conf.m4
--- build/apu-conf.m4	2001/11/11 07:46:28	1.15
+++ build/apu-conf.m4	2001/11/27 23:27:50
@@ -61,11 +61,11 @@
 dnl
 dnl APU_CHECK_DB1: is DB1 present?
 dnl
-dnl if present: sets apu_use_db=1, db_header, and db_lib
+dnl if present: sets apu_have_db=1, db_header, and db_lib
 dnl
 AC_DEFUN(APU_CHECK_DB1,[
 AC_CHECK_HEADER(db1/db.h, [
-  apu_use_db=1
+  apu_have_db=1
   db_header=db1/db.h
   db_lib=db1
   ])
@@ -74,11 +74,11 @@
 dnl
 dnl APU_CHECK_DB185: is DB1.85 present?
 dnl
-dnl if present: sets apu_use_db=1, db_header, and db_lib
+dnl if present: sets apu_have_db=1, db_header, and db_lib
 dnl
 AC_DEFUN(APU_CHECK_DB185,[
 AC_CHECK_HEADER(db_185.h, [
-  apu_use_db=1
+  apu_have_db=1
   db_header=db_185.h
   db_lib=db1
   ])
@@ -87,11 +87,11 @@
 dnl
 dnl APU_CHECK_DB2or3: are DB2 or DB3 present?
 dnl
-dnl if present: sets apu_use_db=1, db_header, and db_lib
+dnl if present: sets apu_have_db=1, db_header, and db_lib
 dnl
 AC_DEFUN(APU_CHECK_DB2or3,[
 AC_CHECK_HEADER(db.h, [
-  apu_use_db=1
+  apu_have_db=1
   db_header=db.h
   db_lib=db
   ])
@@ -126,16 +126,16 @@
 dnl
 AC_DEFUN(APU_FIND_DB,[
   APU_CHECK_DB2or3
-  if test $apu_use_db = 1; then
+  if test $apu_have_db = 1; then
     APU_CHECK_DB_VSN
     which_dbm="db$db_version"
   else
     APU_CHECK_DB1
-    if test $apu_use_db = 1; then
+    if test $apu_have_db = 1; then
       which_dbm="db1"
     else
       APU_CHECK_DB185
-      if test $apu_use_db = 1; then
+      if test $apu_have_db = 1; then
         which_dbm="db185"
       fi
     fi
@@ -150,6 +150,11 @@
 apu_use_sdbm=0
 apu_use_gdbm=0
 apu_use_db=0
+dnl it's in our codebase
+apu_have_sdbm=1
+apu_have_gdbm=0
+apu_have_db=0
+
 db_header=db.h		# default so apu_select_dbm.h is syntactically correct
 
 AC_ARG_WITH(dbm,
@@ -164,6 +169,14 @@
   look_for=default
 ])
 
+AC_CHECK_LIB( gdbm, gdbm_open, 
+    [ AC_CHECK_HEADER( gdbm.h, 
+        apu_have_gdbm=1,
+        apu_have_gdbm=0)],
+      AC_MSG_WARN( "gdbm DBM not found"),)
+
+APU_FIND_DB
+
 case "$look_for" in
   sdbm)
     apu_use_sdbm=1
@@ -174,29 +187,34 @@
     which_dbm=gdbm
     ;;
   db)
-    APU_FIND_DB
-    if test -n "$which_dbm"; then
-      # pretend we were looking for this one
-      look_for=$which_dbm
+    if test $apu_have_db = 1; then
+      apu_use_db=1
+      which_dbm=db
     else
-      look_errmsg="could not find a DB header"
+     look_errmsg="couldn't find berkley DB"
     fi
     ;;
   db1)
+    apu_have_db=0
     APU_CHECK_DB1
-    if test $apu_use_db = 1; then
+    if test $apu_have_db = 1; then
       which_dbm=db1
+      apu_use_db=1
     fi
     ;;
   db185)
+    apu_have_db=0
     APU_CHECK_DB185
-    if test $apu_use_db = 1; then
+    if test $apu_have_db = 1; then
       which_dbm=db185
+      apu_use_db=1
     fi
     ;;
   db2)
+    apu_have_db=0
     APU_CHECK_DB2or3
-    if test $apu_use_db = 1; then
+    if test $apu_have_db = 1; then
+      apu_use_db=1
       APU_CHECK_DB_VSN
       if test "$db_version" = 2; then
         which_dbm=db2
@@ -206,8 +224,10 @@
     fi
     ;;
   db3)
+    apu_have_db=0
     APU_CHECK_DB2or3
-    if test $apu_use_db = 1; then
+    if test $apu_have_db = 1; then
+      apu_use_db=1
       APU_CHECK_DB_VSN
       if test "$db_version" = 3; then
         which_dbm=db3
@@ -241,12 +261,14 @@
 AC_SUBST(apu_use_sdbm)
 AC_SUBST(apu_use_gdbm)
 AC_SUBST(apu_use_db)
-AC_SUBST(db_header)
 
-DBM_OBJECT_FILE=apr_dbm_sdbm.lo
+AC_SUBST(apu_have_sdbm)
+AC_SUBST(apu_have_gdbm)
+AC_SUBST(apu_have_db)
+AC_SUBST(db_header)
+AC_SUBST(db_version)
 
-if test $apu_use_gdbm = 1; then
-  DBM_OBJECT_FILE=apr_dbm_gdbm.lo
+if test $apu_have_gdbm = 1; then
   lib_save="$LIBS"
   LIBS=""
   AC_CHECK_LIB(gdbm, gdbm_open)
@@ -255,14 +277,10 @@
 fi
 
 if test $apu_use_db = 1; then
-  DBM_OBJECT_FILE=apr_dbm_berkeleydb.lo
   dnl ### use AC_CHECK_LIB?
   LIBS="$LIBS -l$db_lib"
   APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS -l$db_lib"
 fi
-
-dnl build and link this object into apr_dbm
-AC_SUBST(DBM_OBJECT_FILE)
 
 ])
 
Index: dbm/Makefile.in
===================================================================
RCS file: /home/cvspublic/apr-util/dbm/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- dbm/Makefile.in	2001/11/11 07:46:28	1.7
+++ dbm/Makefile.in	2001/11/27 23:27:50
@@ -1,7 +1,7 @@
 top_builddir=@top_builddir@
 INCLUDES=-I$(top_builddir)/include -I$(top_builddir)/include/private -I$(top_builddir)/../apr/include
-I$(srcdir)../../apr/include -I$(srcdir)../include -I$(srcdir)../include/private
 
-TARGETS = apr_dbm.lo @DBM_OBJECT_FILE@
+TARGETS = apr_dbm.lo apr_dbm_berkeleydb.lo apr_dbm_gdbm.lo apr_dbm_sdbm.lo
 
 # bring in rules.mk for standard functionality
 @INCLUDE_RULES@
Index: dbm/apr_dbm.c
===================================================================
RCS file: /home/cvspublic/apr-util/dbm/apr_dbm.c,v
retrieving revision 1.33
diff -u -r1.33 apr_dbm.c
--- dbm/apr_dbm.c	2001/11/11 07:46:28	1.33
+++ dbm/apr_dbm.c	2001/11/27 23:27:50
@@ -84,14 +84,38 @@
 #endif
 

+APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **pdb, const char*type, 
+                                       const char *pathname, 
+                                       apr_int32_t mode, apr_fileperms_t perm,
+                                       apr_pool_t *pool)
+{
+#if APU_HAVE_GDBM
+    if (!strcasecmp(type, "GDBM")) {
+        return (*apr_dbm_type_gdbm.open)(pdb, pathname, mode, perm, pool);
+    }
+#endif
 
+#if APU_HAVE_SDBM
+    if (!strcasecmp(type, "SDBM")) {
+        return (*apr_dbm_type_sdbm.open)(pdb, pathname, mode, perm, pool);
+    }
+#endif
+#if APU_HAVE_DB
+    if (!strcasecmp(type, "DB")) {
+        return (*apr_dbm_type_db.open)(pdb, pathname, mode, perm, pool);
+    }
+#endif
+    if (!strcasecmp(type, "default")) {
+        return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
+    }
+
+    return APR_ENOTIMPL;
+} 
+
 APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **pdb, const char *pathname, 
                                        apr_int32_t mode, apr_fileperms_t perm,
                                        apr_pool_t *pool)
 {
-    /* ### one day, a DBM type name will be passed and we'll need to look it
-       ### up. for now, it is constant. */
-
     return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
 }
 
Index: dbm/apr_dbm_berkeleydb.c
===================================================================
RCS file: /home/cvspublic/apr-util/dbm/apr_dbm_berkeleydb.c,v
retrieving revision 1.6
diff -u -r1.6 apr_dbm_berkeleydb.c
--- dbm/apr_dbm_berkeleydb.c	2001/11/11 07:46:28	1.6
+++ dbm/apr_dbm_berkeleydb.c	2001/11/27 23:27:50
@@ -60,9 +60,14 @@
 #include <stdlib.h> /* for abort() */
 #endif
 
+#include "apu_select_dbm.h"
+
+#if APU_HAVE_DB 
+
 #include "apr_dbm_private.h"
 

+
 /* this is used in a few places to define a noop "function". it is needed
    to stop "no effect" warnings from GCC. */
 #define NOOP_FUNCTION if (0) ; else
@@ -430,3 +435,5 @@
     vt_db_freedatum,
     vt_db_usednames
 };
+
+#endif /* APU_HAVE_DB */
Index: dbm/apr_dbm_gdbm.c
===================================================================
RCS file: /home/cvspublic/apr-util/dbm/apr_dbm_gdbm.c,v
retrieving revision 1.6
diff -u -r1.6 apr_dbm_gdbm.c
--- dbm/apr_dbm_gdbm.c	2001/11/11 07:46:28	1.6
+++ dbm/apr_dbm_gdbm.c	2001/11/27 23:27:50
@@ -58,6 +58,10 @@
 #include <stdlib.h>     /* for free() */
 #endif
 
+#include "apu_select_dbm.h"
+
+#if APU_HAVE_GDBM 
+
 #include "apr_dbm_private.h"
 
 #include <gdbm.h>
@@ -303,3 +307,5 @@
     vt_gdbm_freedatum,
     vt_gdbm_usednames
 };
+
+#endif /* APU_HAVE_GDBM */
Index: dbm/apr_dbm_sdbm.c
===================================================================
RCS file: /home/cvspublic/apr-util/dbm/apr_dbm_sdbm.c,v
retrieving revision 1.5
diff -u -r1.5 apr_dbm_sdbm.c
--- dbm/apr_dbm_sdbm.c	2001/11/11 07:46:28	1.5
+++ dbm/apr_dbm_sdbm.c	2001/11/27 23:27:50
@@ -57,6 +57,10 @@
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
 
+#include "apu_select_dbm.h"
+
+#if APU_HAVE_SDBM
+
 #include "apr_dbm_private.h"
 
 #include "apr_sdbm.h"
@@ -293,3 +297,5 @@
     vt_sdbm_freedatum,
     vt_sdbm_usednames
 };
+
+#endif /* APU_HAVE_SDBM */
Index: include/apr_dbm.h
===================================================================
RCS file: /home/cvspublic/apr-util/include/apr_dbm.h,v
retrieving revision 1.13
diff -u -r1.13 apr_dbm.h
--- include/apr_dbm.h	2001/09/27 17:12:07	1.13
+++ include/apr_dbm.h	2001/11/27 23:27:50
@@ -96,6 +96,36 @@
 #define APR_DBM_RWCREATE        3       /**< open for r/w, create if needed */
 #define APR_DBM_RWTRUNC         4       /**< open for r/w, truncating a existing
                                           DB if present */
+/**
+ * Open a dbm file by file name and type of DBM
+ * @param dbm The newly opened database
+ * @param type The type of the DBM (not all may be available at run time)
+ * <pre>
+ *  GDBM for GDBM files
+ *  SDBM for SDBM files
+ *  DB   for berkeley DB files
+ *  default for the default DBM type
+ *  </pre>
+ * @param name The dbm file name to open
+ * @param mode The flag value
+ * <PRE>
+ *           APR_DBM_READONLY   open for read-only access
+ *           APR_DBM_READWRITE  open for read-write access
+ *           APR_DBM_RWCREATE   open for r/w, create if needed
+ *           APR_DBM_RWTRUNC    open for r/w, truncatate if already there
+ * </PRE>
+ * @param perm Permissions to apply to if created
+ * @param cntxt The pool to use when creating the dbm
+ * @deffunc apr_status_t apr_dbm_open(apr_dbm_t **dbm, const char *name, int mode
+ * @tip The dbm name may not be a true file name, as many dbm packages
+ * append suffixes for seperate data and index files.
+ */
+
+APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **dbm, const char* type, 
+                                       const char *name, 
+                                       apr_int32_t mode, apr_fileperms_t perm,
+                                       apr_pool_t *cntxt);
+
 
 /**
  * Open a dbm file by file name
Index: include/private/apu_select_dbm.h.in
===================================================================
RCS file: /home/cvspublic/apr-util/include/private/apu_select_dbm.h.in,v
retrieving revision 1.2
diff -u -r1.2 apu_select_dbm.h.in
--- include/private/apu_select_dbm.h.in	2001/02/16 04:17:11	1.2
+++ include/private/apu_select_dbm.h.in	2001/11/27 23:27:50
@@ -62,7 +62,15 @@
 #define APU_USE_GDBM	@apu_use_gdbm@
 #define APU_USE_DB	@apu_use_db@
 
-#if APU_USE_DB
+/*
+ * we always have SDBM (it's in our codebase)
+ */
+#define APU_HAVE_SDBM   @apu_have_sdbm@
+#define APU_HAVE_GDBM   @apu_have_gdbm@
+#define APU_HAVE_DB     @apu_have_db@
+
+#if APU_HAVE_DB
+/* found version @db_version@ */
 #include <@db_header@>
 #endif
 
Index: test/testdbm.c
===================================================================
RCS file: /home/cvspublic/apr-util/test/testdbm.c,v
retrieving revision 1.11
diff -u -r1.11 testdbm.c
--- test/testdbm.c	2001/09/27 17:12:07	1.11
+++ test/testdbm.c	2001/11/27 23:27:50
@@ -77,7 +77,7 @@
 
 static const char *progname;
 static int rflag;
-static const char *usage = "%s [-R] cat | look |... dbmname";
+static const char *usage = "%s [-t DBMtype] [-R] cat | look |... dbmname";
 
 #define DERROR      0
 #define DLOOK       1
@@ -125,7 +125,7 @@
 
 #define CTABSIZ (sizeof (cmds)/sizeof (cmd))
 
-static void doit(const cmd *act, const char *file, apr_pool_t *pool);
+static void doit(const cmd *act, const char*type, const char *file, apr_pool_t *pool);
 static void badk(const char *word);
 static const cmd *parse(const char *str);
 static void prdatum(FILE *stream, apr_datum_t d);
@@ -140,6 +140,7 @@
     apr_getopt_t *os;
     char optch;
     const char *optarg;
+    const char*dbtype;
 
     (void) apr_initialize();
     apr_pool_create(&pool, NULL);
@@ -148,13 +149,17 @@
     (void) apr_getopt_init(&os, pool, argc, argv);
 
     progname = argv[0];
+    dbtype = "default";
 
-    while (apr_getopt(os, "R", &optch, &optarg) == APR_SUCCESS)
+    while (apr_getopt(os, "Rt:", &optch, &optarg) == APR_SUCCESS)
         switch (optch) {
         case 'R':       /* raw processing  */
             rflag++;
             break;
 
+        case 't':
+            dbtype=optarg;
+            break;
         default:
             oops(NULL, APR_EGENERAL, "(unknown option) usage: %s", usage);
             break;
@@ -166,14 +171,14 @@
     if ((act = parse(argv[os->ind])) == NULL)
         badk(argv[os->ind]);
     os->ind++;
-    doit(act, argv[os->ind], pool);
+    doit(act, dbtype, argv[os->ind], pool);
 
     apr_pool_destroy(pool);
 
     return 0;
 }
 
-static void doit(const cmd *act, const char *file, apr_pool_t *pool)
+static void doit(const cmd *act, const char*type, const char *file, apr_pool_t *pool)
 {
     apr_status_t rv;
     apr_datum_t key;
@@ -189,7 +194,7 @@
     extern long time();
 #endif
 
-    rv = apr_dbm_open(&db, file, act->flags, APR_OS_DEFAULT, pool);
+    rv = apr_dbm_open_ex(&db, type, file, act->flags, APR_OS_DEFAULT, pool);
     if (rv != APR_SUCCESS)
         oops(db, rv, "cannot open: %s", file);
 
-- 
Ian Holsman          IanH@cnet.com
Performance Measurement & Analysis
CNET Networks   -   (415) 344-2608

Mime
View raw message