1998-08-09 08:43:13 +08:00
|
|
|
/* ldbm.c - ldap dbm compatibility routines */
|
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
/* Patched for Berkeley DB version 2.0; /KSp; 98/02/23
|
|
|
|
*
|
1999-01-05 23:40:58 +08:00
|
|
|
* - DB version 2.6.4b ; 1998/12/28, /KSp
|
1998-09-03 08:50:13 +08:00
|
|
|
* - DB_DBT_MALLOC ; 1998/03/22, /KSp
|
1999-01-05 23:40:58 +08:00
|
|
|
* - basic implementation; 1998/02/23, /KSp
|
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>
|
|
|
|
#include <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 );
|
1999-03-30 00:01:59 +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
|
|
|
|
1998-09-03 08:50: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;
|
|
|
|
if ( (dup.dptr = (char *) malloc( data.dsize )) != NULL )
|
|
|
|
memcpy( dup.dptr, data.dptr, data.dsize );
|
|
|
|
|
|
|
|
return( dup );
|
|
|
|
}
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
static int ldbm_initialized = 0;
|
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
#ifndef HAVE_BERKELEY_DB2
|
|
|
|
/* Everything but DB2 is non-reentrant */
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
int ldbm_initialize( void )
|
1999-02-05 01:41:19 +08:00
|
|
|
{
|
1999-02-05 17:03:47 +08:00
|
|
|
if(ldbm_initialized++) return 1;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_init( &ldbm_big_mutex );
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ldbm_shutdown( void )
|
|
|
|
{
|
|
|
|
if( !ldbm_initialized ) return 1;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_destroy( &ldbm_big_mutex );
|
|
|
|
|
|
|
|
return 0;
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
void *
|
|
|
|
ldbm_malloc( size_t size )
|
|
|
|
{
|
|
|
|
return( calloc( 1, size ));
|
|
|
|
}
|
|
|
|
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef HAVE_SYSLOG
|
1999-05-19 09:12:33 +08:00
|
|
|
#ifdef HAVE_SYSLOG_H
|
1999-03-02 06:37:05 +08:00
|
|
|
#include "syslog.h"
|
|
|
|
#else
|
|
|
|
/* quick hack */
|
|
|
|
#define LOG_INFO 1
|
|
|
|
extern int syslog(int, char*, ...);
|
|
|
|
#endif
|
1999-05-19 09:12:33 +08:00
|
|
|
#endif /* HAVE_SYSLOG */
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
static void
|
|
|
|
ldbm_db_errcall( const char *prefix, char *message )
|
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
#ifdef HAVE_SYSLOG
|
1999-02-05 01:41:19 +08:00
|
|
|
syslog( LOG_INFO, "ldbm_db_errcall(): %s %s", prefix, message );
|
1999-04-02 00:06:08 +08:00
|
|
|
#endif
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* a dbEnv for BERKELEYv2 */
|
1999-03-05 19:24:42 +08:00
|
|
|
static DB_ENV ldbm_Env_internal;
|
|
|
|
DB_ENV *ldbm_Env = NULL;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
/* Berkeley DB 2.x is reentrant */
|
1999-02-05 01:41:19 +08:00
|
|
|
#define LDBM_LOCK ((void)0)
|
|
|
|
#define LDBM_UNLOCK ((void)0)
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
int ldbm_initialize( void )
|
1999-02-05 01:41:19 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int envFlags;
|
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
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
memset( &ldbm_Env_internal, 0, sizeof( DB_ENV ));
|
|
|
|
ldbm_Env = &ldbm_Env_internal;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_Env->db_errcall = ldbm_db_errcall;
|
|
|
|
ldbm_Env->db_errpfx = "==>";
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
envFlags = DB_CREATE | DB_THREAD;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
if ( ( err = db_appinit( NULL, NULL, ldbm_Env, envFlags )) ) {
|
1999-02-05 01:41:19 +08:00
|
|
|
char error[BUFSIZ];
|
|
|
|
|
|
|
|
if ( err < 0 ) {
|
|
|
|
sprintf( error, "%ld\n", (long) err );
|
|
|
|
} else {
|
|
|
|
sprintf( error, "%s\n", strerror( err ));
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:54:33 +08:00
|
|
|
#ifdef HAVE_SYSLOG
|
1999-02-05 01:41:19 +08:00
|
|
|
syslog( LOG_INFO,
|
|
|
|
"ldbm_initialize(): FATAL error in db_appinit() : %s\n",
|
|
|
|
error );
|
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
|
|
|
}
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ldbm_shutdown( void )
|
|
|
|
{
|
|
|
|
if( !ldbm_initialized ) return 1;
|
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
db_appexit( ldbm_Env );
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return 0;
|
1999-02-02 01:37:43 +08:00
|
|
|
}
|
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
1999-02-05 01:41:19 +08:00
|
|
|
ldbm_open( char *name, int rw, int mode, int dbcachesize )
|
1999-01-27 04:55:54 +08:00
|
|
|
{
|
|
|
|
LDBM ret = NULL;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1999-02-05 01:41:19 +08:00
|
|
|
DB_INFO dbinfo;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
memset( &dbinfo, 0, sizeof( dbinfo ));
|
1999-03-05 19:24:42 +08:00
|
|
|
if (( ldbm_Env == NULL ) || ( ldbm_Env->mp_info == NULL ))
|
1999-02-08 19:42:14 +08:00
|
|
|
dbinfo.db_cachesize = dbcachesize;
|
1998-09-03 08:50:13 +08:00
|
|
|
dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE;
|
|
|
|
dbinfo.db_malloc = ldbm_malloc;
|
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
LDBM_LOCK;
|
1999-03-05 19:24:42 +08:00
|
|
|
(void) db_open( name, DB_TYPE, rw, mode, ldbm_Env, &dbinfo, &ret );
|
1999-02-05 01:41:19 +08:00
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
ret = dbopen( name, rw, mode, DB_TYPE, info );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
(*ldbm->close)( ldbm, 0 );
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
(*ldbm->close)( ldbm );
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
(*ldbm->sync)( ldbm, 0 );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_fetch( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
Datum data;
|
|
|
|
int rc;
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( data );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
|
|
|
data.flags = DB_DBT_MALLOC;
|
|
|
|
|
|
|
|
if ( (rc = (*ldbm->get)( ldbm, NULL, &key, &data, 0 )) != 0 ) {
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( ldbm, data );
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +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 {
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
data.dptr = NULL;
|
|
|
|
data.dsize = 0;
|
|
|
|
}
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
rc = (*ldbm->put)( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC );
|
|
|
|
rc = (-1 ) * rc;
|
|
|
|
#else
|
1998-08-09 08:43:13 +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 )
|
|
|
|
(*ldbm->sync)( ldbm, 0 );
|
1999-01-27 04:55:54 +08:00
|
|
|
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_delete( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
rc = (*ldbm->del)( ldbm, NULL, &key, 0 );
|
|
|
|
rc = (-1 ) * rc;
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
rc = (*ldbm->del)( ldbm, &key, 0 );
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
(*ldbm->sync)( ldbm, 0 );
|
1999-01-27 04:55:54 +08:00
|
|
|
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
ldbm_firstkey( LDBM ldbm, DBC **dbch )
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
ldbm_firstkey( LDBM ldbm )
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
Datum key, data;
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
DBC *dbci;
|
|
|
|
|
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;
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
/* acquire a cursor for the DB */
|
1998-12-30 01:28:45 +08:00
|
|
|
|
|
|
|
# if defined( DB_VERSION_MAJOR ) && defined( DB_VERSION_MINOR ) && \
|
|
|
|
DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 6
|
|
|
|
|
1999-02-05 01:41:19 +08:00
|
|
|
if ( (*ldbm->cursor)( ldbm, NULL, &dbci ))
|
1998-12-30 01:28:45 +08:00
|
|
|
|
|
|
|
# else
|
1999-02-05 01:41:19 +08:00
|
|
|
if ( (*ldbm->cursor)( ldbm, NULL, &dbci, 0 ))
|
1998-12-30 01:28:45 +08:00
|
|
|
# endif
|
1999-02-05 01:41:19 +08:00
|
|
|
{
|
1999-03-05 19:24:42 +08:00
|
|
|
key.dptr = NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
return( key );
|
|
|
|
} else {
|
|
|
|
*dbch = dbci;
|
|
|
|
if ( (*dbci->c_get)( dbci, &key, &data, DB_NEXT ) == 0 ) {
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( ldbm, data );
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
1999-03-06 12:15:18 +08:00
|
|
|
else {
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
1999-03-02 06:37:05 +08:00
|
|
|
int rc;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( (rc = (*ldbm->seq)( ldbm, &key, &data, R_FIRST )) == 0 ) {
|
|
|
|
key = ldbm_datum_dup( ldbm, key );
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
|
|
|
else {
|
1999-03-06 12:15:18 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
key.dptr = NULL;
|
|
|
|
key.dsize = 0;
|
|
|
|
}
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key )
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
Datum data;
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
if ( (*dbcp->c_get)( dbcp, &key, &data, DB_NEXT ) == 0 ) {
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( ldbm, data );
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
1999-03-06 12:15:18 +08:00
|
|
|
else {
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
1999-03-02 06:37:05 +08:00
|
|
|
int rc;
|
1999-01-27 04:55:54 +08:00
|
|
|
|
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( (rc = (*ldbm->seq)( ldbm, &key, &data, R_NEXT )) == 0 ) {
|
|
|
|
key = ldbm_datum_dup( ldbm, key );
|
1999-02-05 01:41:19 +08:00
|
|
|
}
|
|
|
|
else {
|
1999-03-06 12:15:18 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
key.dptr = NULL;
|
|
|
|
key.dsize = 0;
|
|
|
|
}
|
1999-01-27 04:55:54 +08:00
|
|
|
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_errno( LDBM ldbm )
|
|
|
|
{
|
|
|
|
return( errno );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
ldbm_open( char *name, int rw, int mode, int dbcachesize )
|
|
|
|
{
|
|
|
|
LDBM db;
|
1999-04-20 01:56:48 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
|
|
|
struct stat st;
|
|
|
|
#endif
|
1998-10-25 10:02:31 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
if ( (db = gdbm_open( name, 0, rw | GDBM_FAST, mode, 0 )) == NULL ) {
|
1999-02-05 01:41:19 +08:00
|
|
|
LDBM_UNLOCK;
|
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 ) {
|
|
|
|
dbcachesize = (dbcachesize / st.st_blksize);
|
|
|
|
gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
|
|
|
|
}
|
1999-04-17 11:28:20 +08:00
|
|
|
#else
|
|
|
|
dbcachesize = (dbcachesize / 4096);
|
|
|
|
gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
|
|
|
|
#endif
|
1998-10-25 10:02:31 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
return( db );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
gdbm_close( ldbm );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
gdbm_sync( ldbm );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
d = gdbm_fetch( ldbm, key );
|
|
|
|
LDBM_UNLOCK;
|
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;
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
rc = gdbm_store( ldbm, key, data, flags & ~LDBM_SYNC );
|
|
|
|
if ( flags & LDBM_SYNC )
|
|
|
|
gdbm_sync( ldbm );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
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;
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-10-25 10:02:31 +08:00
|
|
|
rc = gdbm_delete( ldbm, key );
|
|
|
|
gdbm_sync( ldbm );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1998-10-25 10:02:31 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_firstkey( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
d = gdbm_firstkey( ldbm );
|
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1999-02-03 04:36:10 +08:00
|
|
|
d = gdbm_nextkey( ldbm, key );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
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_errno( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
int err;
|
1999-02-05 01:41:19 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1999-02-05 01:41:19 +08:00
|
|
|
err = gdbm_errno;
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
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 */
|
|
|
|
|
|
|
|
#include <alloca.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* #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
|
|
|
|
ldbm_open( char *name, int rw, int mode, int dbcachesize )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
LDBM_LOCK; /* We need locking here, this is the only non-thread
|
|
|
|
* safe function we have.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( (db = mdbm_open( name, rw, mode, MDBM_PG_SZ )) == NULL ) {
|
|
|
|
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
#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
|
|
|
|
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_open(db=%p)\n", db );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return( db );
|
|
|
|
|
|
|
|
}/* LDBM ldbm_open() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
LDBM_LOCK;
|
|
|
|
mdbm_close( ldbm );
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_close()\n" );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}/* void ldbm_close() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_sync( LDBM ldbm )
|
|
|
|
{
|
|
|
|
|
|
|
|
/* XXX: Not sure if this is re-entrant need to check code, if so
|
|
|
|
* you can leave LOCKS out.
|
|
|
|
*/
|
|
|
|
|
|
|
|
LDBM_LOCK;
|
|
|
|
mdbm_sync( ldbm );
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
|
|
|
}/* void ldbm_sync() */
|
|
|
|
|
|
|
|
|
|
|
|
#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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* LDBM_LOCK; */
|
|
|
|
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
k.key.dsize = key.dsize + 1;
|
|
|
|
k.key.dptr = alloca(k.key.dsize);
|
|
|
|
*(k.key.dptr) = 'l';
|
|
|
|
memcpy( (void *)(k.key.dptr + 1), key.dptr, key.dsize );
|
|
|
|
#else
|
|
|
|
k.key = key;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
k.val.dptr = NULL;
|
|
|
|
k.val.dsize = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
d = mdbm_fetch( ldbm, k );
|
|
|
|
|
|
|
|
if ( d.dsize > 0 ) {
|
|
|
|
|
|
|
|
if ( k.val.dptr != NULL ) {
|
|
|
|
|
|
|
|
free( k.val.dptr );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
/* LDBM_UNLOCK; */
|
|
|
|
|
|
|
|
return d;
|
|
|
|
|
|
|
|
}/* Datum ldbm_fetch() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/* LDBM_LOCK; */
|
|
|
|
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
int_key.dsize = key.dsize + 1;
|
|
|
|
int_key.dptr = alloca( int_key.dsize );
|
|
|
|
*(int_key.dptr) = 'l'; /* Must not be NULL !*/
|
|
|
|
memcpy( (void *)(int_key.dptr + 1), key.dptr, key.dsize );
|
|
|
|
#else
|
|
|
|
int_key = key;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = mdbm_store( ldbm, int_key, data, flags );
|
|
|
|
if ( flags & LDBM_SYNC ) {
|
|
|
|
mdbm_sync( ldbm );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LDBM_UNLOCK; */
|
|
|
|
|
|
|
|
#ifdef MDBM_DEBUG
|
|
|
|
fprintf( stdout, "<==(mdbm)ldbm_store(rc=%d)\n", rc );
|
|
|
|
fflush( stdout );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
|
|
|
|
}/* int ldbm_store() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_delete( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
Datum int_key;
|
|
|
|
|
|
|
|
/* LDBM_LOCK; */
|
|
|
|
|
|
|
|
#ifdef NO_NULL_KEY
|
|
|
|
int_key.dsize = key.dsize + 1;
|
|
|
|
int_key.dptr = alloca(int_key.dsize);
|
|
|
|
*(int_key.dptr) = 'l';
|
|
|
|
memcpy( (void *)(int_key.dptr + 1), key.dptr, key.dsize );
|
|
|
|
#else
|
|
|
|
int_key = key;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = mdbm_delete( ldbm, int_key );
|
|
|
|
|
|
|
|
/* LDBM_UNLOCK; */
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
|
|
|
|
}/* int ldbm_delete() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/* LDBM_LOCK; */
|
|
|
|
|
|
|
|
in.key.dsize = sz; /* Assume first key in one pg */
|
|
|
|
in.key.dptr = alloca(sz);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
ret.dsize = out.key.dsize - delta;
|
|
|
|
if ((ret.dptr = (char *)malloc(ret.dsize)) == NULL) {
|
|
|
|
|
|
|
|
ret.dsize = 0;
|
|
|
|
ret.dptr = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
memcpy(ret.dptr, (void *)(out.key.dptr + delta),
|
|
|
|
ret.dsize );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LDBM_UNLOCK; */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}/* static Datum ldbm_get_next() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_firstkey( LDBM ldbm )
|
|
|
|
{
|
|
|
|
|
|
|
|
return ldbm_get_next( ldbm, mdbm_first );
|
|
|
|
|
|
|
|
}/* Datum ldbm_firstkey() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key )
|
|
|
|
{
|
|
|
|
|
|
|
|
/* XXX:
|
|
|
|
* don't know if this will affect the LDAP server opertaion
|
|
|
|
* but mdbm cannot take and input key.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
ldbm_open( char *name, int rw, int mode, int dbcachesize )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM ldbm;
|
|
|
|
|
|
|
|
LDBM_LOCK;
|
|
|
|
ldbm = dbm_open( name, rw, mode );
|
|
|
|
LDBM_UNLOCK;
|
|
|
|
|
|
|
|
return( ldbm );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_close( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
1998-08-09 08:43:13 +08:00
|
|
|
dbm_close( ldbm );
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
d = ldbm_datum_dup( ldbm, dbm_fetch( ldbm, key ) );
|
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
rc = dbm_store( ldbm, key, data, flags );
|
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
rc = dbm_delete( ldbm, key );
|
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
ldbm_firstkey( LDBM ldbm )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
d = dbm_firstkey( ldbm );
|
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
ldbm_nextkey( LDBM ldbm, Datum key )
|
|
|
|
{
|
1999-01-27 04:55:54 +08:00
|
|
|
Datum d;
|
1999-02-02 01:37:43 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
d = dbm_nextkey( ldbm );
|
|
|
|
LDBM_UNLOCK;
|
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
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDBM_LOCK;
|
|
|
|
err = dbm_error( ldbm );
|
|
|
|
LDBM_UNLOCK;
|
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 */
|