1998-08-09 08:43:13 +08:00
|
|
|
/* ldbm.c - ldap dbm compatibility routines */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 13:42:11 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-11-26 13:42:11 +08:00
|
|
|
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
|
|
|
|
* Portions Copyright 1998-2001 Net Boolean Incorporated.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-08-05 07:57:27 +08:00
|
|
|
*/
|
2003-11-26 13:42:11 +08:00
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was originally developed by the University of Michigan
|
|
|
|
* (as part of U-MICH LDAP). Additional significant contributors
|
|
|
|
* include:
|
|
|
|
* Gary Williams
|
|
|
|
* Howard Chu
|
|
|
|
* Juan Gomez
|
|
|
|
* Kurt D. Zeilenga
|
|
|
|
* Kurt Spanier
|
|
|
|
* Mark Whitehouse
|
|
|
|
* Randy Kundee
|
1998-09-03 08:50:13 +08:00
|
|
|
*/
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#include "portable.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef SLAPD_LDBM
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/string.h>
|
1998-10-25 10:02:31 +08:00
|
|
|
#include <ac/errno.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#include "ldbm.h"
|
1999-01-28 12:34:55 +08:00
|
|
|
#include "ldap_pvt_thread.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
void
|
|
|
|
ldbm_datum_free( LDBM ldbm, Datum data )
|
|
|
|
{
|
1999-03-05 19:24:42 +08:00
|
|
|
if ( data.dptr ) {
|
|
|
|
free( data.dptr );
|
2000-06-11 06:39:30 +08:00
|
|
|
memset( &data, '\0', sizeof( Datum ));
|
1999-04-17 11:28:20 +08:00
|
|
|
data.dptr = NULL;
|
1999-03-05 19:24:42 +08:00
|
|
|
}
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
Datum
|
|
|
|
ldbm_datum_dup( LDBM ldbm, Datum data )
|
|
|
|
{
|
|
|
|
Datum dup;
|
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_init( dup );
|
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
if ( data.dsize == 0 ) {
|
|
|
|
dup.dsize = 0;
|
|
|
|
dup.dptr = NULL;
|
|
|
|
|
|
|
|
return( dup );
|
|
|
|
}
|
|
|
|
dup.dsize = data.dsize;
|
2001-05-29 03:11:29 +08:00
|
|
|
|
|
|
|
if ( (dup.dptr = (char *) malloc( data.dsize )) != NULL ) {
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( dup.dptr, data.dptr, data.dsize );
|
2001-05-29 03:11:29 +08:00
|
|
|
}
|
1999-02-05 01:41:19 +08:00
|
|
|
|
|
|
|
return( dup );
|
|
|
|
}
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
static int ldbm_initialized = 0;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
#if defined( USE_BERKELEY_CDB )
|
2001-10-01 14:08:46 +08:00
|
|
|
/* not currently supported */
|
2001-10-02 12:13:47 +08:00
|
|
|
#define LDBM_RWLOCK_INIT ((void) 0)
|
|
|
|
#define LDBM_RWLOCK_DESTROY ((void) 0)
|
|
|
|
#define LDBM_WLOCK ((void) 0)
|
|
|
|
#define LDBM_WUNLOCK ((void) 0)
|
|
|
|
#define LDBM_RLOCK ((void) 0)
|
|
|
|
#define LDBM_RUNLOCK ((void) 0)
|
|
|
|
|
|
|
|
#elif defined( HAVE_BERKELEY_DB_THREAD )
|
|
|
|
static ldap_pvt_thread_rdwr_t ldbm_big_rdwr;
|
|
|
|
#define LDBM_RWLOCK_INIT (ldap_pvt_thread_rdwr_init( &ldbm_big_rdwr ))
|
|
|
|
#define LDBM_RWLOCK_DESTROY (ldap_pvt_thread_rdwr_destroy( &ldbm_big_rdwr ))
|
|
|
|
#define LDBM_WLOCK (ldap_pvt_thread_rdwr_wlock(&ldbm_big_rdwr))
|
|
|
|
#define LDBM_WUNLOCK (ldap_pvt_thread_rdwr_wunlock(&ldbm_big_rdwr))
|
|
|
|
#define LDBM_RLOCK (ldap_pvt_thread_rdwr_rlock(&ldbm_big_rdwr))
|
|
|
|
#define LDBM_RUNLOCK (ldap_pvt_thread_rdwr_runlock(&ldbm_big_rdwr))
|
|
|
|
|
2001-05-29 03:43:11 +08:00
|
|
|
#else
|
1999-02-05 01:41:19 +08:00
|
|
|
static ldap_pvt_thread_mutex_t ldbm_big_mutex;
|
2001-10-02 12:13:47 +08:00
|
|
|
#define LDBM_RWLOCK_INIT (ldap_pvt_thread_mutex_init( &ldbm_big_mutex ))
|
|
|
|
#define LDBM_RWLOCK_DESTROY (ldap_pvt_thread_mutex_destroy( &ldbm_big_mutex ))
|
|
|
|
#define LDBM_WLOCK (ldap_pvt_thread_mutex_lock(&ldbm_big_mutex))
|
|
|
|
#define LDBM_WUNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex))
|
|
|
|
#define LDBM_RLOCK LDBM_WLOCK
|
|
|
|
#define LDBM_RUNLOCK LDBM_WUNLOCK
|
2001-05-29 03:43:11 +08:00
|
|
|
#endif
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
#if !defined( HAVE_BERKELEY_DB ) || (DB_VERSION_MAJOR < 3)
|
2001-10-01 14:08:46 +08:00
|
|
|
/* a dbEnv for BERKELEYv2 */
|
2001-06-22 02:54:56 +08:00
|
|
|
DB_ENV *ldbm_Env = NULL; /* real or fake, depending on db and version */
|
|
|
|
#endif
|
|
|
|
|
2002-10-31 04:35:25 +08:00
|
|
|
/* Let's make the version comparisons a little easier... */
|
|
|
|
#undef DB_VERSION_X
|
|
|
|
#ifdef HAVE_BERKELEY_DB
|
|
|
|
#define DB_VERSION_X ((DB_VERSION_MAJOR<<16)|(DB_VERSION_MINOR<<8)|DB_VERSION_PATCH)
|
|
|
|
#endif
|
|
|
|
|
2000-05-26 04:41:55 +08:00
|
|
|
/*******************************************************************
|
|
|
|
* *
|
|
|
|
* Create some special functions to initialize Berkeley DB for *
|
|
|
|
* versions greater than 2. *
|
|
|
|
* *
|
|
|
|
*******************************************************************/
|
|
|
|
#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2)
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
void *
|
|
|
|
ldbm_malloc( size_t size )
|
|
|
|
{
|
2001-08-28 06:06:07 +08:00
|
|
|
/* likely should use ber_mem* routines */
|
|
|
|
return( calloc( 1, size ) );
|
1999-05-19 09:12:33 +08:00
|
|
|
}
|
|
|
|
|
1999-05-19 09:58:23 +08:00
|
|
|
#ifdef LDAP_SYSLOG
|
|
|
|
#include <ac/syslog.h>
|
1999-03-02 06:37:05 +08:00
|
|
|
#endif
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
static void
|
2004-11-22 00:50:24 +08:00
|
|
|
#if DB_VERSION_X < 0x040300
|
1999-02-05 01:41:19 +08:00
|
|
|
ldbm_db_errcall( const char *prefix, char *message )
|
2004-11-22 00:50:24 +08:00
|
|
|
#else
|
|
|
|
ldbm_db_errcall( const DB_ENV *env, const char *prefix, char *message )
|
|
|
|
#endif
|
1999-02-05 01:41:19 +08:00
|
|
|
{
|
1999-05-19 09:58:23 +08:00
|
|
|
#ifdef LDAP_SYSLOG
|
2000-09-20 08:27:47 +08:00
|
|
|
syslog( LOG_INFO, "ldbm: %s %s", prefix, message );
|
1999-04-02 00:06:08 +08:00
|
|
|
#endif
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
|
|
|
|
2000-09-12 02:46:34 +08:00
|
|
|
int ldbm_initialize( const char* home )
|
1999-02-05 01:41:19 +08:00
|
|
|
{
|
2001-12-09 10:34:45 +08:00
|
|
|
#if DB_VERSION_MAJOR < 3
|
2001-05-29 03:11:29 +08:00
|
|
|
int err;
|
1999-09-07 02:45:39 +08:00
|
|
|
u_int32_t envFlags;
|
2001-12-09 10:34:45 +08:00
|
|
|
#endif
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
if(ldbm_initialized++) return 1;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
2001-06-08 00:11:59 +08:00
|
|
|
{
|
|
|
|
char *version;
|
2004-02-13 08:53:02 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
char v2[1024];
|
|
|
|
#endif
|
2001-06-08 00:11:59 +08:00
|
|
|
int major, minor, patch;
|
|
|
|
version = db_version( &major, &minor, &patch );
|
2004-02-13 08:53:02 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
strcpy( v2, version );
|
|
|
|
__etoa( v2 );
|
|
|
|
version = v2;
|
|
|
|
#endif
|
2001-06-08 00:11:59 +08:00
|
|
|
|
|
|
|
if( major != DB_VERSION_MAJOR ||
|
2001-06-08 00:15:25 +08:00
|
|
|
minor < DB_VERSION_MINOR )
|
2001-06-08 00:11:59 +08:00
|
|
|
{
|
|
|
|
#ifdef LDAP_SYSLOG
|
|
|
|
syslog( LOG_INFO,
|
2001-06-08 00:15:25 +08:00
|
|
|
"ldbm_initialize(): version mismatch\nexpected: %s\ngot: %s\n",
|
2001-10-01 14:08:46 +08:00
|
|
|
DB_VERSION_STRING, version );
|
2001-06-08 00:11:59 +08:00
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-01 14:08:46 +08:00
|
|
|
#if DB_VERSION_MAJOR < 3
|
2000-05-26 13:47:02 +08:00
|
|
|
ldbm_Env = calloc( 1, sizeof( DB_ENV ));
|
|
|
|
|
|
|
|
if( ldbm_Env == NULL ) return 1;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
ldbm_Env->db_errcall = ldbm_db_errcall;
|
|
|
|
ldbm_Env->db_errpfx = "==>";
|
1999-01-05 23:40:58 +08:00
|
|
|
|
2001-10-01 14:08:46 +08:00
|
|
|
envFlags = DB_CREATE | DB_USE_ENVIRON;
|
2001-05-29 03:43:11 +08:00
|
|
|
|
|
|
|
/* add optional flags */
|
2001-05-29 03:11:29 +08:00
|
|
|
#ifdef DB_PRIVATE
|
2001-05-29 03:43:11 +08:00
|
|
|
envFlags |= DB_PRIVATE;
|
2000-09-12 01:49:25 +08:00
|
|
|
#endif
|
2001-05-29 03:11:29 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB_THREAD
|
2001-10-01 14:08:46 +08:00
|
|
|
envFlags |= DB_THREAD;
|
1999-09-21 04:55:54 +08:00
|
|
|
#endif
|
1999-01-05 23:40:58 +08:00
|
|
|
|
2000-09-12 02:46:34 +08:00
|
|
|
err = db_appinit( home, NULL, ldbm_Env, envFlags );
|
2000-05-26 13:47:02 +08:00
|
|
|
|
|
|
|
if ( err ) {
|
2001-05-29 03:11:29 +08:00
|
|
|
#ifdef LDAP_SYSLOG
|
2001-10-01 14:08:46 +08:00
|
|
|
syslog( LOG_INFO, "ldbm_initialize(): "
|
2001-10-13 08:24:40 +08:00
|
|
|
"FATAL error (%d) in db_appinit()\n", err );
|
1999-04-02 00:06:08 +08:00
|
|
|
#endif
|
1999-02-05 17:03:47 +08:00
|
|
|
return( 1 );
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
2001-09-04 03:23:05 +08:00
|
|
|
#endif
|
2000-05-26 13:47:02 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RWLOCK_INIT;
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ldbm_shutdown( void )
|
|
|
|
{
|
|
|
|
if( !ldbm_initialized ) return 1;
|
|
|
|
|
2001-09-04 03:23:05 +08:00
|
|
|
#if DB_VERSION_MAJOR < 3
|
1999-03-05 19:24:42 +08:00
|
|
|
db_appexit( ldbm_Env );
|
2001-10-01 14:08:46 +08:00
|
|
|
#endif
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RWLOCK_DESTROY;
|
2000-05-25 23:21:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-05-26 04:41:55 +08:00
|
|
|
#else /* some DB other than Berkeley V2 or greater */
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2000-09-12 02:46:34 +08:00
|
|
|
int ldbm_initialize( const char * home )
|
2000-05-25 23:21:30 +08:00
|
|
|
{
|
|
|
|
if(ldbm_initialized++) return 1;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RWLOCK_INIT;
|
2000-05-25 23:21:30 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ldbm_shutdown( void )
|
|
|
|
{
|
|
|
|
if( !ldbm_initialized ) return 1;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RWLOCK_DESTROY;
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return 0;
|
1999-02-02 01:37:43 +08:00
|
|
|
}
|
|
|
|
|
2000-09-12 02:46:34 +08:00
|
|
|
#endif /* HAVE_BERKELEY_DB */
|
2000-05-26 04:41:55 +08:00
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 3)
|
|
|
|
|
|
|
|
DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok)
|
|
|
|
{
|
|
|
|
DB_ENV *env = NULL;
|
|
|
|
int err;
|
|
|
|
u_int32_t envFlags;
|
2003-05-23 07:22:22 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
char n2[2048];
|
|
|
|
#endif
|
2001-06-22 02:54:56 +08:00
|
|
|
|
|
|
|
err = db_env_create( &env, 0 );
|
|
|
|
|
|
|
|
if ( err ) {
|
|
|
|
#ifdef LDAP_SYSLOG
|
2001-10-01 14:08:46 +08:00
|
|
|
syslog( LOG_INFO, "ldbm_initialize_env(): "
|
|
|
|
"FATAL error in db_env_create() : %s (%d)\n",
|
|
|
|
db_strerror( err ), err );
|
2001-06-22 02:54:56 +08:00
|
|
|
#endif
|
2001-10-01 14:08:46 +08:00
|
|
|
return NULL;
|
2001-06-22 02:54:56 +08:00
|
|
|
}
|
|
|
|
|
2002-10-31 04:35:25 +08:00
|
|
|
#if DB_VERSION_X >= 0x030300
|
2001-12-11 00:26:32 +08:00
|
|
|
/* This interface appeared in 3.3 */
|
2001-10-04 11:36:48 +08:00
|
|
|
env->set_alloc( env, ldbm_malloc, NULL, NULL );
|
|
|
|
#endif
|
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
env->set_errcall( env, ldbm_db_errcall );
|
|
|
|
env->set_errpfx( env, "==>" );
|
2001-10-01 14:08:46 +08:00
|
|
|
if (dbcachesize) {
|
2001-06-22 16:31:36 +08:00
|
|
|
env->set_cachesize( env, 0, dbcachesize, 0 );
|
2001-10-01 14:08:46 +08:00
|
|
|
}
|
2001-06-22 02:54:56 +08:00
|
|
|
|
2001-10-01 14:08:46 +08:00
|
|
|
envFlags = DB_CREATE | DB_INIT_MPOOL | DB_USE_ENVIRON;
|
|
|
|
#ifdef DB_PRIVATE
|
|
|
|
envFlags |= DB_PRIVATE;
|
2001-09-29 04:52:48 +08:00
|
|
|
#endif
|
2001-10-01 14:08:46 +08:00
|
|
|
#ifdef DB_MPOOL_PRIVATE
|
|
|
|
envFlags |= DB_MPOOL_PRIVATE;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_BERKELEY_DB_THREAD
|
|
|
|
envFlags |= DB_THREAD;
|
2001-09-29 04:52:48 +08:00
|
|
|
#endif
|
2001-06-22 02:54:56 +08:00
|
|
|
|
2003-05-23 07:22:22 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
strncpy(n2, home, sizeof(n2)-1);
|
|
|
|
n2[sizeof(n2)-1] = '\0';
|
|
|
|
__atoe(n2);
|
|
|
|
home = n2;
|
|
|
|
#endif
|
2002-10-31 04:35:25 +08:00
|
|
|
#if DB_VERSION_X >= 0x030100
|
2001-06-22 02:54:56 +08:00
|
|
|
err = env->open( env, home, envFlags, 0 );
|
2001-09-04 03:01:09 +08:00
|
|
|
#else
|
|
|
|
/* 3.0.x requires an extra argument */
|
|
|
|
err = env->open( env, home, NULL, envFlags, 0 );
|
|
|
|
#endif
|
2001-06-22 02:54:56 +08:00
|
|
|
|
2001-10-01 14:08:46 +08:00
|
|
|
if ( err != 0 ) {
|
2001-06-22 02:54:56 +08:00
|
|
|
#ifdef LDAP_SYSLOG
|
2001-10-01 14:08:46 +08:00
|
|
|
syslog( LOG_INFO, "ldbm_initialize_env(): "
|
|
|
|
"FATAL error in dbEnv->open() : %s (%d)\n",
|
|
|
|
db_strerror( err ), err );
|
2001-06-22 02:54:56 +08:00
|
|
|
#endif
|
|
|
|
env->close( env, 0 );
|
2001-10-01 14:08:46 +08:00
|
|
|
return NULL;
|
2001-06-22 02:54:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*envdirok = 1;
|
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ldbm_shutdown_env(DB_ENV *env)
|
|
|
|
{
|
|
|
|
env->close( env, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok)
|
|
|
|
{
|
|
|
|
return ldbm_Env;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ldbm_shutdown_env(DB_ENV *env)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
#if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE )
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
|
|
|
* use berkeley db hash or btree package *
|
|
|
|
* *
|
|
|
|
*****************************************************************/
|
1999-02-02 01:37:43 +08:00
|
|
|
|
|
|
|
LDBM
|
2001-06-22 02:54:56 +08:00
|
|
|
ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize )
|
1999-01-27 04:55:54 +08:00
|
|
|
{
|
|
|
|
LDBM ret = NULL;
|
2002-07-27 12:43:48 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
char n2[2048];
|
|
|
|
#endif
|
1999-01-05 23:40:58 +08:00
|
|
|
|
2000-05-26 04:41:55 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 3
|
2001-05-29 03:11:29 +08:00
|
|
|
int err;
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
2000-07-06 09:24:52 +08:00
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
err = db_create( &ret, env, 0 );
|
2001-05-29 03:11:29 +08:00
|
|
|
if ( err != 0 ) {
|
|
|
|
(void)ret->close(ret, 0);
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
2001-06-08 00:24:46 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2002-10-31 04:35:25 +08:00
|
|
|
#if DB_VERSION_X < 0x030300
|
2001-10-10 03:54:38 +08:00
|
|
|
ret->set_malloc( ret, ldbm_malloc );
|
|
|
|
#endif
|
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
ret->set_pagesize( ret, DEFAULT_DB_PAGE_SIZE );
|
2001-08-28 06:06:07 +08:00
|
|
|
|
|
|
|
/* likely should use ber_mem* routines */
|
|
|
|
|
2002-07-27 12:43:48 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
strncpy(n2, name, sizeof(n2)-1);
|
|
|
|
n2[sizeof(n2)-1] = '\0';
|
|
|
|
__atoe(n2);
|
|
|
|
name = n2;
|
|
|
|
#endif
|
2002-10-31 04:35:25 +08:00
|
|
|
#if DB_VERSION_X >= 0x040111
|
2002-08-22 12:00:06 +08:00
|
|
|
err = ret->open( ret, NULL, name, NULL, DB_TYPE, rw, mode);
|
|
|
|
#else
|
2001-05-29 03:11:29 +08:00
|
|
|
err = ret->open( ret, name, NULL, DB_TYPE, rw, mode);
|
2002-08-22 12:00:06 +08:00
|
|
|
#endif
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
if ( err != 0 ) {
|
2001-06-08 00:24:46 +08:00
|
|
|
int tmp = errno;
|
2001-05-29 03:11:29 +08:00
|
|
|
(void)ret->close(ret, 0);
|
2001-06-08 00:24:46 +08:00
|
|
|
errno = tmp;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
2001-05-29 03:11:29 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-06-08 00:24:46 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2000-05-26 04:41:55 +08:00
|
|
|
#elif DB_VERSION_MAJOR >= 2
|
1999-02-05 01:41:19 +08:00
|
|
|
DB_INFO dbinfo;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
2000-06-11 06:39:30 +08:00
|
|
|
memset( &dbinfo, '\0', sizeof( dbinfo ));
|
1999-05-25 05:21:09 +08:00
|
|
|
|
2000-08-08 03:46:37 +08:00
|
|
|
#if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 4
|
1999-05-25 05:21:09 +08:00
|
|
|
/*
|
|
|
|
* BerkeleyDB 2.4 do not allow db_cachesize
|
|
|
|
* to be specified if an DB_ENV is.
|
|
|
|
*/
|
|
|
|
#else
|
|
|
|
/* set db_cachesize of MPOOL is NOT being used. */
|
2001-05-29 03:11:29 +08:00
|
|
|
if (( ldbm_Env == NULL ) || ( ldbm_Env->mp_info == NULL )) {
|
1999-02-08 19:42:14 +08:00
|
|
|
dbinfo.db_cachesize = dbcachesize;
|
2001-05-29 03:11:29 +08:00
|
|
|
}
|
1999-05-25 05:21:09 +08:00
|
|
|
#endif
|
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE;
|
|
|
|
dbinfo.db_malloc = ldbm_malloc;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
2001-05-29 03:11:29 +08:00
|
|
|
(void) db_open( name, DB_TYPE, rw, mode, ldbm_Env, &dbinfo, &ret );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
void *info;
|
|
|
|
BTREEINFO binfo;
|
|
|
|
HASHINFO hinfo;
|
|
|
|
|
|
|
|
if ( DB_TYPE == DB_HASH ) {
|
|
|
|
memset( (char *) &hinfo, '\0', sizeof(hinfo) );
|
|
|
|
hinfo.cachesize = dbcachesize;
|
|
|
|
info = &hinfo;
|
|
|
|
} else if ( DB_TYPE == DB_BTREE ) {
|
|
|
|
memset( (char *) &binfo, '\0', sizeof(binfo) );
|
|
|
|
binfo.cachesize = dbcachesize;
|
|
|
|
info = &binfo;
|
|
|
|
} else {
|
|
|
|
info = NULL;
|
|
|
|
}
|
1998-09-03 08:50:13 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
ret = dbopen( name, rw, mode, DB_TYPE, info );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
|
|
|
|
2001-06-08 00:24:46 +08:00
|
|
|
return ret;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
2001-12-11 00:26:32 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
2001-05-29 03:11:29 +08:00
|
|
|
ldbm->close( ldbm, 0 );
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2001-12-11 00:26:32 +08:00
|
|
|
ldbm->close( ldbm );
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
(*ldbm->sync)( ldbm, 0 );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_fetch( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
Datum data;
|
|
|
|
int rc;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
2001-05-29 03:11:29 +08:00
|
|
|
|
2001-12-11 00:26:32 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
2001-05-29 03:11:29 +08:00
|
|
|
ldbm_datum_init( data );
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
data.flags = DB_DBT_MALLOC;
|
2000-05-25 23:21:30 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
if ( (rc = ldbm->get( ldbm, NULL, &key, &data, 0 )) != 0 ) {
|
|
|
|
ldbm_datum_free( ldbm, data );
|
|
|
|
data.dptr = NULL;
|
|
|
|
data.dsize = 0;
|
|
|
|
}
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2001-12-11 00:26:32 +08:00
|
|
|
if ( (rc = ldbm->get( ldbm, &key, &data, 0 )) == 0 ) {
|
1999-02-05 01:41:19 +08:00
|
|
|
/* Berkeley DB 1.85 don't malloc the data for us */
|
|
|
|
/* duplicate it for to ensure reentrancy */
|
1998-08-09 08:43:13 +08:00
|
|
|
data = ldbm_datum_dup( ldbm, data );
|
|
|
|
} else {
|
|
|
|
data.dptr = NULL;
|
|
|
|
data.dsize = 0;
|
|
|
|
}
|
2001-05-29 03:11:29 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-12-11 00:26:32 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
2001-05-29 03:11:29 +08:00
|
|
|
rc = ldbm->put( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC );
|
|
|
|
rc = (-1) * rc;
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2001-12-11 00:26:32 +08:00
|
|
|
rc = ldbm->put( ldbm, &key, &data, flags & ~LDBM_SYNC );
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
1998-12-30 01:28:45 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( flags & LDBM_SYNC )
|
2001-12-11 00:26:32 +08:00
|
|
|
ldbm->sync( ldbm, 0 );
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_delete( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-12-11 00:26:32 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
2000-05-25 23:21:30 +08:00
|
|
|
rc = ldbm->del( ldbm, NULL, &key, 0 );
|
2001-05-29 03:11:29 +08:00
|
|
|
rc = (-1) * rc;
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2001-12-11 00:26:32 +08:00
|
|
|
rc = ldbm->del( ldbm, &key, 0 );
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
2001-12-11 00:26:32 +08:00
|
|
|
ldbm->sync( ldbm, 0 );
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
Datum key, data;
|
2001-10-02 12:13:47 +08:00
|
|
|
int rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-05-26 04:41:55 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
1999-08-18 03:00:59 +08:00
|
|
|
LDBMCursor *dbci;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( key );
|
|
|
|
ldbm_datum_init( data );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
|
|
|
key.flags = data.flags = DB_DBT_MALLOC;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
/* acquire a cursor for the DB */
|
2002-10-31 04:35:25 +08:00
|
|
|
# if DB_VERSION_X >= 0x020600
|
2001-10-02 12:13:47 +08:00
|
|
|
rc = ldbm->cursor( ldbm, NULL, &dbci, 0 );
|
|
|
|
# else
|
2001-12-11 00:26:32 +08:00
|
|
|
rc = ldbm->cursor( ldbm, NULL, &dbci );
|
2001-10-02 12:13:47 +08:00
|
|
|
# endif
|
1998-12-30 01:28:45 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
if( rc ) {
|
1999-03-05 19:24:42 +08:00
|
|
|
key.dptr = NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
} else {
|
|
|
|
*dbch = dbci;
|
2001-12-11 00:26:32 +08:00
|
|
|
if ( dbci->c_get( dbci, &key, &data, DB_NEXT ) == 0 ) {
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( ldbm, data );
|
2001-10-02 12:13:47 +08:00
|
|
|
} else {
|
|
|
|
key.dptr = NULL;
|
|
|
|
key.dsize = 0;
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
2001-10-02 12:13:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LDBM_RUNLOCK;
|
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-12-11 00:26:32 +08:00
|
|
|
rc = ldbm->seq( ldbm, &key, &data, R_FIRST );
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
if ( rc == 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
key = ldbm_datum_dup( ldbm, key );
|
2001-10-02 12:13:47 +08:00
|
|
|
} else {
|
1998-08-09 08:43:13 +08:00
|
|
|
key.dptr = NULL;
|
|
|
|
key.dsize = 0;
|
|
|
|
}
|
1998-09-03 08:50:13 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
2001-10-02 12:13:47 +08:00
|
|
|
int rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
Datum data;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
|
|
|
|
2000-05-26 04:41:55 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( data );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( ldbm, key );
|
|
|
|
key.flags = data.flags = DB_DBT_MALLOC;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
2001-12-11 00:26:32 +08:00
|
|
|
rc = dbcp->c_get( dbcp, &key, &data, DB_NEXT );
|
2001-10-02 12:13:47 +08:00
|
|
|
if ( rc == 0 ) {
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( ldbm, data );
|
2001-10-02 12:13:47 +08:00
|
|
|
} else
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2001-12-11 00:26:32 +08:00
|
|
|
rc = ldbm->seq( ldbm, &key, &data, R_NEXT );
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
if ( rc == 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
key = ldbm_datum_dup( ldbm, key );
|
2001-10-02 12:13:47 +08:00
|
|
|
} else
|
1999-03-06 12:15:18 +08:00
|
|
|
#endif
|
2001-10-02 12:13:47 +08:00
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
key.dptr = NULL;
|
|
|
|
key.dsize = 0;
|
|
|
|
}
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
return( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_errno( LDBM ldbm )
|
|
|
|
{
|
|
|
|
return( errno );
|
|
|
|
}
|
|
|
|
|
2000-05-25 23:21:30 +08:00
|
|
|
/******************************************************************
|
|
|
|
* *
|
|
|
|
* END Berkeley section *
|
|
|
|
* *
|
|
|
|
******************************************************************/
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#elif defined( HAVE_GDBM )
|
|
|
|
|
1999-04-17 11:28:20 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
1998-10-25 10:02:31 +08:00
|
|
|
#include <sys/stat.h>
|
1999-04-17 11:28:20 +08:00
|
|
|
#endif
|
1998-10-25 10:02:31 +08:00
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
1998-12-30 01:28:45 +08:00
|
|
|
* use gdbm *
|
1998-10-25 10:02:31 +08:00
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
LDBM
|
2001-06-22 02:54:56 +08:00
|
|
|
ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize )
|
1998-10-25 10:02:31 +08:00
|
|
|
{
|
|
|
|
LDBM db;
|
1999-04-20 01:56:48 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
|
|
|
struct stat st;
|
|
|
|
#endif
|
2002-07-27 12:43:48 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
char n2[2048];
|
|
|
|
|
|
|
|
strncpy(n2, name, sizeof(n2)-1);
|
|
|
|
n2[sizeof(n2)-1] = '\0';
|
|
|
|
__atoe(n2);
|
|
|
|
name = n2;
|
|
|
|
#endif
|
1998-10-25 10:02:31 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
if ( (db = gdbm_open( name, 0, rw | GDBM_FAST, mode, 0 )) == NULL ) {
|
|
|
|
LDBM_WUNLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
return( NULL );
|
|
|
|
}
|
1999-04-17 11:28:20 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
1998-10-25 10:02:31 +08:00
|
|
|
if ( dbcachesize > 0 && stat( name, &st ) == 0 ) {
|
1999-08-26 08:48:24 +08:00
|
|
|
dbcachesize /= st.st_blksize;
|
|
|
|
if( dbcachesize == 0 ) dbcachesize = 1;
|
1998-10-25 10:02:31 +08:00
|
|
|
gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
|
|
|
|
}
|
1999-04-17 11:28:20 +08:00
|
|
|
#else
|
1999-08-26 08:48:24 +08:00
|
|
|
if ( dbcachesize > 0 ) {
|
|
|
|
dbcachesize /= 4096;
|
|
|
|
if( dbcachesize == 0 ) dbcachesize = 1;
|
|
|
|
gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
|
|
|
|
}
|
1999-04-17 11:28:20 +08:00
|
|
|
#endif
|
1998-10-25 10:02:31 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
return( db );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
gdbm_close( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
gdbm_sync( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_fetch( LDBM ldbm, Datum key )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
d = gdbm_fetch( ldbm, key );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return d;
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
rc = gdbm_store( ldbm, key, data, flags & ~LDBM_SYNC );
|
|
|
|
if ( flags & LDBM_SYNC )
|
|
|
|
gdbm_sync( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_delete( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
rc = gdbm_delete( ldbm, key );
|
|
|
|
gdbm_sync( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
|
1998-10-25 10:02:31 +08:00
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
d = gdbm_firstkey( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2000-02-11 10:05:14 +08:00
|
|
|
if ( d.dptr != NULL ) {
|
|
|
|
*dbcp = (Datum *) malloc( sizeof( Datum ) );
|
|
|
|
**dbcp = ldbm_datum_dup( ldbm, d );
|
|
|
|
}
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return d;
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
|
1998-10-25 10:02:31 +08:00
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
2000-02-11 10:05:14 +08:00
|
|
|
d = gdbm_nextkey( ldbm, *dbcp );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2000-02-11 10:05:14 +08:00
|
|
|
ldbm_datum_free( ldbm, *dbcp );
|
|
|
|
|
|
|
|
if ( d.dptr != NULL ) {
|
|
|
|
*dbcp = ldbm_datum_dup( ldbm, d );
|
|
|
|
} else {
|
|
|
|
free( dbcp );
|
|
|
|
}
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return d;
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_errno( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
int err;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-02-05 01:41:19 +08:00
|
|
|
err = gdbm_errno;
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return( err );
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-30 12:39:08 +08:00
|
|
|
#elif HAVE_MDBM
|
|
|
|
|
|
|
|
/* MMAPED DBM HASHING DATABASE */
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/string.h>
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
/* #define MDBM_DEBUG */
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NO_NULL_KEY
|
|
|
|
/* #define MDBM_CHAIN */
|
|
|
|
|
|
|
|
#ifdef MDBM_CHAIN
|
|
|
|
|
|
|
|
/* Use chaining */
|
|
|
|
|
|
|
|
#define mdbm_store mdbm_chain_store
|
|
|
|
#define mdbm_fetch mdbm_chain_fetch
|
|
|
|
#define mdbm_delete mdbm_chain_delete
|
|
|
|
#define mdbm_first mdbm_chain_first
|
|
|
|
#define mdbm_next mdbm_chain_next
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MDBM_PG_SZ (4*1024)
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
|
|
|
* use mdbm *
|
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
LDBM
|
2001-06-22 02:54:56 +08:00
|
|
|
ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize )
|
1999-03-30 12:39:08 +08:00
|
|
|
{
|
|
|
|
LDBM db;
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout,
|
|
|
|
"==>(mdbm)ldbm_open(name=%s,rw=%x,mode=%x,cachesize=%d)\n",
|
|
|
|
name ? name : "NULL", rw, mode, dbcachesize );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK; /* We need locking here, this is the only non-thread
|
|
|
|
* safe function we have. */
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
if ( (db = mdbm_open( name, rw, mode, MDBM_PG_SZ )) == NULL ) {
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-03-30 12:39:08 +08:00
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_open(db=NULL)\n" );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MDBM_CHAIN
|
|
|
|
(void)mdbm_set_chain(db);
|
|
|
|
#endif
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_open(db=%p)\n", db );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return( db );
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
|
|
|
/* Open and close are not reentrant so we need to use locks here */
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout,
|
|
|
|
"==>(mdbm)ldbm_close(db=%p)\n", ldbm );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-03-30 12:39:08 +08:00
|
|
|
mdbm_close( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_close()\n" );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
|
|
|
/* XXX: Not sure if this is re-entrant need to check code, if so
|
|
|
|
* you can leave LOCKS out.
|
|
|
|
*/
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-03-30 12:39:08 +08:00
|
|
|
mdbm_sync( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
#define MAX_MDBM_RETRY 5
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_fetch( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
Datum d;
|
|
|
|
kvpair k;
|
|
|
|
int retry = 0;
|
|
|
|
|
|
|
|
/* This hack is needed because MDBM does not take keys
|
|
|
|
* which begin with NULL when working in the chaining
|
|
|
|
* mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
k.key.dsize = key.dsize + 1;
|
1999-06-12 02:56:28 +08:00
|
|
|
k.key.dptr = malloc(k.key.dsize);
|
1999-03-30 12:39:08 +08:00
|
|
|
*(k.key.dptr) = 'l';
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( (void *)(k.key.dptr + 1), key.dptr, key.dsize );
|
1999-03-30 12:39:08 +08:00
|
|
|
#else
|
|
|
|
k.key = key;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
k.val.dptr = NULL;
|
|
|
|
k.val.dsize = 0;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_RLOCK; */
|
1999-03-30 12:39:08 +08:00
|
|
|
do {
|
|
|
|
d = mdbm_fetch( ldbm, k );
|
|
|
|
|
|
|
|
if ( d.dsize > 0 ) {
|
|
|
|
if ( k.val.dptr != NULL ) {
|
2001-05-29 03:11:29 +08:00
|
|
|
free( k.val.dptr );
|
1999-03-30 12:39:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (k.val.dptr = malloc( d.dsize )) != NULL ) {
|
|
|
|
k.val.dsize = d.dsize;
|
|
|
|
d = mdbm_fetch( ldbm, k );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
d.dsize = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}/* if ( d.dsize > 0 ) */
|
|
|
|
} while ((d.dsize > k.val.dsize) && (++retry < MAX_MDBM_RETRY));
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_RUNLOCK; */
|
1999-03-30 12:39:08 +08:00
|
|
|
|
1999-06-12 02:56:28 +08:00
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
free(k.key.dptr);
|
|
|
|
#endif
|
|
|
|
|
1999-03-30 12:39:08 +08:00
|
|
|
return d;
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
Datum int_key; /* Internal key */
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout,
|
|
|
|
"==>(mdbm)ldbm_store(db=%p, key(dptr=%p,sz=%d), data(dptr=%p,sz=%d), flags=%x)\n",
|
|
|
|
ldbm, key.dptr, key.dsize, data.dptr, data.dsize, flags );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_WLOCK; */
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
int_key.dsize = key.dsize + 1;
|
1999-06-12 02:56:28 +08:00
|
|
|
int_key.dptr = malloc( int_key.dsize );
|
1999-03-30 12:39:08 +08:00
|
|
|
*(int_key.dptr) = 'l'; /* Must not be NULL !*/
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( (void *)(int_key.dptr + 1), key.dptr, key.dsize );
|
1999-03-30 12:39:08 +08:00
|
|
|
#else
|
|
|
|
int_key = key;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = mdbm_store( ldbm, int_key, data, flags );
|
|
|
|
if ( flags & LDBM_SYNC ) {
|
|
|
|
mdbm_sync( ldbm );
|
|
|
|
}
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_WUNLOCK; */
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_store(rc=%d)\n", rc );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
1999-06-12 02:56:28 +08:00
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
free(int_key.dptr);
|
|
|
|
#endif
|
|
|
|
|
1999-03-30 12:39:08 +08:00
|
|
|
return( rc );
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_delete( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
Datum int_key;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_WLOCK; */
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
int_key.dsize = key.dsize + 1;
|
1999-06-12 02:56:28 +08:00
|
|
|
int_key.dptr = malloc(int_key.dsize);
|
1999-03-30 12:39:08 +08:00
|
|
|
*(int_key.dptr) = 'l';
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( (void *)(int_key.dptr + 1), key.dptr, key.dsize );
|
1999-03-30 12:39:08 +08:00
|
|
|
#else
|
|
|
|
int_key = key;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = mdbm_delete( ldbm, int_key );
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_WUNLOCK; */
|
1999-06-12 02:56:28 +08:00
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
free(int_key.dptr);
|
|
|
|
#endif
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
return( rc );
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
static Datum
|
|
|
|
ldbm_get_next( LDBM ldbm, kvpair (*fptr)(MDBM *, kvpair) )
|
|
|
|
{
|
|
|
|
kvpair out;
|
|
|
|
kvpair in;
|
|
|
|
Datum ret;
|
|
|
|
size_t sz = MDBM_PAGE_SIZE(ldbm);
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
int delta = 1;
|
|
|
|
#else
|
|
|
|
int delta = 0;
|
|
|
|
#endif
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_RLOCK; */
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
in.key.dsize = sz; /* Assume first key in one pg */
|
1999-06-12 02:56:28 +08:00
|
|
|
in.key.dptr = malloc(sz);
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
in.val.dptr = NULL; /* Don't need data just key */
|
|
|
|
in.val.dsize = 0;
|
|
|
|
|
|
|
|
ret.dptr = NULL;
|
|
|
|
ret.dsize = NULL;
|
|
|
|
|
|
|
|
out = fptr( ldbm, in );
|
|
|
|
|
|
|
|
if (out.key.dsize > 0) {
|
2001-05-29 03:11:29 +08:00
|
|
|
ret.dsize = out.key.dsize - delta;
|
1999-03-30 12:39:08 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
if ((ret.dptr = (char *)malloc(ret.dsize)) == NULL) {
|
|
|
|
ret.dsize = 0;
|
|
|
|
ret.dptr = NULL;
|
1999-03-30 12:39:08 +08:00
|
|
|
|
2001-05-29 03:11:29 +08:00
|
|
|
} else {
|
|
|
|
AC_MEMCPY(ret.dptr, (void *)(out.key.dptr + delta),
|
|
|
|
ret.dsize );
|
1999-03-30 12:39:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
/* LDBM_RUNLOCK; */
|
1999-06-12 02:56:28 +08:00
|
|
|
|
|
|
|
free(in.key.dptr);
|
1999-03-30 12:39:08 +08:00
|
|
|
return ret;
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
|
1999-03-30 12:39:08 +08:00
|
|
|
{
|
|
|
|
return ldbm_get_next( ldbm, mdbm_first );
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
|
1999-03-30 12:39:08 +08:00
|
|
|
{
|
|
|
|
/* XXX:
|
2001-05-29 03:11:29 +08:00
|
|
|
* don't know if this will affect the LDAP server operation
|
1999-03-30 12:39:08 +08:00
|
|
|
* but mdbm cannot take and input key.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return ldbm_get_next( ldbm, mdbm_next );
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_errno( LDBM ldbm )
|
|
|
|
{
|
|
|
|
/* XXX: best we can do with current mdbm interface */
|
|
|
|
return( errno );
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
1999-03-30 12:39:08 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#elif defined( HAVE_NDBM )
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
1999-03-30 12:39:08 +08:00
|
|
|
* if no gdbm or mdbm, fall back to using ndbm, the standard unix thing *
|
1998-08-09 08:43:13 +08:00
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
LDBM
|
2001-06-22 02:54:56 +08:00
|
|
|
ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM ldbm;
|
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
ldbm = dbm_open( name, rw, mode );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
|
|
|
return( ldbm );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
dbm_close( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_fetch( LDBM ldbm, Datum key )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
d = ldbm_datum_dup( ldbm, dbm_fetch( ldbm, key ) );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return d;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
int rc;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
rc = dbm_store( ldbm, key, data, flags );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_delete( LDBM ldbm, Datum key )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
int rc;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
rc = dbm_delete( ldbm, key );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
d = dbm_firstkey( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return d;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1999-08-18 03:00:59 +08:00
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
d = dbm_nextkey( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_RUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return d;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_errno( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
int err;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WLOCK;
|
1999-01-27 04:55:54 +08:00
|
|
|
err = dbm_error( ldbm );
|
2001-10-02 12:13:47 +08:00
|
|
|
LDBM_WUNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
return err;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ndbm */
|
1998-10-25 10:02:31 +08:00
|
|
|
#endif /* ldbm */
|