ldbm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. /* ldbm.h - ldap dbm compatibility routine header file */
  39. #error "Hmm, shoudn't be here"
  40. /* Deprecated header, why are you including it ??? */
  41. #if 1
  42. #ifndef _LDBM_H_
  43. #define _LDBM_H_
  44. /* define LDAP_USE_DB185 to get the old db library, otherwise, use db2.0 */
  45. #ifndef LDAP_USE_DB185
  46. #define LDAP_USE_DB20
  47. #endif
  48. #ifdef LDBM_USE_GDBM
  49. /*****************************************************************
  50. * *
  51. * use gdbm if possible *
  52. * *
  53. *****************************************************************/
  54. #include <gdbm.h>
  55. typedef datum Datum;
  56. typedef GDBM_FILE LDBM;
  57. extern gdbm_error gdbm_errno;
  58. /* for ldbm_open */
  59. #define LDBM_READER GDBM_READER
  60. #define LDBM_WRITER GDBM_WRITER
  61. #define LDBM_WRCREAT GDBM_WRCREAT
  62. #define LDBM_NEWDB GDBM_NEWDB
  63. #define LDBM_FAST GDBM_FAST
  64. #define LDBM_SUFFIX ".gdbm"
  65. /* for ldbm_insert */
  66. #define LDBM_INSERT GDBM_INSERT
  67. #define LDBM_REPLACE GDBM_REPLACE
  68. #define LDBM_SYNC 0x80000000
  69. #else /* end of gdbm */
  70. #ifdef LDBM_USE_DBHASH
  71. /*****************************************************************
  72. * *
  73. * use berkeley db hash package *
  74. * *
  75. *****************************************************************/
  76. #include <sys/types.h>
  77. #include <limits.h>
  78. #include <fcntl.h>
  79. #include <errno.h>
  80. #include <db.h>
  81. typedef DBT Datum;
  82. #define dsize size
  83. #define dptr data
  84. typedef DB *LDBM;
  85. #define DB_TYPE DB_HASH
  86. /* for ldbm_open */
  87. #define LDBM_READER O_RDONLY
  88. #define LDBM_WRITER O_RDWR
  89. #define LDBM_WRCREAT (O_RDWR|O_CREAT)
  90. #define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
  91. #define LDBM_FAST 0
  92. #define LDBM_SUFFIX ".dbh"
  93. /* for ldbm_insert */
  94. #define LDBM_INSERT R_NOOVERWRITE
  95. #define LDBM_REPLACE 0
  96. #define LDBM_SYNC 0x80000000
  97. #else /* end of db hash */
  98. #ifdef LDBM_USE_DBBTREE
  99. /*****************************************************************
  100. * *
  101. * use berkeley db btree package *
  102. * *
  103. *****************************************************************/
  104. #ifndef LDAP_USE_DB20 /* old-db needed us to include these system headers first */
  105. #include <sys/types.h>
  106. #include <limits.h>
  107. #include <fcntl.h>
  108. #include <errno.h>
  109. #endif
  110. #ifdef HPUX11
  111. #define __BIT_TYPES_DEFINED__
  112. typedef unsigned char u_int8_t;
  113. typedef unsigned int u_int32_t;
  114. typedef unsigned short u_int16_t;
  115. #endif
  116. #include <db.h>
  117. #define DB_TYPE DB_BTREE
  118. #define LDBM_ORDERED 1
  119. #ifdef LDAP_USE_DB20
  120. /* pull in parts of the new interface , this comes from dblayer.h */
  121. typedef struct _tag_dblayer_session{
  122. DB_ENV db_env;
  123. } *dblayer_session, dblayer_session_struct;
  124. /* for ldbm_insert */
  125. #define LDBM_INSERT DB_NOOVERWRITE
  126. #define LDBM_REPLACE 0 /* Db2.0 default is to replace */
  127. #define LDBM_SYNC 0x80000000
  128. typedef DBT Datum;
  129. #define dsize size
  130. #define dptr data
  131. typedef struct _ldbm {
  132. DB *pReal_DB;
  133. DBC *pCursor;
  134. } _ldbmstruct, *LDBM;
  135. /* for ldbm_open */
  136. #define LDBM_READER DB_RDONLY
  137. #define LDBM_WRITER 0
  138. #define LDBM_WRCREAT DB_CREATE
  139. #define LDBM_NEWDB (DB_TRUNCATE | DB_CREATE)
  140. #define LDBM_FAST 0
  141. #define LDBM_SUFFIX ".db2"
  142. #else /* DB 1.85 */
  143. /* for ldbm_insert */
  144. #define LDBM_INSERT R_NOOVERWRITE
  145. #define LDBM_REPLACE 0
  146. #define LDBM_SYNC 0x80000000
  147. typedef DBT Datum;
  148. #define dsize size
  149. #define dptr data
  150. typedef DB *LDBM;
  151. /* for ldbm_open */
  152. #define LDBM_READER O_RDONLY
  153. #define LDBM_WRITER O_RDWR
  154. #define LDBM_WRCREAT (O_RDWR|O_CREAT)
  155. #define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
  156. #define LDBM_FAST 0
  157. #define LDBM_SUFFIX ".dbb"
  158. #endif /* LDAP_USE_DB20 */
  159. #else /* end of db btree */
  160. #ifdef LDBM_USE_NDBM
  161. /*****************************************************************
  162. * *
  163. * if none of the above use ndbm, the standard unix thing *
  164. * *
  165. *****************************************************************/
  166. #include <ndbm.h>
  167. #ifndef O_RDONLY
  168. #include <fcntl.h>
  169. #endif
  170. typedef datum Datum;
  171. typedef DBM *LDBM;
  172. /* for ldbm_open */
  173. #define LDBM_READER O_RDONLY
  174. #define LDBM_WRITER O_WRONLY
  175. #define LDBM_WRCREAT (O_RDWR|O_CREAT)
  176. #define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
  177. #define LDBM_FAST 0
  178. #define LDBM_SUFFIX ".ndbm"
  179. /* for ldbm_insert */
  180. #define LDBM_INSERT DBM_INSERT
  181. #define LDBM_REPLACE DBM_REPLACE
  182. #define LDBM_SYNC 0
  183. #else /* end of ndbm */
  184. #ifdef LDBM_USE_CISAM
  185. /*****************************************************************
  186. * *
  187. * use CISAM db package *
  188. * *
  189. *****************************************************************/
  190. #include <sys/types.h>
  191. #include <sys/errno.h>
  192. #include <limits.h>
  193. #include <fcntl.h>
  194. #include "isam.h"
  195. extern int errno;
  196. struct datum {
  197. void *dptr; /* data */
  198. size_t dsize; /* data length */
  199. };
  200. typedef struct datum Datum;
  201. struct ldbm {
  202. int fd; /* all callers expect a ptr */
  203. int cur_recnum; /* for reading sequentially */
  204. };
  205. typedef struct ldbm *LDBM;
  206. /* for ldbm_open */
  207. #define LDBM_READER (ISINPUT | ISVARLEN | ISMANULOCK)
  208. #define LDBM_WRITER (ISINOUT | ISVARLEN | ISMANULOCK)
  209. #define LDBM_WRCREAT (ISINOUT | ISVARLEN | ISMANULOCK | ISEXCLLOCK)
  210. #define LDBM_NEWDB (ISINOUT | ISVARLEN | ISMANULOCK | ISEXCLLOCK)
  211. #define LDBM_FAST 0
  212. #define LDBM_SUFFIX ""
  213. #define LDBM_ORDERED 1
  214. /* for ldbm_insert */
  215. #define LDBM_INSERT 1
  216. #define LDBM_REPLACE 0
  217. #define LDBM_SYNC 0x80000000
  218. #else /* end of cisam */
  219. #ifdef LDBM_USE_TRIO
  220. /*****************************************************************
  221. * *
  222. * use C-Index/II from Trio *
  223. * *
  224. *****************************************************************/
  225. #include <sys/types.h>
  226. #include <sys/errno.h>
  227. #include <limits.h>
  228. #include <fcntl.h>
  229. #include "cndx.h"
  230. #define CRDCREAT 0x100
  231. extern int errno;
  232. struct datum {
  233. void *dptr; /* data */
  234. size_t dsize; /* data length */
  235. };
  236. typedef struct datum Datum;
  237. typedef CFILE *LDBM;
  238. /* for ldbm_open */
  239. #define LDBM_READER (CRDONLY)
  240. #define LDBM_WRITER (CRDWRITE)
  241. #define LDBM_WRCREAT (CRDWRITE | CRDCREAT)
  242. #define LDBM_NEWDB (CRDWRITE | CRDCREAT)
  243. #define LDBM_FAST 0
  244. #define LDBM_SUFFIX ".c2i"
  245. #define LDBM_ORDERED 1
  246. /* for ldbm_insert */
  247. #define LDBM_INSERT 1
  248. #define LDBM_REPLACE 0
  249. #define LDBM_SYNC 0x80000000
  250. #else /* end of trio */
  251. #ifdef LDBM_USE_CTREE
  252. /*****************************************************************
  253. * *
  254. * use Faircom Ctree db package *
  255. * *
  256. *****************************************************************/
  257. #include <sys/types.h>
  258. #include <sys/errno.h>
  259. #include <limits.h>
  260. #include <fcntl.h>
  261. #include "ctstdr.h"
  262. #include "ctoptn.h"
  263. #include "ctaerr.h"
  264. #include "ctdecl.h"
  265. #include "cterrc.h"
  266. extern int errno;
  267. struct datum {
  268. void *dptr; /* data */
  269. size_t dsize; /* data length */
  270. };
  271. typedef struct datum Datum;
  272. typedef IFIL *LDBM;
  273. /* for ldbm_open */
  274. #define LDBM_READER 0
  275. #define LDBM_WRITER 0
  276. #define LDBM_WRCREAT 1
  277. #define LDBM_NEWDB 1
  278. #define LDBM_FAST 0
  279. #define LDBM_SUFFIX ""
  280. #define LDBM_ORDERED 1
  281. /* for ldbm_insert */
  282. #define LDBM_INSERT 1
  283. #define LDBM_REPLACE 0
  284. #define LDBM_SYNC 0x80000000
  285. #endif /* ctree */
  286. #endif /* trio */
  287. #endif /* cisam */
  288. #endif /* ndbm */
  289. #endif /* db hash */
  290. #endif /* db btree */
  291. #endif /* gdbm */
  292. /*
  293. * name: file name without the suffix
  294. * rw: read/write flags
  295. * mode: this has the desired permissions mode on the file
  296. * dbcachesize: advisory cache size in bytes
  297. */
  298. LDBM ldbm_open( char *name, int rw, int mode, int dbcachesize );
  299. #ifdef LDAP_USE_DB20
  300. /* This is a stopgap measure to allow us to associate a session with ldbm_ calls */
  301. LDBM ldbm_open2( dblayer_session session, char *name, int rw, int mode);
  302. /* These are stolen from beta2's dblayer.h */
  303. int dblayer_session_open(char *home_dir, char* log_dir, char* temp_dir, int cachesize, dblayer_session session) ;
  304. int dblayer_session_terminate(dblayer_session session) ;
  305. #endif
  306. int ldbm_close( LDBM ldbm );
  307. void ldbm_sync( LDBM ldbm );
  308. void ldbm_datum_free( LDBM ldbm, Datum data );
  309. Datum ldbm_datum_dup( LDBM ldbm, Datum data );
  310. Datum ldbm_fetch( LDBM ldbm, Datum key );
  311. int ldbm_store( LDBM ldbm, Datum key, Datum data, int flags );
  312. int ldbm_delete( LDBM ldbm, Datum key );
  313. Datum ldbm_firstkey( LDBM ldbm );
  314. Datum ldbm_nextkey( LDBM ldbm, Datum key );
  315. Datum ldbm_prevkey( LDBM ldbm, Datum key );
  316. Datum ldbm_lastkey( LDBM ldbm );
  317. Datum ldbm_cursorkey( LDBM ldbm, Datum key );
  318. int ldbm_errno( LDBM ldbm );
  319. #endif /* _ldbm_h_ */
  320. #endif /* 0 */