Postfix3.3.1
slmdb.h
[詳解]
1 #ifndef _SLMDB_H_INCLUDED_
2 #define _SLMDB_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* slmdb 3h
7 /* SUMMARY
8 /* LMDB API wrapper
9 /* SYNOPSIS
10 /* #include <slmdb.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * System library.
16  */
17 #include <setjmp.h>
18 
19 #ifdef PATH_LMDB_H
20 #include PATH_LMDB_H
21 #else
22 #include <lmdb.h>
23 #endif
24 
25  /*
26  * Utility library.
27  */
28 #include <check_arg.h>
29 
30  /*
31  * External interface.
32  */
33 #ifdef NO_SIGSETJMP
34 #define SLMDB_JMP_BUF jmp_buf
35 #else
36 #define SLMDB_JMP_BUF sigjmp_buf
37 #endif
38 
39  /*
40  * All data structure members are private.
41  */
42 typedef struct {
43  size_t curr_limit; /* database soft size limit */
44  int size_incr; /* database expansion factor */
45  size_t hard_limit; /* database hard size limit */
46  int open_flags; /* open() flags */
47  int lmdb_flags; /* LMDB-specific flags */
48  int slmdb_flags; /* bulk-mode flag */
49  MDB_env *env; /* database environment */
50  MDB_dbi dbi; /* database instance */
51  MDB_txn *txn; /* bulk transaction */
52  int db_fd; /* database file handle */
53  MDB_cursor *cursor; /* iterator */
54  MDB_val saved_key; /* saved cursor key buffer */
55  size_t saved_key_size; /* saved cursor key buffer size */
56  void (*longjmp_fn) (void *, int);/* exception handling */
57  void (*notify_fn) (void *, int,...); /* workaround notification */
58  void (*assert_fn) (void *, const char *); /* assert notification */
59  void *cb_context; /* call-back context */
60  int api_retry_count; /* slmdb(3) API call retry count */
61  int bulk_retry_count; /* bulk_mode retry count */
62  int api_retry_limit; /* slmdb(3) API call retry limit */
63  int bulk_retry_limit; /* bulk_mode retry limit */
64 } SLMDB;
65 
66 #define SLMDB_FLAG_BULK (1 << 0)
67 
68 extern int slmdb_init(SLMDB *, size_t, int, size_t);
69 extern int slmdb_open(SLMDB *, const char *, int, int, int);
70 extern int slmdb_get(SLMDB *, MDB_val *, MDB_val *);
71 extern int slmdb_put(SLMDB *, MDB_val *, MDB_val *, int);
72 extern int slmdb_del(SLMDB *, MDB_val *);
73 extern int slmdb_cursor_get(SLMDB *, MDB_val *, MDB_val *, MDB_cursor_op);
74 extern int slmdb_control(SLMDB *, int,...);
75 extern int slmdb_close(SLMDB *);
76 
77 #define slmdb_fd(slmdb) ((slmdb)->db_fd)
78 #define slmdb_curr_limit(slmdb) ((slmdb)->curr_limit)
79 
80 /* Legacy API: type-unchecked arguments, internal use. */
81 #define SLMDB_CTL_END 0
82 #define SLMDB_CTL_LONGJMP_FN 1 /* exception handling */
83 #define SLMDB_CTL_NOTIFY_FN 2 /* debug logging function */
84 #define SLMDB_CTL_CB_CONTEXT 3 /* call-back context */
85 #define SLMDB_CTL_API_RETRY_LIMIT 5 /* per slmdb(3) API call */
86 #define SLMDB_CTL_BULK_RETRY_LIMIT 6 /* per bulk update */
87 #define SLMDB_CTL_ASSERT_FN 7 /* report assertion failure */
88 
89 /* Safer API: type-checked arguments, external use. */
90 #define CA_SLMDB_CTL_END SLMDB_CTL_END
91 #define CA_SLMDB_CTL_LONGJMP_FN(v) SLMDB_CTL_LONGJMP_FN, CHECK_VAL(SLMDB_CTL, SLMDB_LONGJMP_FN, (v))
92 #define CA_SLMDB_CTL_NOTIFY_FN(v) SLMDB_CTL_NOTIFY_FN, CHECK_VAL(SLMDB_CTL, SLMDB_NOTIFY_FN, (v))
93 #define CA_SLMDB_CTL_CB_CONTEXT(v) SLMDB_CTL_CB_CONTEXT, CHECK_PTR(SLMDB_CTL, void, (v))
94 #define CA_SLMDB_CTL_API_RETRY_LIMIT(v) SLMDB_CTL_API_RETRY_LIMIT, CHECK_VAL(SLMDB_CTL, int, (v))
95 #define CA_SLMDB_CTL_BULK_RETRY_LIMIT(v) SLMDB_CTL_BULK_RETRY_LIMIT, CHECK_VAL(SLMDB_CTL, int, (v))
96 #define CA_SLMDB_CTL_ASSERT_FN(v) SLMDB_CTL_ASSERT_FN, CHECK_VAL(SLMDB_CTL, SLMDB_ASSERT_FN, (v))
97 
98 typedef void (*SLMDB_NOTIFY_FN) (void *, int,...);
99 typedef void (*SLMDB_LONGJMP_FN) (void *, int);
100 typedef void (*SLMDB_ASSERT_FN) (void *, const char *);
101 
102 CHECK_VAL_HELPER_DCL(SLMDB_CTL, int);
106 CHECK_PTR_HELPER_DCL(SLMDB_CTL, void);
107 
108 /* LICENSE
109 /* .ad
110 /* .fi
111 /* The Secure Mailer license must be distributed with this software.
112 /* AUTHOR(S)
113 /* Howard Chu
114 /* Symas Corporation
115 /*--*/
116 
117 #endif
int db_fd
Definition: slmdb.h:52
Definition: slmdb.h:42
int size_incr
Definition: slmdb.h:44
int api_retry_limit
Definition: slmdb.h:62
void(* SLMDB_NOTIFY_FN)(void *, int,...)
Definition: slmdb.h:98
int slmdb_del(SLMDB *, MDB_val *)
MDB_cursor * cursor
Definition: slmdb.h:53
MDB_env * env
Definition: slmdb.h:49
CHECK_VAL_HELPER_DCL(SLMDB_CTL, int)
int bulk_retry_count
Definition: slmdb.h:61
int slmdb_init(SLMDB *, size_t, int, size_t)
CHECK_PTR_HELPER_DCL(SLMDB_CTL, void)
int lmdb_flags
Definition: slmdb.h:47
int slmdb_get(SLMDB *, MDB_val *, MDB_val *)
int api_retry_count
Definition: slmdb.h:60
MDB_dbi dbi
Definition: slmdb.h:50
size_t curr_limit
Definition: slmdb.h:43
size_t hard_limit
Definition: slmdb.h:45
MDB_val saved_key
Definition: slmdb.h:54
int slmdb_flags
Definition: slmdb.h:48
int open_flags
Definition: slmdb.h:46
int slmdb_close(SLMDB *)
int int
Definition: smtpd_proxy.h:21
void * cb_context
Definition: slmdb.h:59
void(* SLMDB_LONGJMP_FN)(void *, int)
Definition: slmdb.h:99
int slmdb_cursor_get(SLMDB *, MDB_val *, MDB_val *, MDB_cursor_op)
MDB_txn * txn
Definition: slmdb.h:51
int slmdb_open(SLMDB *, const char *, int, int, int)
int bulk_retry_limit
Definition: slmdb.h:63
void(* SLMDB_ASSERT_FN)(void *, const char *)
Definition: slmdb.h:100
int slmdb_control(SLMDB *, int,...)
int slmdb_put(SLMDB *, MDB_val *, MDB_val *, int)
size_t saved_key_size
Definition: slmdb.h:55