NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
qdbm.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <depot.h>
33#include <stdbool.h>
34#include <stddef.h>
35#include <villa.h>
36#include "mutt/lib.h"
37#include "lib.h"
38
42static StoreHandle *store_qdbm_open(const char *path, bool create)
43{
44 if (!path)
45 return NULL;
46
47 VILLA *db = vlopen(path, VL_OWRITER | (create ? VL_OCREAT : 0), VL_CMPLEX);
48
49 // Return an opaque pointer
50 return (StoreHandle *) db;
51}
52
56static void *store_qdbm_fetch(StoreHandle *store, const char *key, size_t klen, size_t *vlen)
57{
58 if (!store)
59 return NULL;
60
61 // Decloak an opaque pointer
62 VILLA *db = store;
63 int sp = 0;
64 void *rv = vlget(db, key, klen, &sp);
65 *vlen = sp;
66 return rv;
67}
68
72static void store_qdbm_free(StoreHandle *store, void **ptr)
73{
74 FREE(ptr);
75}
76
80static int store_qdbm_store(StoreHandle *store, const char *key, size_t klen,
81 void *value, size_t vlen)
82{
83 if (!store)
84 return -1;
85
86 // Decloak an opaque pointer
87 VILLA *db = store;
88 /* Not sure if dpecode is reset on success, so better to explicitly return 0
89 * on success */
90 bool success = vlput(db, key, klen, value, vlen, VL_DOVER);
91 return success ? 0 : dpecode ? dpecode : -1;
92}
93
97static int store_qdbm_delete_record(StoreHandle *store, const char *key, size_t klen)
98{
99 if (!store)
100 return -1;
101
102 // Decloak an opaque pointer
103 VILLA *db = store;
104 /* Not sure if dpecode is reset on success, so better to explicitly return 0
105 * on success */
106 bool success = vlout(db, key, klen);
107 return success ? 0 : dpecode ? dpecode : -1;
108}
109
114{
115 if (!ptr || !*ptr)
116 return;
117
118 // Decloak an opaque pointer
119 VILLA *db = *ptr;
120 vlclose(db);
121 *ptr = NULL;
122}
123
127static const char *store_qdbm_version(void)
128{
129 return "qdbm " _QDBM_VERSION;
130}
131
static void store_qdbm_close(StoreHandle **ptr)
Close a Store connection - Implements StoreOps::close() -.
Definition: qdbm.c:113
static int store_qdbm_delete_record(StoreHandle *store, const char *key, size_t klen)
Delete a record from the Store - Implements StoreOps::delete_record() -.
Definition: qdbm.c:97
static void * store_qdbm_fetch(StoreHandle *store, const char *key, size_t klen, size_t *vlen)
Fetch a Value from the Store - Implements StoreOps::fetch() -.
Definition: qdbm.c:56
static void store_qdbm_free(StoreHandle *store, void **ptr)
Free a Value returned by fetch() - Implements StoreOps::free() -.
Definition: qdbm.c:72
static StoreHandle * store_qdbm_open(const char *path, bool create)
Open a connection to a Store - Implements StoreOps::open() -.
Definition: qdbm.c:42
static int store_qdbm_store(StoreHandle *store, const char *key, size_t klen, void *value, size_t vlen)
Write a Value to the Store - Implements StoreOps::store() -.
Definition: qdbm.c:80
static const char * store_qdbm_version(void)
Get a Store version string - Implements StoreOps::version() -.
Definition: qdbm.c:127
#define FREE(x)
Definition: memory.h:55
Convenience wrapper for the library headers.
Key value store.
void StoreHandle
Opaque type for store backend.
Definition: lib.h:61
#define STORE_BACKEND_OPS(_name)
Definition: lib.h:163