ianh 01/11/28 09:34:18
Modified: . CHANGES
build apu-conf.m4
dbm Makefile.in apr_dbm.c apr_dbm_berkeleydb.c
apr_dbm_gdbm.c apr_dbm_sdbm.c
include apr_dbm.h apu.h.in apu.hw
include/private apu_select_dbm.h.in
test testdbm.c
Log:
Multi DBM support
2 new functions
apr_dbm_open_ex
apr_dbm_get_usednames_ex
Revision Changes Path
1.39 +2 -0 apr-util/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr-util/CHANGES,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- CHANGES 2001/11/21 17:00:51 1.38
+++ CHANGES 2001/11/28 17:34:17 1.39
@@ -1,4 +1,6 @@
Changes with APR-util b1
+ *) Multi-DBM support (via apr_dbm_open_ex [Ian Holsman])
+
*) Use apr_mmap_dup in MMap Bucket [Brian Pane <[EMAIL PROTECTED]>]
*) Dropped the "w" parameter from apr_bucket_heap_create() and
1.16 +45 -27 apr-util/build/apu-conf.m4
Index: apu-conf.m4
===================================================================
RCS file: /home/cvs/apr-util/build/apu-conf.m4,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- apu-conf.m4 2001/11/11 07:46:28 1.15
+++ apu-conf.m4 2001/11/28 17:34:17 1.16
@@ -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)
@@ -254,15 +276,11 @@
LIBS="$lib_save $LIBS"
fi
-if test $apu_use_db = 1; then
- DBM_OBJECT_FILE=apr_dbm_berkeleydb.lo
+if test $apu_have_db = 1; then
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)
])
1.8 +1 -1 apr-util/dbm/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr-util/dbm/Makefile.in,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Makefile.in 2001/11/11 07:46:28 1.7
+++ Makefile.in 2001/11/28 17:34:17 1.8
@@ -1,7 +1,7 @@
[EMAIL PROTECTED]@
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@
1.34 +58 -3 apr-util/dbm/apr_dbm.c
Index: apr_dbm.c
===================================================================
RCS file: /home/cvs/apr-util/dbm/apr_dbm.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- apr_dbm.c 2001/11/11 07:46:28 1.33
+++ apr_dbm.c 2001/11/28 17:34:17 1.34
@@ -60,6 +60,7 @@
#define APR_WANT_STRFUNC
#include "apr_want.h"
+#include "apu.h"
#include "apu_select_dbm.h"
#include "apr_dbm.h"
#include "apr_dbm_private.h"
@@ -84,14 +85,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);
}
@@ -151,6 +176,36 @@
(void) apr_cpystrn(errbuf, dbm->errmsg, errbufsize);
return errbuf;
}
+APU_DECLARE(void) apr_dbm_get_usednames_ex(apr_pool_t *p,
+ const char*type,
+ const char *pathname,
+ const char **used1,
+ const char **used2)
+{
+#if APU_HAVE_GDBM
+ if (!strcasecmp(type, "GDBM")) {
+ (*apr_dbm_type_gdbm.getusednames)(p,pathname,used1,used2);
+ return;
+ }
+#endif
+
+#if APU_HAVE_SDBM
+ if (!strcasecmp(type, "SDBM")) {
+ (*apr_dbm_type_sdbm.getusednames)(p,pathname,used1,used2);
+ return;
+ }
+#endif
+#if APU_HAVE_DB
+ if (!strcasecmp(type, "DB")) {
+ (*apr_dbm_type_db.getusednames)(p,pathname,used1,used2);
+ return;
+ }
+#endif
+ if (!strcasecmp(type, "default")) {
+ (*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
+ return;
+ }
+}
APU_DECLARE(void) apr_dbm_get_usednames(apr_pool_t *p,
const char *pathname,
1.7 +7 -0 apr-util/dbm/apr_dbm_berkeleydb.c
Index: apr_dbm_berkeleydb.c
===================================================================
RCS file: /home/cvs/apr-util/dbm/apr_dbm_berkeleydb.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apr_dbm_berkeleydb.c 2001/11/11 07:46:28 1.6
+++ apr_dbm_berkeleydb.c 2001/11/28 17:34:17 1.7
@@ -60,9 +60,14 @@
#include <stdlib.h> /* for abort() */
#endif
+#include "apu.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 */
1.7 +6 -0 apr-util/dbm/apr_dbm_gdbm.c
Index: apr_dbm_gdbm.c
===================================================================
RCS file: /home/cvs/apr-util/dbm/apr_dbm_gdbm.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apr_dbm_gdbm.c 2001/11/11 07:46:28 1.6
+++ apr_dbm_gdbm.c 2001/11/28 17:34:17 1.7
@@ -58,6 +58,10 @@
#include <stdlib.h> /* for free() */
#endif
+#include "apu.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 */
1.6 +6 -0 apr-util/dbm/apr_dbm_sdbm.c
Index: apr_dbm_sdbm.c
===================================================================
RCS file: /home/cvs/apr-util/dbm/apr_dbm_sdbm.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apr_dbm_sdbm.c 2001/11/11 07:46:28 1.5
+++ apr_dbm_sdbm.c 2001/11/28 17:34:17 1.6
@@ -57,6 +57,10 @@
#define APR_WANT_STRFUNC
#include "apr_want.h"
+#include "apu.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 */
1.14 +48 -0 apr-util/include/apr_dbm.h
Index: apr_dbm.h
===================================================================
RCS file: /home/cvs/apr-util/include/apr_dbm.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- apr_dbm.h 2001/09/27 17:12:07 1.13
+++ apr_dbm.h 2001/11/28 17:34:18 1.14
@@ -96,7 +96,37 @@
#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
* @param dbm The newly opened database
@@ -197,6 +227,24 @@
*/
APU_DECLARE(char *) apr_dbm_geterror(apr_dbm_t *dbm, int *errcode,
char *errbuf, apr_size_t errbufsize);
+/**
+ * If the specified file/path were passed to apr_dbm_open(), return the
+ * actual file/path names which would be (created and) used. At most, two
+ * files may be used; used2 may be NULL if only one file is used.
+ * @param pool The pool for allocating used1 and used2.
+ * @param type The type of DBM you require info on
+ * @param pathname The path name to generate used-names from.
+ * @param used1 The first pathname used by the apr_dbm implementation.
+ * @param used2 The second pathname used by apr_dbm. If only one file is
+ * used by the specific implementation, this will be set to
NULL.
+ * @tip The dbm file(s) don't need to exist. This function only manipulates
+ * the pathnames.
+ */
+APU_DECLARE(void) apr_dbm_get_usednames_ex(apr_pool_t *pool,
+ const char *type,
+ const char *pathname,
+ const char **used1,
+ const char **used2);
/**
* If the specified file/path were passed to apr_dbm_open(), return the
1.9 +12 -0 apr-util/include/apu.h.in
Index: apu.h.in
===================================================================
RCS file: /home/cvs/apr-util/include/apu.h.in,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apu.h.in 2001/09/09 05:54:35 1.8
+++ apu.h.in 2001/11/28 17:34:18 1.9
@@ -108,6 +108,18 @@
* declarations within headers to properly import the variable.
*/
#define APU_DECLARE_DATA
+/*
+ * 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
+
#endif /* APU_H */
/** @} */
1.5 +12 -0 apr-util/include/apu.hw
Index: apu.hw
===================================================================
RCS file: /home/cvs/apr-util/include/apu.hw,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- apu.hw 2001/09/09 05:54:35 1.4
+++ apu.hw 2001/11/28 17:34:18 1.5
@@ -139,6 +139,18 @@
#define APU_DECLARE_DATA __declspec(dllimport)
#endif
/** @} */
+/*
+ * we always have SDBM (it's in our codebase)
+ */
+#define APU_HAVE_SDBM 1
+#define APU_HAVE_GDBM 0
+#define APU_HAVE_DB 0
+
+#if APU_HAVE_DB
+/* win32 note.. you will need to change this for db1 */
+#include <db.h>
+#endif
+
#endif /* APU_H */
#endif /* WIN32 */
1.3 +0 -4 apr-util/include/private/apu_select_dbm.h.in
Index: apu_select_dbm.h.in
===================================================================
RCS file: /home/cvs/apr-util/include/private/apu_select_dbm.h.in,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- apu_select_dbm.h.in 2001/02/16 04:17:11 1.2
+++ apu_select_dbm.h.in 2001/11/28 17:34:18 1.3
@@ -62,8 +62,4 @@
#define APU_USE_GDBM @apu_use_gdbm@
#define APU_USE_DB @apu_use_db@
-#if APU_USE_DB
-#include <@db_header@>
-#endif
-
#endif /* !APU_SELECT_DBM_H */
1.12 +11 -6 apr-util/test/testdbm.c
Index: testdbm.c
===================================================================
RCS file: /home/cvs/apr-util/test/testdbm.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- testdbm.c 2001/09/27 17:12:07 1.11
+++ testdbm.c 2001/11/28 17:34:18 1.12
@@ -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);