NeoMutt  2024-10-02-37-gfa9146
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 <stdbool.h>
33#include <stddef.h>
34#include <tcbdb.h>
35#include <tcutil.h>
36#include "mutt/lib.h"
37#include "lib.h"
38
42static StoreHandle *store_tokyocabinet_open(const char *path, bool create)
43{
44 if (!path)
45 return NULL;
46
47 TCBDB *db = tcbdbnew();
48 if (!db)
49 return NULL;
50 if (!tcbdbopen(db, path, BDBOWRITER | (create ? BDBOCREAT : 0)))
51 {
52 int ecode = tcbdbecode(db);
53 mutt_debug(LL_DEBUG2, "tcbdbopen failed for %s: %s (ecode %d)\n", path,
54 tcbdberrmsg(ecode), ecode);
55 tcbdbdel(db);
56 return NULL;
57 }
58
59 // Return an opaque pointer
60 return (StoreHandle *) db;
61}
62
66static void *store_tokyocabinet_fetch(StoreHandle *store, const char *key,
67 size_t klen, size_t *vlen)
68{
69 if (!store)
70 return NULL;
71
72 // Decloak an opaque pointer
73 TCBDB *db = store;
74 int sp = 0;
75 void *rv = tcbdbget(db, key, klen, &sp);
76 *vlen = sp;
77 return rv;
78}
79
83static void store_tokyocabinet_free(StoreHandle *store, void **ptr)
84{
85 FREE(ptr);
86}
87
91static int store_tokyocabinet_store(StoreHandle *store, const char *key,
92 size_t klen, void *value, size_t vlen)
93{
94 if (!store)
95 return -1;
96
97 // Decloak an opaque pointer
98 TCBDB *db = store;
99 if (!tcbdbput(db, key, klen, value, vlen))
100 {
101 int ecode = tcbdbecode(db);
102 return ecode ? ecode : -1;
103 }
104 return 0;
105}
106
110static int store_tokyocabinet_delete_record(StoreHandle *store, const char *key, size_t klen)
111{
112 if (!store)
113 return -1;
114
115 // Decloak an opaque pointer
116 TCBDB *db = store;
117 if (!tcbdbout(db, key, klen))
118 {
119 int ecode = tcbdbecode(db);
120 return ecode ? ecode : -1;
121 }
122 return 0;
123}
124
129{
130 if (!ptr || !*ptr)
131 return;
132
133 // Decloak an opaque pointer
134 TCBDB *db = *ptr;
135 if (!tcbdbclose(db))
136 {
137 int ecode = tcbdbecode(db);
138 mutt_debug(LL_DEBUG2, "tcbdbclose failed: %s (ecode %d)\n", tcbdberrmsg(ecode), ecode);
139 }
140 tcbdbdel(db);
141 *ptr = NULL;
142}
143
147static const char *store_tokyocabinet_version(void)
148{
149 return "tokyocabinet " _TC_VERSION;
150}
151
152STORE_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:128
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:110
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:66
static void store_tokyocabinet_free(StoreHandle *store, void **ptr)
Free a Value returned by fetch() - Implements StoreOps::free() -.
Definition: tc.c:83
static StoreHandle * store_tokyocabinet_open(const char *path, bool create)
Open a connection to a Store - Implements StoreOps::open() -.
Definition: tc.c:42
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:91
static const char * store_tokyocabinet_version(void)
Get a Store version string - Implements StoreOps::version() -.
Definition: tc.c:147
@ 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:163