NeoMutt  2021-02-05-666-ge300cd
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;
37 STORE_BACKEND(bdb)
38 STORE_BACKEND(gdbm)
39 STORE_BACKEND(kyotocabinet)
40 STORE_BACKEND(lmdb)
41 STORE_BACKEND(qdbm)
42 STORE_BACKEND(rocksdb)
43 STORE_BACKEND(tdb)
44 STORE_BACKEND(tokyocabinet)
45 #undef STORE_BACKEND
46 
50 static const struct StoreOps *store_ops[] = {
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 
84 const char *store_backend_list(void)
85 {
86  char tmp[256] = { 0 };
87  const struct StoreOps **ops = store_ops;
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 
107 const struct StoreOps *store_get_backend_ops(const char *str)
108 {
109  const struct StoreOps **ops = store_ops;
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 
129 bool store_is_valid_backend(const char *str)
130 {
131  return store_get_backend_ops(str);
132 }
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:129
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
const char * store_backend_list(void)
Get a list of backend names.
Definition: store.c:84
Definition: lib.h:63
const struct StoreOps * store_get_backend_ops(const char *str)
Get the API functions for an store backend.
Definition: store.c:107
static const struct StoreOps * store_ops[]
Backend implementations.
Definition: store.c:50
#define STORE_BACKEND(name)
Definition: store.c:36
Convenience wrapper for the library headers.