NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
store.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include <string.h>
33#include "mutt/lib.h"
34#include "lib.h"
35
36#define STORE_BACKEND(name) extern const struct StoreOps store_##name##_ops;
38STORE_BACKEND(gdbm)
39STORE_BACKEND(kyotocabinet)
40STORE_BACKEND(lmdb)
41STORE_BACKEND(qdbm)
42STORE_BACKEND(rocksdb)
44STORE_BACKEND(tokyocabinet)
45#undef STORE_BACKEND
46
50static const struct StoreOps *StoreOps[] = {
51#ifdef HAVE_TC
52 &store_tokyocabinet_ops,
53#endif
54#ifdef HAVE_KC
55 &store_kyotocabinet_ops,
56#endif
57#ifdef HAVE_QDBM
58 &store_qdbm_ops,
59#endif
60#ifdef HAVE_ROCKSDB
61 &store_rocksdb_ops,
62#endif
63#ifdef HAVE_GDBM
64 &store_gdbm_ops,
65#endif
66#ifdef HAVE_BDB
67 &store_bdb_ops,
68#endif
69#ifdef HAVE_TDB
70 &store_tdb_ops,
71#endif
72#ifdef HAVE_LMDB
73 &store_lmdb_ops,
74#endif
75 NULL,
76};
77
84const char *store_backend_list(void)
85{
86 char tmp[256] = { 0 };
87 const struct StoreOps **ops = StoreOps;
88 size_t len = 0;
89
90 for (; *ops; ops++)
91 {
92 if (len != 0)
93 {
94 len += snprintf(tmp + len, sizeof(tmp) - len, ", ");
95 }
96 len += snprintf(tmp + len, sizeof(tmp) - len, "%s", (*ops)->name);
97 }
98
99 return mutt_str_dup(tmp);
100}
101
107const struct StoreOps *store_get_backend_ops(const char *str)
108{
109 const struct StoreOps **ops = StoreOps;
110
111 if (!str || (*str == '\0'))
112 {
113 return *ops;
114 }
115
116 for (; *ops; ops++)
117 if (strcmp(str, (*ops)->name) == 0)
118 break;
119
120 return *ops;
121}
122
129bool store_is_valid_backend(const char *str)
130{
131 return store_get_backend_ops(str);
132}
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
Key value store.
static const struct StoreOps * StoreOps[]
Backend implementations.
Definition: store.c:50
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:129
#define STORE_BACKEND(name)
Definition: store.c:36
const struct StoreOps * store_get_backend_ops(const char *str)
Get the API functions for an store backend.
Definition: store.c:107
const char * store_backend_list(void)
Get a list of backend names.
Definition: store.c:84
Definition: lib.h:66