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