ldbm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* ldbm.h - ldap dbm compatibility routine header file */
  42. #error "Hmm, shoudn't be here"
  43. /* Deprecated header, why are you including it ??? */
  44. #if 1
  45. #ifndef _LDBM_H_
  46. #define _LDBM_H_
  47. /* define LDAP_USE_DB185 to get the old db library, otherwise, use db2.0 */
  48. #ifndef LDAP_USE_DB185
  49. #define LDAP_USE_DB20
  50. #endif
  51. #ifdef LDBM_USE_GDBM
  52. /*****************************************************************
  53. * *
  54. * use gdbm if possible *
  55. * *
  56. *****************************************************************/
  57. #include <gdbm.h>
  58. typedef datum Datum;
  59. typedef GDBM_FILE LDBM;
  60. extern gdbm_error gdbm_errno;
  61. /* for ldbm_open */
  62. #define LDBM_READER GDBM_READER
  63. #define LDBM_WRITER GDBM_WRITER
  64. #define LDBM_WRCREAT GDBM_WRCREAT
  65. #define LDBM_NEWDB GDBM_NEWDB
  66. #define LDBM_FAST GDBM_FAST
  67. #define LDBM_SUFFIX ".gdbm"
  68. /* for ldbm_insert */
  69. #define LDBM_INSERT GDBM_INSERT
  70. #define LDBM_REPLACE GDBM_REPLACE
  71. #define LDBM_SYNC 0x80000000
  72. #else /* end of gdbm */
  73. #ifdef LDBM_USE_DBHASH
  74. /*****************************************************************
  75. * *
  76. * use berkeley db hash package *
  77. * *
  78. *****************************************************************/
  79. #include <sys/types.h>
  80. #include <limits.h>
  81. #include <fcntl.h>
  82. #include <errno.h>
  83. #include <db.h>
  84. typedef DBT Datum;
  85. #define dsize size
  86. #define dptr data
  87. typedef DB *LDBM;
  88. #define DB_TYPE DB_HASH
  89. /* for ldbm_open */
  90. #define LDBM_READER O_RDONLY
  91. #define LDBM_WRITER O_RDWR
  92. #define LDBM_WRCREAT (O_RDWR|O_CREAT)
  93. #define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
  94. #define LDBM_FAST 0
  95. #define LDBM_SUFFIX ".dbh"
  96. /* for ldbm_insert */
  97. #define LDBM_INSERT R_NOOVERWRITE
  98. #define LDBM_REPLACE 0
  99. #define LDBM_SYNC 0x80000000
  100. #else /* end of db hash */
  101. #ifdef LDBM_USE_DBBTREE
  102. /*****************************************************************
  103. * *
  104. * use berkeley db btree package *
  105. * *
  106. *****************************************************************/
  107. #ifndef LDAP_USE_DB20 /* old-db needed us to include these system headers first */
  108. #include <sys/types.h>
  109. #include <limits.h>
  110. #include <fcntl.h>
  111. #include <errno.h>
  112. #endif
  113. #ifdef HPUX11
  114. #define __BIT_TYPES_DEFINED__
  115. typedef unsigned char u_int8_t;
  116. typedef unsigned int u_int32_t;
  117. typedef unsigned short u_int16_t;
  118. #endif
  119. #include <db.h>
  120. #define DB_TYPE DB_BTREE
  121. #define LDBM_ORDERED 1
  122. #ifdef LDAP_USE_DB20
  123. /* pull in parts of the new interface , this comes from dblayer.h */
  124. typedef struct _tag_dblayer_session{
  125. DB_ENV db_env;
  126. } *dblayer_session, dblayer_session_struct;
  127. /* for ldbm_insert */
  128. #define LDBM_INSERT DB_NOOVERWRITE
  129. #define LDBM_REPLACE 0 /* Db2.0 default is to replace */
  130. #define LDBM_SYNC 0x80000000
  131. typedef DBT Datum;
  132. #define dsize size
  133. #define dptr data
  134. typedef struct _ldbm {
  135. DB *pReal_DB;
  136. DBC *pCursor;
  137. } _ldbmstruct, *LDBM;
  138. /* for ldbm_open */
  139. #define LDBM_READER DB_RDONLY
  140. #define LDBM_WRITER 0
  141. #define LDBM_WRCREAT DB_CREATE
  142. #define LDBM_NEWDB (DB_TRUNCATE | DB_CREATE)
  143. #define LDBM_FAST 0
  144. #define LDBM_SUFFIX ".db2"
  145. #else /* DB 1.85 */
  146. /* for ldbm_insert */
  147. #define LDBM_INSERT R_NOOVERWRITE
  148. #define LDBM_REPLACE 0
  149. #define LDBM_SYNC 0x80000000
  150. typedef DBT Datum;
  151. #define dsize size
  152. #define dptr data
  153. typedef DB *LDBM;
  154. /* for ldbm_open */
  155. #define LDBM_READER O_RDONLY
  156. #define LDBM_WRITER O_RDWR
  157. #define LDBM_WRCREAT (O_RDWR|O_CREAT)
  158. #define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
  159. #define LDBM_FAST 0
  160. #define LDBM_SUFFIX ".dbb"
  161. #endif /* LDAP_USE_DB20 */
  162. #else /* end of db btree */
  163. #ifdef LDBM_USE_NDBM
  164. /*****************************************************************
  165. * *
  166. * if none of the above use ndbm, the standard unix thing *
  167. * *
  168. *****************************************************************/
  169. #include <ndbm.h>
  170. #ifndef O_RDONLY
  171. #include <fcntl.h>
  172. #endif
  173. typedef datum Datum;
  174. typedef DBM *LDBM;
  175. /* for ldbm_open */
  176. #define LDBM_READER O_RDONLY
  177. #define LDBM_WRITER O_WRONLY
  178. #define LDBM_WRCREAT (O_RDWR|O_CREAT)
  179. #define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
  180. #define LDBM_FAST 0
  181. #define LDBM_SUFFIX ".ndbm"
  182. /* for ldbm_insert */
  183. #define LDBM_INSERT DBM_INSERT
  184. #define LDBM_REPLACE DBM_REPLACE
  185. #define LDBM_SYNC 0
  186. #else /* end of ndbm */
  187. #ifdef LDBM_USE_CISAM
  188. /*****************************************************************
  189. * *
  190. * use CISAM db package *
  191. * *
  192. *****************************************************************/
  193. #include <sys/types.h>
  194. #include <sys/errno.h>
  195. #include <limits.h>
  196. #include <fcntl.h>
  197. #include "isam.h"
  198. extern int errno;
  199. struct datum {
  200. void *dptr; /* data */
  201. size_t dsize; /* data length */
  202. };
  203. typedef struct datum Datum;
  204. struct ldbm {
  205. int fd; /* all callers expect a ptr */
  206. int cur_recnum; /* for reading sequentially */
  207. };
  208. typedef struct ldbm *LDBM;
  209. /* for ldbm_open */
  210. #define LDBM_READER (ISINPUT | ISVARLEN | ISMANULOCK)
  211. #define LDBM_WRITER (ISINOUT | ISVARLEN | ISMANULOCK)
  212. #define LDBM_WRCREAT (ISINOUT | ISVARLEN | ISMANULOCK | ISEXCLLOCK)
  213. #define LDBM_NEWDB (ISINOUT | ISVARLEN | ISMANULOCK | ISEXCLLOCK)
  214. #define LDBM_FAST 0
  215. #define LDBM_SUFFIX ""
  216. #define LDBM_ORDERED 1
  217. /* for ldbm_insert */
  218. #define LDBM_INSERT 1
  219. #define LDBM_REPLACE 0
  220. #define LDBM_SYNC 0x80000000
  221. #else /* end of cisam */
  222. #ifdef LDBM_USE_TRIO
  223. /*****************************************************************
  224. * *
  225. * use C-Index/II from Trio *
  226. * *
  227. *****************************************************************/
  228. #include <sys/types.h>
  229. #include <sys/errno.h>
  230. #include <limits.h>
  231. #include <fcntl.h>
  232. #include "cndx.h"
  233. #define CRDCREAT 0x100
  234. extern int errno;
  235. struct datum {
  236. void *dptr; /* data */
  237. size_t dsize; /* data length */
  238. };
  239. typedef struct datum Datum;
  240. typedef CFILE *LDBM;
  241. /* for ldbm_open */
  242. #define LDBM_READER (CRDONLY)
  243. #define LDBM_WRITER (CRDWRITE)
  244. #define LDBM_WRCREAT (CRDWRITE | CRDCREAT)
  245. #define LDBM_NEWDB (CRDWRITE | CRDCREAT)
  246. #define LDBM_FAST 0
  247. #define LDBM_SUFFIX ".c2i"
  248. #define LDBM_ORDERED 1
  249. /* for ldbm_insert */
  250. #define LDBM_INSERT 1
  251. #define LDBM_REPLACE 0
  252. #define LDBM_SYNC 0x80000000
  253. #else /* end of trio */
  254. #ifdef LDBM_USE_CTREE
  255. /*****************************************************************
  256. * *
  257. * use Faircom Ctree db package *
  258. * *
  259. *****************************************************************/
  260. #include <sys/types.h>
  261. #include <sys/errno.h>
  262. #include <limits.h>
  263. #include <fcntl.h>
  264. #include "ctstdr.h"
  265. #include "ctoptn.h"
  266. #include "ctaerr.h"
  267. #include "ctdecl.h"
  268. #include "cterrc.h"
  269. extern int errno;
  270. struct datum {
  271. void *dptr; /* data */
  272. size_t dsize; /* data length */
  273. };
  274. typedef struct datum Datum;
  275. typedef IFIL *LDBM;
  276. /* for ldbm_open */
  277. #define LDBM_READER 0
  278. #define LDBM_WRITER 0
  279. #define LDBM_WRCREAT 1
  280. #define LDBM_NEWDB 1
  281. #define LDBM_FAST 0
  282. #define LDBM_SUFFIX ""
  283. #define LDBM_ORDERED 1
  284. /* for ldbm_insert */
  285. #define LDBM_INSERT 1
  286. #define LDBM_REPLACE 0
  287. #define LDBM_SYNC 0x80000000
  288. #endif /* ctree */
  289. #endif /* trio */
  290. #endif /* cisam */
  291. #endif /* ndbm */
  292. #endif /* db hash */
  293. #endif /* db btree */
  294. #endif /* gdbm */
  295. /*
  296. * name: file name without the suffix
  297. * rw: read/write flags
  298. * mode: this has the desired permissions mode on the file
  299. * dbcachesize: advisory cache size in bytes
  300. */
  301. LDBM ldbm_open( char *name, int rw, int mode, int dbcachesize );
  302. #ifdef LDAP_USE_DB20
  303. /* This is a stopgap measure to allow us to associate a session with ldbm_ calls */
  304. LDBM ldbm_open2( dblayer_session session, char *name, int rw, int mode);
  305. /* These are stolen from beta2's dblayer.h */
  306. int dblayer_session_open(char *home_dir, char* log_dir, char* temp_dir, int cachesize, dblayer_session session) ;
  307. int dblayer_session_terminate(dblayer_session session) ;
  308. #endif
  309. int ldbm_close( LDBM ldbm );
  310. void ldbm_sync( LDBM ldbm );
  311. void ldbm_datum_free( LDBM ldbm, Datum data );
  312. Datum ldbm_datum_dup( LDBM ldbm, Datum data );
  313. Datum ldbm_fetch( LDBM ldbm, Datum key );
  314. int ldbm_store( LDBM ldbm, Datum key, Datum data, int flags );
  315. int ldbm_delete( LDBM ldbm, Datum key );
  316. Datum ldbm_firstkey( LDBM ldbm );
  317. Datum ldbm_nextkey( LDBM ldbm, Datum key );
  318. Datum ldbm_prevkey( LDBM ldbm, Datum key );
  319. Datum ldbm_lastkey( LDBM ldbm );
  320. Datum ldbm_cursorkey( LDBM ldbm, Datum key );
  321. int ldbm_errno( LDBM ldbm );
  322. #endif /* _ldbm_h_ */
  323. #endif /* 0 */