/* $OpenLDAP$ */
/*
- * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
+ * Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
- * Redistribution and use in source and binary forms are permitted only
- * as authorized by the OpenLDAP Public License. A copy of this
- * license is available at http://www.OpenLDAP.org/license.html or
- * in file LICENSE in the top-level directory of the distribution.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License. A copy of this license is available at
+ * http://www.OpenLDAP.org/license.html or in file LICENSE in the
+ * top-level directory of the distribution.
*/
/* ldbm.h - ldap dbm compatibility routine header file */
#include <ldap_cdefs.h>
+/* dummy DB_ENV for non Berkeley DB */
+#if !defined( LDBM_USE_DBBTREE ) && !defined( LDBM_USE_DBHASH )
+# define DB_ENV void
+#endif
+
#if defined( LDBM_USE_DBBTREE ) || defined( LDBM_USE_DBHASH )
/*****************************************************************
* use berkeley db btree or hash package *
* *
*****************************************************************/
-
#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>
# else
# include <db.h>
# endif
-# ifdef HAVE_BERKELEY_DB2
-# define R_NOOVERWRITE DB_NOOVERWRITE
-# define DEFAULT_DB_PAGE_SIZE 1024
+#endif
+
+#ifndef DB_VERSION_MAJOR
+# define DB_VERSION_MAJOR 1
+#endif
+#ifndef DB_VERSION_MINOR
+# define DB_VERSION_MINOR 85
+#endif
+
+#if DB_VERSION_MAJOR >= 2
+# define R_NOOVERWRITE DB_NOOVERWRITE
+# ifndef DEFAULT_DB_PAGE_SIZE
+# define DEFAULT_DB_PAGE_SIZE 4096
# endif
+#else
+# define DB_ENV void
#endif
/* for ldbm_open */
-#ifdef HAVE_BERKELEY_DB2
+#if DB_VERSION_MAJOR >= 2
typedef DBC LDBMCursor;
# define LDBM_READER DB_RDONLY
# define LDBM_WRITER 0x00000 /* hopefully */
-# ifdef HAVE_BERKELEY_DB2_DB_THREAD
+# if defined( HAVE_BERKELEY_DB_THREAD )
# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD)
# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD)
# else
-# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD)
-# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD)
+# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE)
+# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE)
# endif
#else
-typedef int LDBMCursor;
+typedef void LDBMCursor;
# define LDBM_READER O_RDONLY
# define LDBM_WRITER O_RDWR
# define LDBM_WRCREAT (O_RDWR|O_CREAT)
LDAP_BEGIN_DECL
typedef datum Datum;
-typedef int LDBMCursor;
+typedef Datum LDBMCursor;
typedef GDBM_FILE LDBM;
-extern gdbm_error gdbm_errno;
-
LDAP_END_DECL
/* for ldbm_open */
#define LDBM_LOCKING 0
#ifdef GDBM_NOLOCK
#define LDBM_NOLOCKING GDBM_NOLOCK
+#else
+#define LDBM_NOLOCKING 0
#endif
#define LDBM_SUFFIX ".gdbm"
typedef MDBM *LDBM;
LDAP_END_DECL
-
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
LDAP_BEGIN_DECL
-int ldbm_initialize( void );
-int ldbm_shutdown( void );
+LDAP_LDBM_F (int) ldbm_initialize( const char * );
+LDAP_LDBM_F (int) ldbm_shutdown( void );
+
+LDAP_LDBM_F (DB_ENV*) ldbm_initialize_env(const char *, int dbcachesize, int *envdirok);
+LDAP_LDBM_F (void) ldbm_shutdown_env(DB_ENV *);
-int ldbm_errno( LDBM ldbm );
-LDBM ldbm_open( char *name, int rw, int mode, int dbcachesize );
-void ldbm_close( LDBM ldbm );
-void ldbm_sync( LDBM ldbm );
-void ldbm_datum_free( LDBM ldbm, Datum data );
-Datum ldbm_datum_dup( LDBM ldbm, Datum data );
-Datum ldbm_fetch( LDBM ldbm, Datum key );
-int ldbm_store( LDBM ldbm, Datum key, Datum data, int flags );
-int ldbm_delete( LDBM ldbm, Datum key );
+LDAP_LDBM_F (int) ldbm_errno( LDBM ldbm );
+LDAP_LDBM_F (LDBM) ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize );
+LDAP_LDBM_F (void) ldbm_close( LDBM ldbm );
+LDAP_LDBM_F (void) ldbm_sync( LDBM ldbm );
+LDAP_LDBM_F (void) ldbm_datum_free( LDBM ldbm, Datum data );
+LDAP_LDBM_F (Datum) ldbm_datum_dup( LDBM ldbm, Datum data );
+LDAP_LDBM_F (Datum) ldbm_fetch( LDBM ldbm, Datum key );
+LDAP_LDBM_F (int) ldbm_store( LDBM ldbm, Datum key, Datum data, int flags );
+LDAP_LDBM_F (int) ldbm_delete( LDBM ldbm, Datum key );
-Datum ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor );
-Datum ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor );
+LDAP_LDBM_F (Datum) ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor );
+LDAP_LDBM_F (Datum) ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor );
/* initialization of Datum structures */
-#ifdef HAVE_BERKELEY_DB2
- void *ldbm_malloc( size_t size );
-# define ldbm_datum_init(d) ((void)memset(&(d), 0, sizeof(Datum)))
+#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2)
+ LDAP_LDBM_F (void *) ldbm_malloc( size_t size );
+# define ldbm_datum_init(d) ((void)memset(&(d), '\0', sizeof(Datum)))
#else
# define ldbm_datum_init(d) ((void)0)
-#endif /* HAVE_BERKELEY_DB2 */
+#endif /* HAVE_BERKELEY_DB */
LDAP_END_DECL