NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Key value store. More...

#include <stdbool.h>
#include <stdlib.h>
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  StoreOps
 Key Value Store API. More...
 

Macros

#define STORE_BACKEND_OPS(_name)
 

Functions

const char * store_backend_list (void)
 Get a list of backend names. More...
 
const struct StoreOpsstore_get_backend_ops (const char *str)
 Get the API functions for an store backend. More...
 
bool store_is_valid_backend (const char *str)
 Is the string a valid Store backend. More...
 

Detailed Description

Key value store.

Authors
  • Pietro Cerutti
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Macro Definition Documentation

◆ STORE_BACKEND_OPS

#define STORE_BACKEND_OPS (   _name)
Value:
const struct StoreOps store_##_name##_ops = { \
.name = #_name, \
.open = store_##_name##_open, \
.fetch = store_##_name##_fetch, \
.free = store_##_name##_free, \
.store = store_##_name##_store, \
.delete_record = store_##_name##_delete_record, \
.close = store_##_name##_close, \
.version = store_##_name##_version, \
};
Key Value Store API.
Definition: lib.h:61
const char * name
Store name.
Definition: lib.h:63

Definition at line 134 of file lib.h.

Function Documentation

◆ store_backend_list()

const char* store_backend_list ( void  )

Get a list of backend names.

Return values
ptrComma-space-separated list of names

The caller should free the string.

Definition at line 84 of file store.c.

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 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
Key Value Store API.
Definition: lib.h:61
const struct StoreOps * store_ops[]
Backend implementations.
Definition: store.c:50

◆ store_get_backend_ops()

const struct StoreOps* store_get_backend_ops ( const char *  str)

Get the API functions for an store backend.

Parameters
strName of the Store
Return values
ptrSet of function pointers

Definition at line 107 of file store.c.

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 }
Key Value Store API.
Definition: lib.h:61
const struct StoreOps * store_ops[]
Backend implementations.
Definition: store.c:50
+ Here is the caller graph for this function:

◆ store_is_valid_backend()

bool store_is_valid_backend ( const char *  str)

Is the string a valid Store backend.

Parameters
strStore name
Return values
trues is recognized as a valid backend
falseotherwise

Definition at line 129 of file store.c.

130 {
131  return store_get_backend_ops(str);
132 }
const struct StoreOps * store_get_backend_ops(const char *str)
Get the API functions for an store backend.
Definition: store.c:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function: