/* ldbm.c - ldap dbm compatibility routines */
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
/* Patched for Berkeley DB version 2.0; /KSp; 98/02/23
*
static int ldbm_initialized = 0;
-#ifndef HAVE_BERKELEY_DB2
-/* Everything but DB2 is non-reentrant */
-
+#ifndef HAVE_BERKELEY_DB2_DB_THREAD
+/* Only DB2 with DB_THREAD is thread-free */
static ldap_pvt_thread_mutex_t ldbm_big_mutex;
#define LDBM_LOCK (ldap_pvt_thread_mutex_lock(&ldbm_big_mutex))
#define LDBM_UNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex))
+#else
+#define LDBM_LOCK ((void)0)
+#define LDBM_UNLOCK ((void)0)
+#endif
+
+#ifndef HAVE_BERKELEY_DB2
+
int ldbm_initialize( void )
{
if(ldbm_initialized++) return 1;
static DB_ENV ldbm_Env_internal;
DB_ENV *ldbm_Env = NULL;
-/* Berkeley DB 2.x is reentrant */
-#define LDBM_LOCK ((void)0)
-#define LDBM_UNLOCK ((void)0)
-
int ldbm_initialize( void )
{
int err;
- int envFlags;
+ u_int32_t envFlags;
if(ldbm_initialized++) return 1;
ldbm_Env->db_errcall = ldbm_db_errcall;
ldbm_Env->db_errpfx = "==>";
- envFlags = DB_CREATE | DB_THREAD;
+ envFlags = DB_CREATE
+#ifdef HAVE_BERKELEY_DB2_DB_THREAD
+ | DB_THREAD
+#endif
+ ;
if ( ( err = db_appinit( NULL, NULL, ldbm_Env, envFlags )) ) {
char error[BUFSIZ];
}
Datum
-#ifdef HAVE_BERKELEY_DB2
-ldbm_firstkey( LDBM ldbm, DBC **dbch )
-#else
-ldbm_firstkey( LDBM ldbm )
-#endif
+ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch )
{
Datum key, data;
#ifdef HAVE_BERKELEY_DB2
- DBC *dbci;
+ LDBMCursor *dbci;
ldbm_datum_init( key );
ldbm_datum_init( data );
}
Datum
-#ifdef HAVE_BERKELEY_DB2
-ldbm_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
-#else
-ldbm_nextkey( LDBM ldbm, Datum key )
-#endif
+ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
{
Datum data;
#ifdef HAVE_ST_BLKSIZE
if ( dbcachesize > 0 && stat( name, &st ) == 0 ) {
- dbcachesize = (dbcachesize / st.st_blksize);
+ dbcachesize /= st.st_blksize;
+ if( dbcachesize == 0 ) dbcachesize = 1;
gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
}
#else
- dbcachesize = (dbcachesize / 4096);
- gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
+ if ( dbcachesize > 0 ) {
+ dbcachesize /= 4096;
+ if( dbcachesize == 0 ) dbcachesize = 1;
+ gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
+ }
#endif
LDBM_UNLOCK;
}
Datum
-ldbm_firstkey( LDBM ldbm )
+ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
{
Datum d;
}
Datum
-ldbm_nextkey( LDBM ldbm, Datum key )
+ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
{
Datum d;
return( db );
-}/* LDBM ldbm_open() */
+}
fflush( stdout );
#endif
-}/* void ldbm_close() */
+}
mdbm_sync( ldbm );
LDBM_UNLOCK;
-}/* void ldbm_sync() */
+}
#define MAX_MDBM_RETRY 5
return d;
-}/* Datum ldbm_fetch() */
+}
return( rc );
-}/* int ldbm_store() */
-
+}
return( rc );
-}/* int ldbm_delete() */
+}
return ret;
-}/* static Datum ldbm_get_next() */
+}
Datum
-ldbm_firstkey( LDBM ldbm )
+ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
{
return ldbm_get_next( ldbm, mdbm_first );
-}/* Datum ldbm_firstkey() */
+}
Datum
-ldbm_nextkey( LDBM ldbm, Datum key )
+ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
{
/* XXX:
return ldbm_get_next( ldbm, mdbm_next );
-}/* Datum ldbm_nextkey() */
+}
int
ldbm_errno( LDBM ldbm )
/* XXX: best we can do with current mdbm interface */
return( errno );
-}/* int ldbm_errno() */
+}
}
Datum
-ldbm_firstkey( LDBM ldbm )
+ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
{
Datum d;
}
Datum
-ldbm_nextkey( LDBM ldbm, Datum key )
+ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
{
Datum d;