NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
tdb.c
Go to the documentation of this file.
1
23
30
31
#include "config.h"
32
#include <fcntl.h>
33
#include <stdbool.h>
34
#include <stddef.h>
35
#include <tdb.h>
36
#include "
mutt/lib.h
"
37
#include "
lib.h
"
38
42
static
StoreHandle
*
store_tdb_open
(
const
char
*path,
bool
create)
43
{
44
if
(!path)
45
return
NULL;
46
47
/* TDB_NOLOCK - Don't do any locking
48
* TDB_NOSYNC - Don't use synchronous transactions
49
* TDB_INCOMPATIBLE_HASH - Better hashing
50
*/
51
const
int
flags = TDB_NOLOCK | TDB_INCOMPATIBLE_HASH | TDB_NOSYNC;
52
const
int
hash_size = 33533;
// Based on test timings for 100K emails
53
54
struct
tdb_context *db = tdb_open(path, hash_size, flags,
55
(create ? O_CREAT : 0) | O_RDWR, 00600);
56
57
// Return an opaque pointer
58
return
(
StoreHandle
*) db;
59
}
60
64
static
void
*
store_tdb_fetch
(
StoreHandle
*store,
const
char
*key,
size_t
klen,
size_t
*vlen)
65
{
66
if
(!store)
67
return
NULL;
68
69
// Decloak an opaque pointer
70
TDB_CONTEXT *db = store;
71
TDB_DATA dkey = { 0 };
72
TDB_DATA data = { 0 };
73
74
dkey.dptr = (
unsigned
char
*) key;
75
dkey.dsize = klen;
76
data = tdb_fetch(db, dkey);
77
78
*vlen = data.dsize;
79
return
data.dptr;
80
}
81
85
static
void
store_tdb_free
(
StoreHandle
*store,
void
**ptr)
86
{
87
FREE
(ptr);
88
}
89
93
static
int
store_tdb_store
(
StoreHandle
*store,
const
char
*key,
size_t
klen,
94
void
*value,
size_t
vlen)
95
{
96
if
(!store)
97
return
-1;
98
99
// Decloak an opaque pointer
100
TDB_CONTEXT *db = store;
101
TDB_DATA dkey = { 0 };
102
TDB_DATA databuf = { 0 };
103
104
dkey.dptr = (
unsigned
char
*) key;
105
dkey.dsize = klen;
106
107
databuf.dsize = vlen;
108
databuf.dptr = value;
109
110
return
tdb_store(db, dkey, databuf, TDB_INSERT);
111
}
112
116
static
int
store_tdb_delete_record
(
StoreHandle
*store,
const
char
*key,
size_t
klen)
117
{
118
if
(!store)
119
return
-1;
120
121
// Decloak an opaque pointer
122
TDB_CONTEXT *db = store;
123
TDB_DATA dkey = { 0 };
124
125
dkey.dptr = (
unsigned
char
*) key;
126
dkey.dsize = klen;
127
128
return
tdb_delete(db, dkey);
129
}
130
134
static
void
store_tdb_close
(
StoreHandle
**ptr)
135
{
136
if
(!ptr || !*ptr)
137
return
;
138
139
// Decloak an opaque pointer
140
TDB_CONTEXT *db = *ptr;
141
tdb_close(db);
142
*ptr = NULL;
143
}
144
148
static
const
char
*
store_tdb_version
(
void
)
149
{
150
// TDB doesn't supply any version info
151
return
"tdb"
;
152
}
153
154
STORE_BACKEND_OPS
(tdb)
store_tdb_close
static void store_tdb_close(StoreHandle **ptr)
Close a Store connection - Implements StoreOps::close() -.
Definition
tdb.c:134
store_tdb_delete_record
static int store_tdb_delete_record(StoreHandle *store, const char *key, size_t klen)
Delete a record from the Store - Implements StoreOps::delete_record() -.
Definition
tdb.c:116
store_tdb_fetch
static void * store_tdb_fetch(StoreHandle *store, const char *key, size_t klen, size_t *vlen)
Fetch a Value from the Store - Implements StoreOps::fetch() -.
Definition
tdb.c:64
store_tdb_free
static void store_tdb_free(StoreHandle *store, void **ptr)
Free a Value returned by fetch() - Implements StoreOps::free() -.
Definition
tdb.c:85
store_tdb_open
static StoreHandle * store_tdb_open(const char *path, bool create)
Open a connection to a Store - Implements StoreOps::open() -.
Definition
tdb.c:42
store_tdb_store
static int store_tdb_store(StoreHandle *store, const char *key, size_t klen, void *value, size_t vlen)
Write a Value to the Store - Implements StoreOps::store() -.
Definition
tdb.c:93
store_tdb_version
static const char * store_tdb_version(void)
Get a Store version string - Implements StoreOps::version() -.
Definition
tdb.c:148
FREE
#define FREE(x)
Free memory and set the pointer to NULL.
Definition
memory.h:68
lib.h
Convenience wrapper for the library headers.
lib.h
Key value store.
StoreHandle
void StoreHandle
Opaque type for store backend.
Definition
lib.h:58
STORE_BACKEND_OPS
#define STORE_BACKEND_OPS(_name)
Definition
lib.h:160