You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by ia...@apache.org on 2002/08/21 23:42:41 UTC
cvs commit: apr-util/test testdbm.c
ianh 2002/08/21 14:42:41
Modified: . CHANGES
build apu-conf.m4
dbm Makefile.in apr_dbm.c
include apr_dbm.h apu.h.in
include/private apr_dbm_private.h apu_select_dbm.h.in
apu_select_dbm.hw
test testdbm.c
Added: dbm apr_dbm_ndbm.c
Log:
Bug #9789 NDBM support for apr_dbm.
this still needs a bit more testing, but it seems to work ok for me
Submitted by: Toomas Soome <ts...@muhv.pri.ee>
Revision Changes Path
1.75 +3 -0 apr-util/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr-util/CHANGES,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- CHANGES 18 Aug 2002 20:22:28 -0000 1.74
+++ CHANGES 21 Aug 2002 21:42:41 -0000 1.75
@@ -1,5 +1,8 @@
Changes with APR-util b1
+ *) Bug #9789 : NDBM support
+ [Toomas Soome <ts...@muhv.pri.ee>, Ian Holsman]
+
*) Added a Thread safe FIFO bounded buffer (apr_queue) [Ian Holsman]
*) Changed file_bucket_setaside() to use apr_file_setaside() instead
1.45 +82 -4 apr-util/build/apu-conf.m4
Index: apu-conf.m4
===================================================================
RCS file: /home/cvs/apr-util/build/apu-conf.m4,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- apu-conf.m4 30 Jul 2002 19:34:19 -0000 1.44
+++ apu-conf.m4 21 Aug 2002 21:42:41 -0000 1.45
@@ -184,11 +184,13 @@
dnl
AC_DEFUN(APU_CHECK_DBM,[
apu_use_sdbm=0
+apu_use_ndbm=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_ndbm=0
apu_have_db=0
apu_db_header=db.h # default so apu_select_dbm.h is syntactically correct
@@ -196,15 +198,16 @@
AC_ARG_WITH(dbm,
[ --with-dbm=DBM choose the DBM type to use.
- DBM={sdbm,gdbm,db,db1,db185,db2,db3,db4}],[
+ DBM={sdbm,gdbm,ndbm,db,db1,db185,db2,db3,db4}],[
if test "$withval" = "yes"; then
AC_MSG_ERROR([--with-dbm needs to specify a DBM type to use.
-One of: sdbm, gdbm, db, db1, db185, db2, db3, db4])
+One of: sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4])
fi
requested="$withval"
],[
requested=default
])
+
AC_ARG_WITH([gdbm],
[ --with-gdbm=DIR specify GDBM location], [
apu_have_gdbm=0
@@ -227,7 +230,70 @@
apu_have_gdbm=0
AC_CHECK_HEADER(gdbm.h, AC_CHECK_LIB(gdbm, gdbm_open, [apu_have_gdbm=1]))
])
-
+
+AC_ARG_WITH([ndbm],
+[ --with-ndbm=PATH
+ Find the NDBM header and library in \`PATH/include' and
+ \`PATH/lib'. If PATH is of the form \`HEADER:LIB', then search
+ for header files in HEADER, and the library in LIB. If you omit
+ the \`=PATH' part completely, the configure script will search
+ for NDBM in a number of standard places.], [
+
+ apu_have_ndbm=0
+ if test "$withval" = "yes"; then
+ AC_MSG_CHECKING(checking for ndbm in the usual places)
+ apu_want_ndbm=1
+ NDBM_INC=""
+ NDBM_LDFLAGS=""
+ elif test "$withval" = "no"; then
+ apu_want_ndbm=0
+ else
+ apu_want_ndbm=1
+ case "$withval" in
+ *":"*)
+ NDBM_INC="-I`echo $withval |sed -e 's/:.*$//'`"
+ NDBM_LDFLAGS="-L`echo $withval |sed -e 's/^.*://'`"
+ AC_MSG_CHECKING(checking for ndbm includes with $NDBM_INC libs with $NDBM_LDFLAGS )
+ ;;
+ *)
+ NDBM_INC="-I$withval/include"
+ NDBM_LDFLAGS="-L$withval/lib"
+ AC_MSG_CHECKING(checking for ndbm includes in $withval)
+ ;;
+ esac
+ fi
+
+ save_cppflags="$CPPFLAGS"
+ save_ldflags="$LDFLAGS"
+ CPPFLAGS="$CPPFLAGS $NDBM_INC"
+ LDFLAGS="$LDFLAGS $NDBM_LDFLAGS"
+ dnl db_ndbm_open is what sleepcat's compatibility library actually has in it's lib
+ if test "$apu_want_ndbm" != "0"; then
+ AC_CHECK_HEADER(ndbm.h,
+ AC_CHECK_LIB(c, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=c],
+ AC_CHECK_LIB(dbm, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=dbm],
+ AC_CHECK_LIB(db, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=db],
+ AC_CHECK_LIB(db, __db_ndbm_open, [apu_have_ndbm=1;apu_ndbm_lib=db])
+ )
+ )
+ )
+ )
+ if test "$apu_have_ndbm" != "0"; then
+ if test "$withval" != "yes"; then
+ APR_ADDTO(APRUTIL_INCLUDES, [$NDBM_INC])
+ APR_ADDTO(APRUTIL_LDFLAGS, [$NDBM_LDFLAGS])
+ fi
+ elif test "$withval" != "yes"; then
+ AC_ERROR( NDBM not found in the specified directory)
+ fi
+ fi
+ CPPFLAGS="$save_cppflags"
+ LDFLAGS="$save_ldflags"
+],[
+ dnl don't check it no one has asked us for it
+ apu_have_ndbm=0
+])
+
dnl We're going to try to find the highest version of Berkeley DB supported.
AC_ARG_WITH([berkeley-db],
@@ -294,6 +360,10 @@
apu_use_gdbm=1
apu_default_dbm=gdbm
;;
+ ndbm)
+ apu_use_ndbm=1
+ apu_default_dbm=ndbm
+ ;;
db)
if test "$apu_db_version" != "0"; then
apu_use_db=1
@@ -354,7 +424,7 @@
;;
*)
AC_MSG_ERROR([--with-dbm=$look_for is an unknown DBM type.
-Use one of: sdbm, gdbm, db, db1, db185, db2, db3, db4])
+Use one of: sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4])
;;
esac
@@ -366,10 +436,12 @@
AC_SUBST(apu_use_sdbm)
AC_SUBST(apu_use_gdbm)
+AC_SUBST(apu_use_ndbm)
AC_SUBST(apu_use_db)
AC_SUBST(apu_have_sdbm)
AC_SUBST(apu_have_gdbm)
+AC_SUBST(apu_have_ndbm)
AC_SUBST(apu_have_db)
AC_SUBST(apu_db_header)
AC_SUBST(apu_db_version)
@@ -380,6 +452,12 @@
APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lgdbm])
APR_ADDTO(APRUTIL_LIBS,[-lgdbm])
fi
+
+if test "$apu_have_ndbm" = "1"; then
+ APR_ADDTO(APRUTIL_EXPORT_LIBS,[-l$apu_ndbm_lib])
+ APR_ADDTO(APRUTIL_LIBS,[-l$apu_ndbm_lib])
+fi
+
if test "$apu_db_version" != "0"; then
if test -n "$apu_db_lib"; then
1.13 +1 -1 apr-util/dbm/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr-util/dbm/Makefile.in,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Makefile.in 8 May 2002 22:00:57 -0000 1.12
+++ Makefile.in 21 Aug 2002 21:42:41 -0000 1.13
@@ -2,7 +2,7 @@
INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@
-TARGETS = apr_dbm.lo apr_dbm_berkeleydb.lo apr_dbm_gdbm.lo apr_dbm_sdbm.lo
+TARGETS = apr_dbm.lo apr_dbm_berkeleydb.lo apr_dbm_gdbm.lo apr_dbm_sdbm.lo apr_dbm_ndbm.lo
# bring in rules.mk for standard functionality
@INCLUDE_RULES@
1.38 +15 -0 apr-util/dbm/apr_dbm.c
Index: apr_dbm.c
===================================================================
RCS file: /home/cvs/apr-util/dbm/apr_dbm.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- apr_dbm.c 13 Mar 2002 20:40:47 -0000 1.37
+++ apr_dbm.c 21 Aug 2002 21:42:41 -0000 1.38
@@ -78,6 +78,8 @@
#define DBM_VTABLE apr_dbm_type_gdbm
#elif APU_USE_DB
#define DBM_VTABLE apr_dbm_type_db
+#elif APU_USE_NDBM
+#define DBM_VTABLE apr_dbm_type_ndbm
#else /* Not in the USE_xDBM list above */
#error a DBM implementation was not specified
#endif
@@ -102,6 +104,12 @@
return (*apr_dbm_type_db.open)(pdb, pathname, mode, perm, pool);
}
#endif
+#if APU_HAVE_NDBM
+ if (!strcasecmp(type, "NDBM")) {
+ return (*apr_dbm_type_ndbm.open)(pdb, pathname, mode, perm, pool);
+ }
+#endif
+
if (!strcasecmp(type, "default")) {
return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
}
@@ -197,6 +205,13 @@
return;
}
#endif
+#if APU_HAVE_NDBM
+ if (!strcasecmp(type, "NDBM")) {
+ (*apr_dbm_type_ndbm.getusednames)(p,pathname,used1,used2);
+ return;
+ }
+#endif
+
if (!strcasecmp(type, "default")) {
(*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
return;
1.1 apr-util/dbm/apr_dbm_ndbm.c
Index: apr_dbm_ndbm.c
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#include "apr_strings.h"
#if APR_HAVE_STDLIB_H
#include <stdlib.h> /* for free() */
#endif
#include "apu.h"
#if APU_HAVE_NDBM
#include "apr_dbm_private.h"
#include <ndbm.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.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 APR_DBM_DBMODE_RO O_RDONLY
#define APR_DBM_DBMODE_RW O_RDWR
#define APR_DBM_DBMODE_RWCREATE (O_RDWR|O_CREAT)
#define APR_DBM_DBMODE_RWTRUNC (O_RDWR|O_CREAT|O_TRUNC)
/* map a NDBM error to an apr_status_t */
static apr_status_t ndbm2s(int ndbmerr)
{
if (ndbmerr == -1) {
/* ### need to fix this */
return APR_EGENERAL;
}
return APR_SUCCESS;
}
static apr_status_t set_error(apr_dbm_t *dbm, apr_status_t dbm_said)
{
apr_status_t rv = APR_SUCCESS;
/* ### ignore whatever the DBM said (dbm_said); ask it explicitly */
dbm->errmsg = NULL;
if (dbm_error((DBM*)dbm->file)) {
dbm->errmsg = NULL;
rv = APR_EGENERAL; /* ### need something better */
}
/* captured it. clear it now. */
dbm_clearerr((DBM*)dbm->file);
return rv;
}
/* --------------------------------------------------------------------------
**
** DEFINE THE VTABLE FUNCTIONS FOR NDBM
*/
static apr_status_t vt_ndbm_open(apr_dbm_t **pdb, const char *pathname,
apr_int32_t mode, apr_fileperms_t perm,
apr_pool_t *pool)
{
DBM *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;
}
{
file = dbm_open(pathname, dbmode, apr_posix_perms2mode(perm));
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_ndbm;
(*pdb)->file = file;
/* ### register a cleanup to close the DBM? */
return APR_SUCCESS;
}
static void vt_ndbm_close(apr_dbm_t *dbm)
{
dbm_close(dbm->file);
}
static apr_status_t vt_ndbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t * pvalue)
{
datum *ckey;
datum rd;
ckey = (datum*)&key;
rd = dbm_fetch(dbm->file, *ckey);
*pvalue = *(apr_datum_t*)&rd;
/* 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, APR_SUCCESS);
}
static apr_status_t vt_ndbm_store(apr_dbm_t *dbm, apr_datum_t key,
apr_datum_t value)
{
apr_status_t rv;
datum *ckey;
datum *cvalue;
ckey = (datum*)&key;
cvalue = (datum*)&value;
rv = ndbm2s( dbm_store( dbm->file, *ckey, *cvalue, DBM_REPLACE));
/* store any error info into DBM, and return a status code. */
return set_error(dbm, rv);
}
static apr_status_t vt_ndbm_del(apr_dbm_t *dbm, apr_datum_t key)
{
apr_status_t rv;
datum *ckey;
ckey = (datum*)&key;
rv = ndbm2s( dbm_delete(dbm->file, *ckey));
/* store any error info into DBM, and return a status code. */
return set_error(dbm, rv);
}
static int vt_ndbm_exists(apr_dbm_t *dbm, apr_datum_t key)
{
datum *ckey = (datum *)&key;
datum value;
value = dbm_fetch( dbm->file, *ckey);
return value.dptr != NULL;
}
static apr_status_t vt_ndbm_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
datum rd;
rd = dbm_firstkey(dbm->file);
*pkey = *(apr_datum_t*)&rd;
/* store any error info into DBM, and return a status code. */
return set_error(dbm, APR_SUCCESS);
}
static apr_status_t vt_ndbm_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
{
datum *ckey;
datum rd;
ckey = (datum*)pkey;
rd = dbm_nextkey(dbm->file);
*pkey = *(apr_datum_t*)&rd;
/* store any error info into DBM, and return a status code. */
return set_error(dbm, APR_SUCCESS);
}
static void vt_ndbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
{
/* nothing to do */
}
static void vt_ndbm_usednames(apr_pool_t *pool, const char *pathname,
const char **used1, const char **used2)
{
*used1 = apr_pstrdup(pool, pathname);
*used2 = NULL;
}
APU_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_ndbm = {
"ndbm",
vt_ndbm_open,
vt_ndbm_close,
vt_ndbm_fetch,
vt_ndbm_store,
vt_ndbm_del,
vt_ndbm_exists,
vt_ndbm_firstkey,
vt_ndbm_nextkey,
vt_ndbm_freedatum,
vt_ndbm_usednames
};
#endif /* APU_HAVE_NDBM */
1.17 +1 -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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- apr_dbm.h 21 Aug 2002 17:30:09 -0000 1.16
+++ apr_dbm.h 21 Aug 2002 21:42:41 -0000 1.17
@@ -104,6 +104,7 @@
* GDBM for GDBM files
* SDBM for SDBM files
* DB for berkeley DB files
+ * NDBM for NDBM files
* default for the default DBM type
* </pre>
* @param name The dbm file name to open
1.15 +1 -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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- apu.h.in 19 Jul 2002 13:02:14 -0000 1.14
+++ apu.h.in 21 Aug 2002 21:42:41 -0000 1.15
@@ -109,6 +109,7 @@
*/
#define APU_HAVE_SDBM @apu_have_sdbm@
#define APU_HAVE_GDBM @apu_have_gdbm@
+#define APU_HAVE_NDBM @apu_have_ndbm@
#define APU_HAVE_DB @apu_have_db@
#if APU_HAVE_DB
1.6 +1 -0 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apr_dbm_private.h 13 Mar 2002 20:40:49 -0000 1.5
+++ apr_dbm_private.h 21 Aug 2002 21:42:41 -0000 1.6
@@ -146,6 +146,7 @@
/* Declare all of the builtin DBM providers */
APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_sdbm;
APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_gdbm;
+APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_ndbm;
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;
1.6 +1 -0 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apu_select_dbm.h.in 13 Mar 2002 20:40:49 -0000 1.5
+++ apu_select_dbm.h.in 21 Aug 2002 21:42:41 -0000 1.6
@@ -59,6 +59,7 @@
** The following macros control what features APRUTIL will use
*/
#define APU_USE_SDBM @apu_use_sdbm@
+#define APU_USE_NDBM @apu_use_ndbm@
#define APU_USE_GDBM @apu_use_gdbm@
#define APU_USE_DB @apu_use_db@
1.4 +1 -0 apr-util/include/private/apu_select_dbm.hw
Index: apu_select_dbm.hw
===================================================================
RCS file: /home/cvs/apr-util/include/private/apu_select_dbm.hw,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- apu_select_dbm.hw 13 Mar 2002 20:40:49 -0000 1.3
+++ apu_select_dbm.hw 21 Aug 2002 21:42:41 -0000 1.4
@@ -60,6 +60,7 @@
*/
#define APU_USE_SDBM 1
#define APU_USE_GDBM 0
+#define APU_USE_NDBM 0
#define APU_USE_DB 0
#if APU_USE_DB
1.16 +3 -0 apr-util/test/testdbm.c
Index: testdbm.c
===================================================================
RCS file: /home/cvs/apr-util/test/testdbm.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- testdbm.c 13 Mar 2002 20:40:49 -0000 1.15
+++ testdbm.c 21 Aug 2002 21:42:41 -0000 1.16
@@ -442,6 +442,9 @@
#if APU_HAVE_GDBM
fputs(" GDBM", stderr);
#endif
+#if APU_HAVE_NDBM
+ fputs(" NDBM", stderr);
+#endif
#if APU_HAVE_SDBM
fputs(" SDBM", stderr);
#endif