NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
qdbm.c
Go to the documentation of this file.
1 
33 #include "config.h"
34 #include <stddef.h>
35 #include <depot.h>
36 #include <stdbool.h>
37 #include <villa.h>
38 #include "mutt/lib.h"
39 #include "lib.h"
40 
44 static void *store_qdbm_open(const char *path)
45 {
46  if (!path)
47  return NULL;
48 
49  return vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX);
50 }
51 
55 static void *store_qdbm_fetch(void *store, const char *key, size_t klen, size_t *vlen)
56 {
57  if (!store)
58  return NULL;
59 
60  VILLA *db = store;
61  int sp = 0;
62  void *rv = vlget(db, key, klen, &sp);
63  *vlen = sp;
64  return rv;
65 }
66 
70 static void store_qdbm_free(void *store, void **ptr)
71 {
72  FREE(ptr);
73 }
74 
78 static int store_qdbm_store(void *store, const char *key, size_t klen, void *value, size_t vlen)
79 {
80  if (!store)
81  return -1;
82 
83  VILLA *db = store;
84  /* Not sure if dbecode is reset on success, so better to explicitly return 0
85  * on success */
86  bool success = vlput(db, key, klen, value, vlen, VL_DOVER);
87  return success ? 0 : dpecode ? dpecode : -1;
88 }
89 
93 static int store_qdbm_delete_record(void *store, const char *key, size_t klen)
94 {
95  if (!store)
96  return -1;
97 
98  VILLA *db = store;
99  /* Not sure if dbecode is reset on success, so better to explicitly return 0
100  * on success */
101  bool success = vlout(db, key, klen);
102  return success ? 0 : dpecode ? dpecode : -1;
103 }
104 
108 static void store_qdbm_close(void **ptr)
109 {
110  if (!ptr || !*ptr)
111  return;
112 
113  VILLA *db = *ptr;
114  vlclose(db);
115  *ptr = NULL;
116 }
117 
121 static const char *store_qdbm_version(void)
122 {
123  return "qdbm " _QDBM_VERSION;
124 }
125 
126 STORE_BACKEND_OPS(qdbm)
static void store_qdbm_free(void *store, void **ptr)
Implements StoreOps::free() -.
Definition: qdbm.c:70
#define STORE_BACKEND_OPS(_name)
Definition: lib.h:157
static int store_qdbm_store(void *store, const char *key, size_t klen, void *value, size_t vlen)
Implements StoreOps::store() -.
Definition: qdbm.c:78
static const char * store_qdbm_version(void)
Implements StoreOps::version() -.
Definition: qdbm.c:121
MDB_dbi db
Definition: lmdb.c:60
static void * store_qdbm_open(const char *path)
Implements StoreOps::open() -.
Definition: qdbm.c:44
#define FREE(x)
Definition: memory.h:40
static void store_qdbm_close(void **ptr)
Implements StoreOps::close() -.
Definition: qdbm.c:108
Convenience wrapper for the library headers.
static void * store_qdbm_fetch(void *store, const char *key, size_t klen, size_t *vlen)
Implements StoreOps::fetch() -.
Definition: qdbm.c:55
static int store_qdbm_delete_record(void *store, const char *key, size_t klen)
Implements StoreOps::delete_record() -.
Definition: qdbm.c:93