gstein 01/11/10 23:46:29
Modified: build apu-conf.m4
dbm Makefile.in apr_dbm.c apr_dbm_berkeleydb.c
apr_dbm_gdbm.c apr_dbm_sdbm.c
include/private apr_dbm_private.h
Log:
* Copy a lot of code unchanged from apr_dbm.c to apr_dbm_*.c. Changes
occurred:
- open() and exists() split the #if logic out to the three files
- vt_db_fetch() had minor changes related to the 'rd' variable
- the various exists() functions were tweaked
* the geterror() was eliminated as apr_dbm.c can handle it
* Jeff Trawick's comments re: static vs APU_DECLARE_DATA for the
vtables.
* apu_conf.m4, dbm/Makefile.in: build/link in the appropriate dbm file
(until we start buildig/linking all of them)
Revision Changes Path
1.15 +7 -0 apr-util/build/apu-conf.m4
Index: apu-conf.m4
===================================================================
RCS file: /home/cvs/apr-util/build/apu-conf.m4,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- apu-conf.m4 2001/08/21 18:44:26 1.14
+++ apu-conf.m4 2001/11/11 07:46:28 1.15
@@ -243,7 +243,10 @@
AC_SUBST(apu_use_db)
AC_SUBST(db_header)
+DBM_OBJECT_FILE=apr_dbm_sdbm.lo
+
if test $apu_use_gdbm = 1; then
+ DBM_OBJECT_FILE=apr_dbm_gdbm.lo
lib_save="$LIBS"
LIBS=""
AC_CHECK_LIB(gdbm, gdbm_open)
@@ -252,10 +255,14 @@
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)
])
1.7 +1 -1 apr-util/dbm/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr-util/dbm/Makefile.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile.in 2001/09/13 06:56:54 1.6
+++ Makefile.in 2001/11/11 07:46:28 1.7
@@ -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
+TARGETS = apr_dbm.lo @DBM_OBJECT_FILE@
# bring in rules.mk for standard functionality
@INCLUDE_RULES@
1.33 +12 -184 apr-util/dbm/apr_dbm.c
Index: apr_dbm.c
===================================================================
RCS file: /home/cvs/apr-util/dbm/apr_dbm.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- apr_dbm.c 2001/11/07 14:25:40 1.32
+++ apr_dbm.c 2001/11/11 07:46:28 1.33
@@ -62,33 +62,21 @@
#include "apu_select_dbm.h"
#include "apr_dbm.h"
+#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
-
-/* ### define defaults for now; these will go away in a while */
-#define REGISTER_CLEANUP(dbm, pdatum) NOOP_FUNCTION
-#define SET_FILE(pdb, f) ((pdb)->file = (f))
-
-
/* ### note: the setting of DBM_VTABLE will go away once we have multiple
### DBMs in here. */
#if APU_USE_SDBM
-#include "apr_dbm_sdbm.c"
#define DBM_VTABLE apr_dbm_type_sdbm
#elif APU_USE_GDBM
-#include "apr_dbm_gdbm.c"
#define DBM_VTABLE apr_dbm_type_gdbm
#elif APU_USE_DB
-#include "apr_dbm_berkeleydb.c"
#define DBM_VTABLE apr_dbm_type_db
#else /* Not in the USE_xDBM list above */
@@ -101,91 +89,10 @@
apr_int32_t mode, apr_fileperms_t
perm,
apr_pool_t *pool)
{
- real_file_t file;
- int dbmode;
-
- *pdb = NULL;
-
- switch (mode) {
- case APR_DBM_READONLY:
- dbmode = APR_DBM_DBMODE_RO;
- break;
- case APR_DBM_READWRITE:
- dbmode = APR_DBM_DBMODE_RW;
- break;
- case APR_DBM_RWCREATE:
- dbmode = APR_DBM_DBMODE_RWCREATE;
- break;
- case APR_DBM_RWTRUNC:
- dbmode = APR_DBM_DBMODE_RWTRUNC;
- break;
- default:
- return APR_EINVAL;
- }
-
-#if APU_USE_SDBM
-
- {
- apr_status_t rv;
-
- rv = apr_sdbm_open(&file, pathname, dbmode, perm, pool);
- if (rv != APR_SUCCESS)
- return rv;
- }
-
-#elif APU_USE_GDBM
-
- {
- /* Note: stupid cast to get rid of "const" on the pathname */
- file = gdbm_open((char *) pathname, 0, dbmode,
- apr_posix_perms2mode(perm), NULL);
- if (file == NULL)
- return APR_EGENERAL; /* ### need a better error */
- }
-
-#elif APU_USE_DB
-
- {
- int dberr;
-
-#if DB_VER == 3
- if ((dberr = db_create(&file.bdb, NULL, 0)) == 0) {
- if ((dberr = (*file.bdb->open)(file.bdb, pathname, NULL,
- DB_HASH, dbmode,
- apr_posix_perms2mode(perm))) !=
0) {
- /* close the DB handler */
- (void) (*file.bdb->close)(file.bdb, 0);
- }
- }
- file.curs = NULL;
-#elif DB_VER == 2
- dberr = db_open(pathname, DB_HASH, dbmode,
apr_posix_perms2mode(perm),
- NULL, NULL, &file.bdb);
- file.curs = NULL;
-#else
- file.bdb = dbopen(pathname, dbmode, apr_posix_perms2mode(perm),
- DB_HASH, NULL);
- if (file.bdb == NULL)
- return APR_EGENERAL; /* ### need a better error */
- dberr = 0;
-#endif
- if (dberr != 0)
- return db2s(dberr);
- }
-
-#else
-#error apr_dbm_open has not been coded for this database type
-#endif /* switch on database types */
-
- /* we have an open database... return it */
- *pdb = apr_pcalloc(pool, sizeof(**pdb));
- (*pdb)->pool = pool;
- (*pdb)->type = &DBM_VTABLE;
- SET_FILE(*pdb, file);
-
- /* ### register a cleanup to close the DBM? */
+ /* ### one day, a DBM type name will be passed and we'll need to look it
+ ### up. for now, it is constant. */
- return APR_SUCCESS;
+ return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
}
APU_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm)
@@ -196,112 +103,33 @@
APU_DECLARE(apr_status_t) apr_dbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t *pvalue)
{
- apr_status_t rv;
- cvt_datum_t ckey;
- result_datum_t rd;
-
- CONVERT_DATUM(ckey, &key);
-#if APU_USE_DB
- memset(&rd,0,sizeof(rd));
-#endif
- rv = APR_DBM_FETCH(dbm->file, ckey, rd);
- RETURN_DATUM(pvalue, rd);
-
- REGISTER_CLEANUP(dbm, pvalue);
-
- /* store the error info into DBM, and return a status code. Also, note
- that *pvalue should have been cleared on error. */
- return set_error(dbm, rv);
+ return (*dbm->type->fetch)(dbm, key, pvalue);
}
APU_DECLARE(apr_status_t) apr_dbm_store(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t value)
{
- apr_status_t rv;
- cvt_datum_t ckey;
- cvt_datum_t cvalue;
-
- CONVERT_DATUM(ckey, &key);
- CONVERT_DATUM(cvalue, &value);
- rv = APR_DBM_STORE(dbm->file, ckey, cvalue);
-
- /* store any error info into DBM, and return a status code. */
- return set_error(dbm, rv);
+ return (*dbm->type->store)(dbm, key, value);
}
APU_DECLARE(apr_status_t) apr_dbm_delete(apr_dbm_t *dbm, apr_datum_t key)
{
- apr_status_t rv;
- cvt_datum_t ckey;
-
- CONVERT_DATUM(ckey, &key);
- rv = APR_DBM_DELETE(dbm->file, ckey);
-
- /* store any error info into DBM, and return a status code. */
- return set_error(dbm, rv);
+ return (*dbm->type->del)(dbm, key);
}
APU_DECLARE(int) apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key)
{
- int exists;
- cvt_datum_t ckey;
-
- CONVERT_DATUM(ckey, &key);
-
-#if APU_USE_SDBM
- {
- apr_sdbm_datum_t value;
- if (apr_sdbm_fetch(dbm->file, &value, *ckey) != APR_SUCCESS) {
- exists = 0;
- }
- else
- exists = value.dptr != NULL;
- }
-#elif APU_USE_GDBM
- exists = gdbm_exists(dbm->file, *ckey) != 0;
-#elif APU_USE_DB
- {
- DBT data;
- int dberr = do_fetch(GET_BDB(dbm->file), ckey, data);
-
- /* DB returns DB_NOTFOUND if it doesn't exist. but we want to say
- that *any* error means it doesn't exist. */
- exists = dberr == 0;
- }
-#else
-#error apr_dbm_exists has not been coded for this database type
-#endif
- return exists;
+ return (*dbm->type->exists)(dbm, key);
}
APU_DECLARE(apr_status_t) apr_dbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey)
{
- apr_status_t rv;
- result_datum_t rd;
-
- rv = APR_DBM_FIRSTKEY(dbm->file, rd);
- RETURN_DATUM(pkey, rd);
-
- REGISTER_CLEANUP(dbm, pkey);
-
- /* store any error info into DBM, and return a status code. */
- return set_error(dbm, rv);
+ return (*dbm->type->firstkey)(dbm, pkey);
}
APU_DECLARE(apr_status_t) apr_dbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
{
- apr_status_t rv;
- cvt_datum_t ckey;
- result_datum_t rd;
-
- CONVERT_DATUM(ckey, pkey);
- rv = APR_DBM_NEXTKEY(dbm->file, ckey, rd);
- RETURN_DATUM(pkey, rd);
-
- REGISTER_CLEANUP(dbm, pkey);
-
- /* store any error info into DBM, and return a status code. */
- return set_error(dbm, APR_SUCCESS);
+ return (*dbm->type->nextkey)(dbm, pkey);
}
APU_DECLARE(void) apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
@@ -329,8 +157,8 @@
const char **used1,
const char **used2)
{
- /* ### one day, we will pass in a DBM name and need to look it up.
- ### for now, it is constant. */
+ /* ### one day, a DBM type name will be passed and we'll need to look it
+ ### up. for now, it is constant. */
(*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
}
1.6 +141 -24 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apr_dbm_berkeleydb.c 2001/11/08 19:46:44 1.5
+++ apr_dbm_berkeleydb.c 2001/11/11 07:46:28 1.6
@@ -52,12 +52,25 @@
* <http://www.apache.org/>.
*/
-#include "apr_dbm_private.h"
+#include "apr_strings.h"
+#define APR_WANT_MEMFUNC
+#include "apr_want.h"
#if APR_HAVE_STDLIB_H
#include <stdlib.h> /* for abort() */
#endif
+#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
+
+/* ### define defaults for now; these will go away in a while */
+#define REGISTER_CLEANUP(dbm, pdatum) NOOP_FUNCTION
+#define SET_FILE(pdb, f) ((pdb)->file = (f))
+
/*
* We pick up all varieties of Berkeley DB through db.h (included through
* apu_select_dbm.h). This code has been compiled/tested against DB1,
@@ -227,11 +240,68 @@
** ### we may need three sets of these: db1, db2, db3
*/
-static apr_status_t vt_db_open(apr_dbm_t **dbm, const char *name,
+static apr_status_t vt_db_open(apr_dbm_t **pdb, const char *pathname,
apr_int32_t mode, apr_fileperms_t perm,
- apr_pool_t *cntxt)
+ apr_pool_t *pool)
{
- abort();
+ real_file_t file;
+ int dbmode;
+
+ *pdb = NULL;
+
+ switch (mode) {
+ case APR_DBM_READONLY:
+ dbmode = APR_DBM_DBMODE_RO;
+ break;
+ case APR_DBM_READWRITE:
+ dbmode = APR_DBM_DBMODE_RW;
+ break;
+ case APR_DBM_RWCREATE:
+ dbmode = APR_DBM_DBMODE_RWCREATE;
+ break;
+ case APR_DBM_RWTRUNC:
+ dbmode = APR_DBM_DBMODE_RWTRUNC;
+ break;
+ default:
+ return APR_EINVAL;
+ }
+
+ {
+ int dberr;
+
+#if DB_VER == 3
+ if ((dberr = db_create(&file.bdb, NULL, 0)) == 0) {
+ if ((dberr = (*file.bdb->open)(file.bdb, pathname, NULL,
+ DB_HASH, dbmode,
+ apr_posix_perms2mode(perm))) !=
0) {
+ /* close the DB handler */
+ (void) (*file.bdb->close)(file.bdb, 0);
+ }
+ }
+ file.curs = NULL;
+#elif DB_VER == 2
+ dberr = db_open(pathname, DB_HASH, dbmode,
apr_posix_perms2mode(perm),
+ NULL, NULL, &file.bdb);
+ file.curs = NULL;
+#else
+ file.bdb = dbopen(pathname, dbmode, apr_posix_perms2mode(perm),
+ DB_HASH, NULL);
+ if (file.bdb == NULL)
+ return APR_EGENERAL; /* ### need a better error */
+ dberr = 0;
+#endif
+ if (dberr != 0)
+ return db2s(dberr);
+ }
+
+ /* we have an open database... return it */
+ *pdb = apr_pcalloc(pool, sizeof(**pdb));
+ (*pdb)->pool = pool;
+ (*pdb)->type = &apr_dbm_type_db;
+ SET_FILE(*pdb, file);
+
+ /* ### register a cleanup to close the DBM? */
+
return APR_SUCCESS;
}
@@ -243,46 +313,94 @@
static apr_status_t vt_db_fetch(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t * pvalue)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ result_datum_t rd = { 0 };
+
+ CONVERT_DATUM(ckey, &key);
+ rv = APR_DBM_FETCH(dbm->file, ckey, rd);
+ RETURN_DATUM(pvalue, rd);
+
+ REGISTER_CLEANUP(dbm, pvalue);
+
+ /* store the error info into DBM, and return a status code. Also, note
+ that *pvalue should have been cleared on error. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_db_store(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t value)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ cvt_datum_t cvalue;
+
+ CONVERT_DATUM(ckey, &key);
+ CONVERT_DATUM(cvalue, &value);
+ rv = APR_DBM_STORE(dbm->file, ckey, cvalue);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_db_del(apr_dbm_t *dbm, apr_datum_t key)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+
+ CONVERT_DATUM(ckey, &key);
+ rv = APR_DBM_DELETE(dbm->file, ckey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static int vt_db_exists(apr_dbm_t *dbm, apr_datum_t key)
{
- abort();
- return 0;
+ DBT ckey = { 0 }; /* converted key */
+ DBT data = { 0 };
+ int dberr;
+
+ ckey.data = key.dptr;
+ ckey.size = key.dsize;
+
+ dberr = do_fetch(GET_BDB(dbm->file), ckey, data);
+
+ /* note: the result data is "loaned" to us; we don't need to free it */
+
+ /* DB returns DB_NOTFOUND if it doesn't exist. but we want to say
+ that *any* error means it doesn't exist. */
+ return dberr == 0;
}
static apr_status_t vt_db_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ result_datum_t rd;
+
+ rv = APR_DBM_FIRSTKEY(dbm->file, rd);
+ RETURN_DATUM(pkey, rd);
+
+ REGISTER_CLEANUP(dbm, pkey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_db_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
- abort();
- return APR_SUCCESS;
-}
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ result_datum_t rd;
+
+ CONVERT_DATUM(ckey, pkey);
+ rv = APR_DBM_NEXTKEY(dbm->file, ckey, rd);
+ RETURN_DATUM(pkey, rd);
-static char * vt_db_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf,
- apr_size_t errbufsize)
-{
- abort();
- return NULL;
+ REGISTER_CLEANUP(dbm, pkey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, APR_SUCCESS);
}
static void vt_db_freedatum(apr_dbm_t *dbm, apr_datum_t data)
@@ -298,7 +416,7 @@
}
-static const apr_dbm_type_t apr_dbm_type_db = {
+APU_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_db = {
"db",
vt_db_open,
@@ -309,7 +427,6 @@
vt_db_exists,
vt_db_firstkey,
vt_db_nextkey,
- vt_db_geterror,
vt_db_freedatum,
vt_db_usednames
};
1.6 +111 -26 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apr_dbm_gdbm.c 2001/11/08 19:46:44 1.5
+++ apr_dbm_gdbm.c 2001/11/11 07:46:28 1.6
@@ -52,13 +52,25 @@
* <http://www.apache.org/>.
*/
-#include "apr_dbm_private.h"
+#include "apr_strings.h"
-#include <gdbm.h>
#if APR_HAVE_STDLIB_H
-#include <stdlib.h> /* for free() and abort() */
+#include <stdlib.h> /* for free() */
#endif
+#include "apr_dbm_private.h"
+
+#include <gdbm.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
+
+/* ### define defaults for now; these will go away in a while */
+#define REGISTER_CLEANUP(dbm, pdatum) NOOP_FUNCTION
+#define SET_FILE(pdb, f) ((pdb)->file = (f))
+
typedef GDBM_FILE real_file_t;
typedef datum *cvt_datum_t;
@@ -132,11 +144,48 @@
** DEFINE THE VTABLE FUNCTIONS FOR GDBM
*/
-static apr_status_t vt_gdbm_open(apr_dbm_t **dbm, const char *name,
+static apr_status_t vt_gdbm_open(apr_dbm_t **pdb, const char *pathname,
apr_int32_t mode, apr_fileperms_t perm,
- apr_pool_t *cntxt)
+ apr_pool_t *pool)
{
- abort();
+ real_file_t file;
+ int dbmode;
+
+ *pdb = NULL;
+
+ switch (mode) {
+ case APR_DBM_READONLY:
+ dbmode = APR_DBM_DBMODE_RO;
+ break;
+ case APR_DBM_READWRITE:
+ dbmode = APR_DBM_DBMODE_RW;
+ break;
+ case APR_DBM_RWCREATE:
+ dbmode = APR_DBM_DBMODE_RWCREATE;
+ break;
+ case APR_DBM_RWTRUNC:
+ dbmode = APR_DBM_DBMODE_RWTRUNC;
+ break;
+ default:
+ return APR_EINVAL;
+ }
+
+ {
+ /* Note: stupid cast to get rid of "const" on the pathname */
+ file = gdbm_open((char *) pathname, 0, dbmode,
+ apr_posix_perms2mode(perm), NULL);
+ if (file == NULL)
+ return APR_EGENERAL; /* ### need a better error */
+ }
+
+ /* we have an open database... return it */
+ *pdb = apr_pcalloc(pool, sizeof(**pdb));
+ (*pdb)->pool = pool;
+ (*pdb)->type = &apr_dbm_type_gdbm;
+ SET_FILE(*pdb, file);
+
+ /* ### register a cleanup to close the DBM? */
+
return APR_SUCCESS;
}
@@ -148,46 +197,83 @@
static apr_status_t vt_gdbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t * pvalue)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ result_datum_t rd;
+
+ CONVERT_DATUM(ckey, &key);
+ rv = APR_DBM_FETCH(dbm->file, ckey, rd);
+ RETURN_DATUM(pvalue, rd);
+
+ REGISTER_CLEANUP(dbm, pvalue);
+
+ /* store the error info into DBM, and return a status code. Also, note
+ that *pvalue should have been cleared on error. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_gdbm_store(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t value)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ cvt_datum_t cvalue;
+
+ CONVERT_DATUM(ckey, &key);
+ CONVERT_DATUM(cvalue, &value);
+ rv = APR_DBM_STORE(dbm->file, ckey, cvalue);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_gdbm_del(apr_dbm_t *dbm, apr_datum_t key)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+
+ CONVERT_DATUM(ckey, &key);
+ rv = APR_DBM_DELETE(dbm->file, ckey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static int vt_gdbm_exists(apr_dbm_t *dbm, apr_datum_t key)
{
- abort();
- return 0;
+ datum *ckey = (datum *)&key;
+
+ return gdbm_exists(dbm->file, *ckey) != 0;
}
static apr_status_t vt_gdbm_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ result_datum_t rd;
+
+ rv = APR_DBM_FIRSTKEY(dbm->file, rd);
+ RETURN_DATUM(pkey, rd);
+
+ REGISTER_CLEANUP(dbm, pkey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_gdbm_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
- abort();
- return APR_SUCCESS;
-}
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ result_datum_t rd;
+
+ CONVERT_DATUM(ckey, pkey);
+ rv = APR_DBM_NEXTKEY(dbm->file, ckey, rd);
+ RETURN_DATUM(pkey, rd);
-static char * vt_gdbm_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf,
- apr_size_t errbufsize)
-{
- abort();
- return NULL;
+ REGISTER_CLEANUP(dbm, pkey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, APR_SUCCESS);
}
static void vt_gdbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
@@ -203,7 +289,7 @@
}
-static const apr_dbm_type_t apr_dbm_type_gdbm = {
+APU_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_gdbm = {
"gdbm",
vt_gdbm_open,
@@ -214,7 +300,6 @@
vt_gdbm_exists,
vt_gdbm_firstkey,
vt_gdbm_nextkey,
- vt_gdbm_geterror,
vt_gdbm_freedatum,
vt_gdbm_usednames
};
1.5 +120 -23 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- apr_dbm_sdbm.c 2001/11/08 19:46:44 1.4
+++ apr_dbm_sdbm.c 2001/11/11 07:46:28 1.5
@@ -52,6 +52,11 @@
* <http://www.apache.org/>.
*/
+#include "apr_strings.h"
+#define APR_WANT_MEMFUNC
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+
#include "apr_dbm_private.h"
#include "apr_sdbm.h"
@@ -59,6 +64,15 @@
#include <stdlib.h> /* For abort() */
#endif
+
+/* 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
+
+/* ### define defaults for now; these will go away in a while */
+#define REGISTER_CLEANUP(dbm, pdatum) NOOP_FUNCTION
+#define SET_FILE(pdb, f) ((pdb)->file = (f))
+
typedef apr_sdbm_t *real_file_t;
typedef apr_sdbm_datum_t *cvt_datum_t;
@@ -102,11 +116,48 @@
** DEFINE THE VTABLE FUNCTIONS FOR SDBM
*/
-static apr_status_t vt_sdbm_open(apr_dbm_t **dbm, const char *name,
+static apr_status_t vt_sdbm_open(apr_dbm_t **pdb, const char *pathname,
apr_int32_t mode, apr_fileperms_t perm,
- apr_pool_t *cntxt)
+ apr_pool_t *pool)
{
- abort();
+ real_file_t file;
+ int dbmode;
+
+ *pdb = NULL;
+
+ switch (mode) {
+ case APR_DBM_READONLY:
+ dbmode = APR_DBM_DBMODE_RO;
+ break;
+ case APR_DBM_READWRITE:
+ dbmode = APR_DBM_DBMODE_RW;
+ break;
+ case APR_DBM_RWCREATE:
+ dbmode = APR_DBM_DBMODE_RWCREATE;
+ break;
+ case APR_DBM_RWTRUNC:
+ dbmode = APR_DBM_DBMODE_RWTRUNC;
+ break;
+ default:
+ return APR_EINVAL;
+ }
+
+ {
+ apr_status_t rv;
+
+ rv = apr_sdbm_open(&file, pathname, dbmode, perm, pool);
+ if (rv != APR_SUCCESS)
+ return rv;
+ }
+
+ /* we have an open database... return it */
+ *pdb = apr_pcalloc(pool, sizeof(**pdb));
+ (*pdb)->pool = pool;
+ (*pdb)->type = &apr_dbm_type_sdbm;
+ SET_FILE(*pdb, file);
+
+ /* ### register a cleanup to close the DBM? */
+
return APR_SUCCESS;
}
@@ -118,46 +169,93 @@
static apr_status_t vt_sdbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t * pvalue)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ result_datum_t rd;
+
+ CONVERT_DATUM(ckey, &key);
+ rv = APR_DBM_FETCH(dbm->file, ckey, rd);
+ RETURN_DATUM(pvalue, rd);
+
+ REGISTER_CLEANUP(dbm, pvalue);
+
+ /* store the error info into DBM, and return a status code. Also, note
+ that *pvalue should have been cleared on error. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_sdbm_store(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t value)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ cvt_datum_t cvalue;
+
+ CONVERT_DATUM(ckey, &key);
+ CONVERT_DATUM(cvalue, &value);
+ rv = APR_DBM_STORE(dbm->file, ckey, cvalue);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_sdbm_del(apr_dbm_t *dbm, apr_datum_t key)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ cvt_datum_t ckey;
+
+ CONVERT_DATUM(ckey, &key);
+ rv = APR_DBM_DELETE(dbm->file, ckey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static int vt_sdbm_exists(apr_dbm_t *dbm, apr_datum_t key)
{
- abort();
- return 0;
+ int exists;
+ apr_sdbm_datum_t *ckey = (apr_sdbm_datum_t *)&key;
+
+ {
+ apr_sdbm_datum_t value;
+ if (apr_sdbm_fetch(dbm->file, &value, *ckey) != APR_SUCCESS) {
+ exists = 0;
+ }
+ else
+ exists = value.dptr != NULL;
+ }
+
+ return exists;
}
static apr_status_t vt_sdbm_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
- abort();
- return APR_SUCCESS;
+ apr_status_t rv;
+ result_datum_t rd;
+
+ rv = APR_DBM_FIRSTKEY(dbm->file, rd);
+ RETURN_DATUM(pkey, rd);
+
+ REGISTER_CLEANUP(dbm, pkey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, rv);
}
static apr_status_t vt_sdbm_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
- abort();
- return APR_SUCCESS;
-}
+ apr_status_t rv;
+ cvt_datum_t ckey;
+ result_datum_t rd;
+
+ CONVERT_DATUM(ckey, pkey);
+ rv = APR_DBM_NEXTKEY(dbm->file, ckey, rd);
+ RETURN_DATUM(pkey, rd);
-static char * vt_sdbm_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf,
- apr_size_t errbufsize)
-{
- abort();
- return NULL;
+ REGISTER_CLEANUP(dbm, pkey);
+
+ /* store any error info into DBM, and return a status code. */
+ return set_error(dbm, APR_SUCCESS);
}
static void vt_sdbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
@@ -181,7 +279,7 @@
}
-static const apr_dbm_type_t apr_dbm_type_sdbm = {
+APU_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_sdbm = {
"sdbm",
vt_sdbm_open,
@@ -192,7 +290,6 @@
vt_sdbm_exists,
vt_sdbm_firstkey,
vt_sdbm_nextkey,
- vt_sdbm_geterror,
vt_sdbm_freedatum,
vt_sdbm_usednames
};
1.3 +4 -6 apr-util/include/private/apr_dbm_private.h
Index: apr_dbm_private.h
===================================================================
RCS file: /home/cvs/apr-util/include/private/apr_dbm_private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- apr_dbm_private.h 2001/11/07 01:24:54 1.2
+++ apr_dbm_private.h 2001/11/11 07:46:29 1.3
@@ -87,8 +87,9 @@
const char *name;
/** Open the DBM */
- apr_status_t (*open)(apr_dbm_t **dbm, const char *name, apr_int32_t mode,
- apr_fileperms_t perm, apr_pool_t *cntxt);
+ apr_status_t (*open)(apr_dbm_t **pdb, const char *pathname,
+ apr_int32_t mode, apr_fileperms_t perm,
+ apr_pool_t *pool);
/** Close the DBM */
void (*close)(apr_dbm_t *dbm);
@@ -112,10 +113,6 @@
/** Retrieve the next record key from a dbm */
apr_status_t (*nextkey)(apr_dbm_t *dbm, apr_datum_t * pkey);
- /** Report more information when an apr_dbm function fails. */
- char *(*geterror)(apr_dbm_t *dbm, int *errcode, char *errbuf,
- apr_size_t errbufsize);
-
/** Proactively toss any memory associated with the apr_datum_t. */
void (*freedatum)(apr_dbm_t *dbm, apr_datum_t data);
@@ -152,6 +149,7 @@
APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db1;
APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db2;
APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db3;
+APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db;
#ifdef __cplusplus
}