1999-08-31 09:17:01 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-12-29 03:51:35 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
|
1998-12-29 03:51:35 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2001-05-29 11:29:53 +08:00
|
|
|
* 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.
|
1998-12-29 03:51:35 +08:00
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
/* ldbm.h - ldap dbm compatibility routine header file */
|
|
|
|
|
|
|
|
#ifndef _LDBM_H_
|
|
|
|
#define _LDBM_H_
|
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
#include <ldap_cdefs.h>
|
2003-11-04 08:45:41 +08:00
|
|
|
#include <ac/string.h>
|
1999-01-27 04:55:54 +08:00
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
/* dummy DB_ENV for non Berkeley DB */
|
|
|
|
#if !defined( LDBM_USE_DBBTREE ) && !defined( LDBM_USE_DBHASH )
|
|
|
|
# define DB_ENV void
|
|
|
|
#endif
|
|
|
|
|
1999-09-24 03:49:20 +08:00
|
|
|
#if defined( LDBM_USE_DBBTREE ) || defined( LDBM_USE_DBHASH )
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
1999-09-24 03:49:20 +08:00
|
|
|
* use berkeley db btree or hash package *
|
1998-08-09 08:43:13 +08:00
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <fcntl.h>
|
1998-08-20 08:05:08 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
#ifdef HAVE_DB_185_H
|
1998-08-20 08:05:08 +08:00
|
|
|
# include <db_185.h>
|
|
|
|
#else
|
1999-05-07 09:27:16 +08:00
|
|
|
# ifdef HAVE_DB1_DB_H
|
|
|
|
# include <db1/db.h>
|
|
|
|
# else
|
|
|
|
# include <db.h>
|
|
|
|
# endif
|
2000-05-26 07:14:53 +08:00
|
|
|
#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
|
1998-09-03 08:50:13 +08:00
|
|
|
# endif
|
2001-06-22 02:54:56 +08:00
|
|
|
#else
|
|
|
|
# define DB_ENV void
|
1998-08-20 08:05:08 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
typedef DBT Datum;
|
|
|
|
#define dsize size
|
|
|
|
#define dptr data
|
|
|
|
|
|
|
|
typedef DB *LDBM;
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* for ldbm_open */
|
2000-05-26 04:41:55 +08:00
|
|
|
#if DB_VERSION_MAJOR >= 2
|
1999-08-18 03:00:59 +08:00
|
|
|
typedef DBC LDBMCursor;
|
1999-09-22 01:50:31 +08:00
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
# define LDBM_READER DB_RDONLY
|
|
|
|
# define LDBM_WRITER 0x00000 /* hopefully */
|
2000-05-26 04:41:55 +08:00
|
|
|
# if defined( HAVE_BERKELEY_DB_THREAD )
|
1999-09-22 01:50:31 +08:00
|
|
|
# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD)
|
|
|
|
# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD)
|
|
|
|
# else
|
1999-11-29 08:49:55 +08:00
|
|
|
# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE)
|
|
|
|
# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE)
|
1999-09-22 01:50:31 +08:00
|
|
|
# endif
|
|
|
|
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
2000-02-11 10:05:14 +08:00
|
|
|
typedef void LDBMCursor;
|
1998-09-03 08:50:13 +08:00
|
|
|
# define LDBM_READER O_RDONLY
|
|
|
|
# define LDBM_WRITER O_RDWR
|
|
|
|
# define LDBM_WRCREAT (O_RDWR|O_CREAT)
|
|
|
|
# define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
|
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
LDAP_END_DECL
|
|
|
|
|
1999-09-24 03:49:20 +08:00
|
|
|
/* for ldbm_open */
|
|
|
|
#define LDBM_NOSYNC 0
|
|
|
|
#define LDBM_SYNC 0
|
|
|
|
#define LDBM_LOCKING 0
|
|
|
|
#define LDBM_NOLOCKING 0
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/* for ldbm_insert */
|
|
|
|
#define LDBM_INSERT R_NOOVERWRITE
|
|
|
|
#define LDBM_REPLACE 0
|
|
|
|
|
1999-09-24 03:49:20 +08:00
|
|
|
#ifdef LDBM_USE_DBBTREE
|
|
|
|
# define LDBM_ORDERED 1
|
|
|
|
# define LDBM_SUFFIX ".dbb"
|
|
|
|
# define DB_TYPE DB_BTREE
|
1998-09-03 08:50:13 +08:00
|
|
|
#else
|
1999-09-24 03:49:20 +08:00
|
|
|
# define LDBM_SUFFIX ".dbh"
|
|
|
|
# define DB_TYPE DB_HASH
|
1998-09-03 08:50:13 +08:00
|
|
|
#endif
|
|
|
|
|
1998-11-17 12:07:31 +08:00
|
|
|
#elif defined( HAVE_GDBM )
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
|
|
|
* use gdbm if possible *
|
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
#include <gdbm.h>
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
typedef datum Datum;
|
2000-02-11 10:05:14 +08:00
|
|
|
typedef Datum LDBMCursor;
|
1998-10-25 09:41:42 +08:00
|
|
|
typedef GDBM_FILE LDBM;
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
LDAP_END_DECL
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
/* for ldbm_open */
|
|
|
|
#define LDBM_READER GDBM_READER
|
|
|
|
#define LDBM_WRITER GDBM_WRITER
|
|
|
|
#define LDBM_WRCREAT GDBM_WRCREAT
|
|
|
|
#define LDBM_NEWDB GDBM_NEWDB
|
1999-09-24 03:49:20 +08:00
|
|
|
|
|
|
|
#ifdef GDBM_FAST
|
|
|
|
#define LDBM_NOSYNC GDBM_FAST
|
|
|
|
#else
|
|
|
|
#define LDBM_NOSYNC 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GDBM_SYNC
|
|
|
|
#define LDBM_SYNC GDBM_SYNC
|
|
|
|
#else
|
|
|
|
#define LDBM_SYNC 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LDBM_LOCKING 0
|
|
|
|
#ifdef GDBM_NOLOCK
|
|
|
|
#define LDBM_NOLOCKING GDBM_NOLOCK
|
1999-12-18 02:43:02 +08:00
|
|
|
#else
|
|
|
|
#define LDBM_NOLOCKING 0
|
1999-09-24 03:49:20 +08:00
|
|
|
#endif
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#define LDBM_SUFFIX ".gdbm"
|
|
|
|
|
|
|
|
/* for ldbm_insert */
|
|
|
|
#define LDBM_INSERT GDBM_INSERT
|
|
|
|
#define LDBM_REPLACE GDBM_REPLACE
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-30 12:39:41 +08:00
|
|
|
#elif defined( HAVE_MDBM )
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
|
|
|
* use mdbm if possible *
|
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
#include <mdbm.h>
|
|
|
|
|
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
|
|
|
typedef datum Datum;
|
1999-08-18 03:00:59 +08:00
|
|
|
typedef int LDBMCursor;
|
1999-03-30 12:39:41 +08:00
|
|
|
typedef MDBM *LDBM;
|
|
|
|
|
|
|
|
LDAP_END_DECL
|
2001-12-24 11:49:54 +08:00
|
|
|
|
1999-03-30 12:39:41 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
/* for ldbm_open */
|
|
|
|
#define LDBM_READER O_RDONLY
|
|
|
|
#define LDBM_WRITER O_RDWR
|
|
|
|
#define LDBM_WRCREAT (O_RDWR|O_CREAT)
|
|
|
|
#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
|
1999-09-24 03:49:20 +08:00
|
|
|
|
|
|
|
#define LDBM_SYNC 0
|
|
|
|
#define LDBM_NOSYNC 0
|
|
|
|
#define LDBM_LOCKING 0
|
|
|
|
#define LDBM_NOLOCKING 0
|
1999-03-30 12:39:41 +08:00
|
|
|
|
|
|
|
#define LDBM_SUFFIX ".mdbm"
|
|
|
|
|
|
|
|
/* for ldbm_insert */
|
|
|
|
#define LDBM_INSERT MDBM_INSERT
|
|
|
|
#define LDBM_REPLACE MDBM_REPLACE
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-11-17 12:07:31 +08:00
|
|
|
#elif defined( HAVE_NDBM )
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* *
|
|
|
|
* if none of the above use ndbm, the standard unix thing *
|
|
|
|
* *
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
#include <ndbm.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
typedef datum Datum;
|
1999-08-18 03:00:59 +08:00
|
|
|
typedef int LDBMCursor;
|
1998-08-09 08:43:13 +08:00
|
|
|
typedef DBM *LDBM;
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
LDAP_END_DECL
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* for ldbm_open */
|
|
|
|
#define LDBM_READER O_RDONLY
|
|
|
|
#define LDBM_WRITER O_WRONLY
|
|
|
|
#define LDBM_WRCREAT (O_RDWR|O_CREAT)
|
|
|
|
#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
|
1999-09-24 03:49:20 +08:00
|
|
|
|
|
|
|
#define LDBM_NOSYNC 0
|
|
|
|
#define LDBM_SYNC 0
|
|
|
|
#define LDBM_NOLOCK 0
|
|
|
|
#define LDBM_SYNC 0
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#define LDBM_SUFFIX ".ndbm"
|
|
|
|
|
|
|
|
/* for ldbm_insert */
|
|
|
|
#define LDBM_INSERT DBM_INSERT
|
|
|
|
#define LDBM_REPLACE DBM_REPLACE
|
|
|
|
|
1998-11-17 12:07:31 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
2000-09-12 02:46:34 +08:00
|
|
|
LDAP_LDBM_F (int) ldbm_initialize( const char * );
|
2000-06-19 03:48:07 +08:00
|
|
|
LDAP_LDBM_F (int) ldbm_shutdown( void );
|
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
LDAP_LDBM_F (DB_ENV*) ldbm_initialize_env(const char *, int dbcachesize, int *envdirok);
|
|
|
|
LDAP_LDBM_F (void) ldbm_shutdown_env(DB_ENV *);
|
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LDAP_LDBM_F (int) ldbm_errno( LDBM ldbm );
|
2001-06-22 02:54:56 +08:00
|
|
|
LDAP_LDBM_F (LDBM) ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize );
|
2000-06-19 03:48:07 +08:00
|
|
|
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 );
|
|
|
|
|
|
|
|
LDAP_LDBM_F (Datum) ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor );
|
|
|
|
LDAP_LDBM_F (Datum) ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor );
|
1998-12-30 01:28:45 +08:00
|
|
|
|
|
|
|
/* initialization of Datum structures */
|
2000-05-26 04:41:55 +08:00
|
|
|
#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2)
|
2000-06-19 03:48:07 +08:00
|
|
|
LDAP_LDBM_F (void *) ldbm_malloc( size_t size );
|
2000-06-09 14:24:10 +08:00
|
|
|
# define ldbm_datum_init(d) ((void)memset(&(d), '\0', sizeof(Datum)))
|
1998-12-30 01:28:45 +08:00
|
|
|
#else
|
|
|
|
# define ldbm_datum_init(d) ((void)0)
|
2000-05-26 04:41:55 +08:00
|
|
|
#endif /* HAVE_BERKELEY_DB */
|
1998-12-30 01:28:45 +08:00
|
|
|
|
1999-01-27 04:55:54 +08:00
|
|
|
LDAP_END_DECL
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#endif /* _ldbm_h_ */
|