NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
tc.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <stddef.h>
33#include <tcbdb.h>
34#include <tcutil.h>
35#include "mutt/lib.h"
36#include "lib.h"
37
41static StoreHandle *store_tokyocabinet_open(const char *path)
42{
43 if (!path)
44 return NULL;
45
46 TCBDB *db = tcbdbnew();
47 if (!db)
48 return NULL;
49 if (!tcbdbopen(db, path, BDBOWRITER | BDBOCREAT))
50 {
51 int ecode = tcbdbecode(db);
52 mutt_debug(LL_DEBUG2, "tcbdbopen failed for %s: %s (ecode %d)\n", path,
53 tcbdberrmsg(ecode), ecode);
54 tcbdbdel(db);
55 return NULL;
56 }
57
58 // Return an opaque pointer
59 return (StoreHandle *) db;
60}
61
65static void *store_tokyocabinet_fetch(StoreHandle *store, const char *key,
66 size_t klen, size_t *vlen)
67{
68 if (!store)
69 return NULL;
70
71 // Decloak an opaque pointer
72 TCBDB *db = store;
73 int sp = 0;
74 void *rv = tcbdbget(db, key, klen, &sp);
75 *vlen = sp;
76 return rv;
77}
78
82static void store_tokyocabinet_free(StoreHandle *store, void **ptr)
83{
84 FREE(ptr);
85}
86
90static int store_tokyocabinet_store(StoreHandle *store, const char *key,
91 size_t klen, void *value, size_t vlen)
92{
93 if (!store)
94 return -1;
95
96 // Decloak an opaque pointer
97 TCBDB *db = store;
98 if (!tcbdbput(db, key, klen, value, vlen))
99 {
100 int ecode = tcbdbecode(db);
101 return ecode ? ecode : -1;
102 }
103 return 0;
104}
105
109static int store_tokyocabinet_delete_record(StoreHandle *store, const char *key, size_t klen)
110{
111 if (!store)
112 return -1;
113
114 // Decloak an opaque pointer
115 TCBDB *db = store;
116 if (!tcbdbout(db, key, klen))
117 {
118 int ecode = tcbdbecode(db);
119 return ecode ? ecode : -1;
120 }
121 return 0;
122}
123
128{
129 if (!ptr || !*ptr)
130 return;
131
132 // Decloak an opaque pointer
133 TCBDB *db = *ptr;
134 if (!tcbdbclose(db))
135 {
136 int ecode = tcbdbecode(db);
137 mutt_debug(LL_DEBUG2, "tcbdbclose failed: %s (ecode %d)\n", tcbdberrmsg(ecode), ecode);
138 }
139 tcbdbdel(db);
140 *ptr = NULL;
141}
142
146static const char *store_tokyocabinet_version(void)
147{
148 return "tokyocabinet " _TC_VERSION;
149}
150
151STORE_BACKEND_OPS(tokyocabinet)
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static void store_tokyocabinet_close(StoreHandle **ptr)
Close a Store connection - Implements StoreOps::close() -.
Definition: tc.c:127
static int store_tokyocabinet_delete_record(StoreHandle *store, const char *key, size_t klen)
Delete a record from the Store - Implements StoreOps::delete_record() -.
Definition: tc.c:109
static void * store_tokyocabinet_fetch(StoreHandle *store, const char *key, size_t klen, size_t *vlen)
Fetch a Value from the Store - Implements StoreOps::fetch() -.
Definition: tc.c:65
static void store_tokyocabinet_free(StoreHandle *store, void **ptr)
Free a Value returned by fetch() - Implements StoreOps::free() -.
Definition: tc.c:82
static StoreHandle * store_tokyocabinet_open(const char *path)
Open a connection to a Store - Implements StoreOps::open() -.
Definition: tc.c:41
static int store_tokyocabinet_store(StoreHandle *store, const char *key, size_t klen, void *value, size_t vlen)
Write a Value to the Store - Implements StoreOps::store() -.
Definition: tc.c:90
static const char * store_tokyocabinet_version(void)
Get a Store version string - Implements StoreOps::version() -.
Definition: tc.c:146
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define FREE(x)
Definition: memory.h:45
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:162