NeoMutt  2024-04-25-127-g771158
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
store.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.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 **store_ops = StoreOps;
88 size_t len = 0;
89
90 for (; *store_ops; store_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", (*store_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 **store_ops = StoreOps;
110
111 if (!str || (*str == '\0'))
112 {
113 return *store_ops;
114 }
115
116 for (; *store_ops; store_ops++)
117 if (mutt_str_equal(str, (*store_ops)->name))
118 break;
119
120 return *store_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:253
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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:69