2 * Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 * $Id: smdb.h,v 8.41 2002/09/24 19:53:28 ca Exp $
16 # include <sys/types.h>
17 # include <sys/stat.h>
19 # include <sm/errstring.h>
30 ** Some size constants
33 #define SMDB_MAX_USER_NAME_LEN 1024
36 ** This file defines the abstraction for database lookups. It is pretty
37 ** much a copy of the db2 interface with the exception that every function
38 ** returns 0 on success and non-zero on failure. The non-zero return code
41 ** I'm going to put the function comments in this file since the interface
42 ** MUST be the same for all inheritors of this interface.
45 typedef struct database_struct SMDB_DATABASE;
46 typedef struct cursor_struct SMDB_CURSOR;
47 typedef struct entry_struct SMDB_DBENT;
50 ** DB_CLOSE_FUNC -- close the database
53 ** db -- The database to close.
56 ** 0 - Success, otherwise errno.
60 typedef int (*db_close_func) __P((SMDB_DATABASE *db));
63 ** DB_DEL_FUNC -- removes a key and data pair from the database
66 ** db -- The database to close.
67 ** key -- The key to remove.
68 ** flags -- delete options. There are currently no defined
72 ** 0 - Success, otherwise errno.
76 typedef int (*db_del_func) __P((SMDB_DATABASE *db,
77 SMDB_DBENT *key, unsigned int flags));
80 ** DB_FD_FUNC -- Returns a pointer to a file used for the database.
83 ** db -- The database to close.
84 ** fd -- A pointer to store the returned fd in.
87 ** 0 - Success, otherwise errno.
91 typedef int (*db_fd_func) __P((SMDB_DATABASE *db, int* fd));
94 ** DB_GET_FUNC -- Gets the data associated with a key.
97 ** db -- The database to close.
98 ** key -- The key to access.
99 ** data -- A place to store the returned data.
100 ** flags -- get options. There are currently no defined
104 ** 0 - Success, otherwise errno.
108 typedef int (*db_get_func) __P((SMDB_DATABASE *db,
110 SMDB_DBENT *data, unsigned int flags));
113 ** DB_PUT_FUNC -- Sets some data according to the key.
116 ** db -- The database to close.
117 ** key -- The key to use.
118 ** data -- The data to store.
119 ** flags -- put options:
120 ** SMDBF_NO_OVERWRITE - Return an error if key alread
122 ** SMDBF_ALLOW_DUP - Allow duplicates in btree maps.
125 ** 0 - Success, otherwise errno.
129 typedef int (*db_put_func) __P((SMDB_DATABASE *db,
131 SMDB_DBENT *data, unsigned int flags));
134 ** DB_SYNC_FUNC -- Flush any cached information to disk.
137 ** db -- The database to sync.
138 ** flags -- sync options:
141 ** 0 - Success, otherwise errno.
145 typedef int (*db_sync_func) __P((SMDB_DATABASE *db, unsigned int flags));
148 ** DB_SET_OWNER_FUNC -- Set the owner and group of the database files.
151 ** db -- The database to set.
152 ** uid -- The UID for the new owner (-1 for no change)
153 ** gid -- The GID for the new owner (-1 for no change)
156 ** 0 - Success, otherwise errno.
160 typedef int (*db_set_owner_func) __P((SMDB_DATABASE *db, uid_t uid, gid_t gid));
163 ** DB_CURSOR -- Obtain a cursor for sequential access
166 ** db -- The database to use.
167 ** cursor -- The address of a cursor pointer.
168 ** flags -- sync options:
171 ** 0 - Success, otherwise errno.
175 typedef int (*db_cursor_func) __P((SMDB_DATABASE *db,
176 SMDB_CURSOR **cursor, unsigned int flags));
178 typedef int (*db_lockfd_func) __P((SMDB_DATABASE *db));
180 struct database_struct
182 db_close_func smdb_close;
183 db_del_func smdb_del;
185 db_get_func smdb_get;
186 db_put_func smdb_put;
187 db_sync_func smdb_sync;
188 db_set_owner_func smdb_set_owner;
189 db_cursor_func smdb_cursor;
190 db_lockfd_func smdb_lockfd;
194 ** DB_CURSOR_CLOSE -- Close a cursor
197 ** cursor -- The cursor to close.
200 ** 0 - Success, otherwise errno.
204 typedef int (*db_cursor_close_func) __P((SMDB_CURSOR *cursor));
207 ** DB_CURSOR_DEL -- Delete the key/value pair of this cursor
210 ** cursor -- The cursor.
214 ** 0 - Success, otherwise errno.
218 typedef int (*db_cursor_del_func) __P((SMDB_CURSOR *cursor,
219 unsigned int flags));
222 ** DB_CURSOR_GET -- Get the key/value of this cursor.
225 ** cursor -- The cursor.
226 ** key -- The current key.
227 ** value -- The current value
231 ** 0 - Success, otherwise errno.
232 ** SMDBE_LAST_ENTRY - This is a success condition that
233 ** gets returned when the end of the
238 typedef int (*db_cursor_get_func) __P((SMDB_CURSOR *cursor,
241 unsigned int flags));
244 ** Flags for DB_CURSOR_GET
247 #define SMDB_CURSOR_GET_FIRST 0
248 #define SMDB_CURSOR_GET_LAST 1
249 #define SMDB_CURSOR_GET_NEXT 2
250 #define SMDB_CURSOR_GET_RANGE 3
253 ** DB_CURSOR_PUT -- Put the key/value at this cursor.
256 ** cursor -- The cursor.
257 ** key -- The current key.
258 ** value -- The current value
262 ** 0 - Success, otherwise errno.
266 typedef int (*db_cursor_put_func) __P((SMDB_CURSOR *cursor,
269 unsigned int flags));
275 db_cursor_close_func smdbc_close;
276 db_cursor_del_func smdbc_del;
277 db_cursor_get_func smdbc_get;
278 db_cursor_put_func smdbc_put;
283 struct database_params_struct
285 unsigned int smdbp_num_elements;
286 unsigned int smdbp_cache_size;
287 bool smdbp_allow_dup;
290 typedef struct database_params_struct SMDB_DBPARAMS;
292 struct database_user_struct
295 gid_t smdbu_group_id;
296 char smdbu_name[SMDB_MAX_USER_NAME_LEN];
299 typedef struct database_user_struct SMDB_USER_INFO;
307 typedef char *SMDB_DBTYPE;
308 typedef unsigned int SMDB_FLAG;
311 ** These are types of databases.
314 # define SMDB_TYPE_DEFAULT NULL
315 # define SMDB_TYPE_DEFAULT_LEN 0
316 # define SMDB_TYPE_HASH "hash"
317 # define SMDB_TYPE_HASH_LEN 5
318 # define SMDB_TYPE_BTREE "btree"
319 # define SMDB_TYPE_BTREE_LEN 6
320 # define SMDB_TYPE_NDBM "dbm"
321 # define SMDB_TYPE_NDBM_LEN 4
328 # define SMDBF_NO_OVERWRITE 0x00000001
329 # define SMDBF_ALLOW_DUP 0x00000002
332 extern SMDB_DATABASE *smdb_malloc_database __P((void));
333 extern void smdb_free_database __P((SMDB_DATABASE *));
334 extern int smdb_open_database __P((SMDB_DATABASE **, char *, int,
335 int, long, SMDB_DBTYPE,
339 extern int smdb_db_open __P((SMDB_DATABASE **, char *, int, int,
340 long, SMDB_DBTYPE, SMDB_USER_INFO *,
344 extern int smdb_ndbm_open __P((SMDB_DATABASE **, char *, int, int,
349 extern int smdb_add_extension __P((char *, int, char *, char *));
350 extern int smdb_setup_file __P((char *, char *, int, long,
351 SMDB_USER_INFO *, struct stat *));
352 extern int smdb_lock_file __P((int *, char *, int, long, char *));
353 extern int smdb_unlock_file __P((int));
354 extern int smdb_filechanged __P((char *, char *, int,
356 extern void smdb_print_available_types __P((void));
357 extern char *smdb_db_definition __P((SMDB_DBTYPE));
358 extern int smdb_lock_map __P((SMDB_DATABASE *, int));
359 extern int smdb_unlock_map __P((SMDB_DATABASE *));
360 #endif /* ! _SMDB_H_ */