NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
tc.c
Go to the documentation of this file.
1 
33 #include "config.h"
34 #include <stddef.h>
35 #include <tcbdb.h>
36 #include <tcutil.h>
37 #include "mutt/lib.h"
38 #include "lib.h"
39 
43 static void *store_tokyocabinet_open(const char *path)
44 {
45  if (!path)
46  return NULL;
47 
48  TCBDB *db = tcbdbnew();
49  if (!db)
50  return NULL;
51  if (tcbdbopen(db, path, BDBOWRITER | BDBOCREAT))
52  return db;
53 
54  int ecode = tcbdbecode(db);
55  mutt_debug(LL_DEBUG2, "tcbdbopen failed for %s: %s (ecode %d)\n", path,
56  tcbdberrmsg(ecode), ecode);
57  tcbdbdel(db);
58  return NULL;
59 }
60 
64 static void *store_tokyocabinet_fetch(void *store, const char *key, size_t klen, size_t *vlen)
65 {
66  if (!store)
67  return NULL;
68 
69  int sp = 0;
70  TCBDB *db = store;
71  void *rv = tcbdbget(db, key, klen, &sp);
72  *vlen = sp;
73  return rv;
74 }
75 
79 static void store_tokyocabinet_free(void *store, void **ptr)
80 {
81  FREE(ptr);
82 }
83 
87 static int store_tokyocabinet_store(void *store, const char *key, size_t klen,
88  void *value, size_t vlen)
89 {
90  if (!store)
91  return -1;
92 
93  TCBDB *db = store;
94  if (!tcbdbput(db, key, klen, value, vlen))
95  {
96  int ecode = tcbdbecode(db);
97  return ecode ? ecode : -1;
98  }
99  return 0;
100 }
101 
105 static int store_tokyocabinet_delete_record(void *store, const char *key, size_t klen)
106 {
107  if (!store)
108  return -1;
109 
110  TCBDB *db = store;
111  if (!tcbdbout(db, key, klen))
112  {
113  int ecode = tcbdbecode(db);
114  return ecode ? ecode : -1;
115  }
116  return 0;
117 }
118 
122 static void store_tokyocabinet_close(void **ptr)
123 {
124  if (!ptr || !*ptr)
125  return;
126 
127  TCBDB *db = *ptr;
128  if (!tcbdbclose(db))
129  {
130  int ecode = tcbdbecode(db);
131  mutt_debug(LL_DEBUG2, "tcbdbclose failed: %s (ecode %d)\n", tcbdberrmsg(ecode), ecode);
132  }
133  tcbdbdel(db);
134  *ptr = NULL;
135 }
136 
140 static const char *store_tokyocabinet_version(void)
141 {
142  return "tokyocabinet " _TC_VERSION;
143 }
144 
145 STORE_BACKEND_OPS(tokyocabinet)
#define STORE_BACKEND_OPS(_name)
Definition: lib.h:157
static void * store_tokyocabinet_open(const char *path)
Implements StoreOps::open() -.
Definition: tc.c:43
static int store_tokyocabinet_store(void *store, const char *key, size_t klen, void *value, size_t vlen)
Implements StoreOps::store() -.
Definition: tc.c:87
Log at debug level 2.
Definition: logging.h:41
int(* store)(void *store, const char *key, size_t klen, void *value, size_t vlen)
Definition: lib.h:119
static void store_tokyocabinet_free(void *store, void **ptr)
Implements StoreOps::free() -.
Definition: tc.c:79
static int store_tokyocabinet_delete_record(void *store, const char *key, size_t klen)
Implements StoreOps::delete_record() -.
Definition: tc.c:105
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
#define FREE(x)
Definition: memory.h:40
static void * store_tokyocabinet_fetch(void *store, const char *key, size_t klen, size_t *vlen)
Implements StoreOps::fetch() -.
Definition: tc.c:64
Convenience wrapper for the library headers.
static void store_tokyocabinet_close(void **ptr)
Implements StoreOps::close() -.
Definition: tc.c:122
static const char * store_tokyocabinet_version(void)
Implements StoreOps::version() -.
Definition: tc.c:140