NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN

Write a Value to the Store. More...

+ Collaboration diagram for store():

Functions

static int store_bdb_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_gdbm_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_kyotocabinet_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_lmdb_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_qdbm_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_rocksdb_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_tokyocabinet_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_tdb_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 

Detailed Description

Write a Value to the Store.

Parameters
[in]storeStore retrieved via open()
[in]keyKey identifying the record
[in]klenLength of the Key string
[in]valueValue to save
[in]vlenLength of the Value
Return values
0Success
numError, a backend-specific error code

Function Documentation

◆ store_bdb_store()

static int store_bdb_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 189 of file bdb.c.

190 {
191  if (!store)
192  return -1;
193 
194  DBT dkey;
195  DBT databuf;
196 
197  struct StoreDbCtx *ctx = store;
198 
199  dbt_init(&dkey, (void *) key, klen);
200  dbt_empty_init(&databuf);
201  databuf.flags = DB_DBT_USERMEM;
202  databuf.data = value;
203  databuf.size = vlen;
204  databuf.ulen = vlen;
205 
206  return ctx->db->put(ctx->db, NULL, &dkey, &databuf, 0);
207 }
static void dbt_empty_init(DBT *dbt)
Initialise an empty BDB context.
Definition: bdb.c:76
static void dbt_init(DBT *dbt, void *data, size_t len)
Initialise a BDB context.
Definition: bdb.c:62
Berkeley DB context.
Definition: bdb.c:49
DB * db
Definition: bdb.c:51
+ Here is the call graph for this function:

◆ store_gdbm_store()

static int store_gdbm_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 89 of file gdbm.c.

90 {
91  if (!store)
92  return -1;
93 
94  datum dkey;
95  datum databuf;
96 
97  GDBM_FILE db = store;
98 
99  dkey.dptr = (char *) key;
100  dkey.dsize = klen;
101 
102  databuf.dsize = vlen;
103  databuf.dptr = value;
104 
105  return gdbm_store(db, dkey, databuf, GDBM_REPLACE);
106 }

◆ store_kyotocabinet_store()

static int store_kyotocabinet_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 95 of file kc.c.

97 {
98  if (!store)
99  return -1;
100 
101  KCDB *db = store;
102  if (!kcdbset(db, key, klen, value, vlen))
103  {
104  int ecode = kcdbecode(db);
105  return ecode ? ecode : -1;
106  }
107  return 0;
108 }

◆ store_lmdb_store()

static int store_lmdb_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 236 of file lmdb.c.

237 {
238  if (!store)
239  return -1;
240 
241  MDB_val dkey;
242  MDB_val databuf;
243 
244  struct StoreLmdbCtx *ctx = store;
245 
246  dkey.mv_data = (void *) key;
247  dkey.mv_size = klen;
248  databuf.mv_data = value;
249  databuf.mv_size = vlen;
250  int rc = mdb_get_w_txn(ctx);
251  if (rc != MDB_SUCCESS)
252  {
253  mutt_debug(LL_DEBUG2, "mdb_get_w_txn: %s\n", mdb_strerror(rc));
254  return rc;
255  }
256  rc = mdb_put(ctx->txn, ctx->db, &dkey, &databuf, 0);
257  if (rc != MDB_SUCCESS)
258  {
259  mutt_debug(LL_DEBUG2, "mdb_put: %s\n", mdb_strerror(rc));
260  mdb_txn_abort(ctx->txn);
262  ctx->txn = NULL;
263  }
264  return rc;
265 }
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int mdb_get_w_txn(struct StoreLmdbCtx *ctx)
Get an LMDB write transaction.
Definition: lmdb.c:106
@ TXN_UNINITIALIZED
Transaction is uninitialised.
Definition: lmdb.c:57
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
LMDB context.
Definition: lmdb.c:66
MDB_txn * txn
Definition: lmdb.c:68
enum MdbTxnMode txn_mode
Definition: lmdb.c:70
MDB_dbi db
Definition: lmdb.c:69
+ Here is the call graph for this function:

◆ store_qdbm_store()

static int store_qdbm_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 78 of file qdbm.c.

79 {
80  if (!store)
81  return -1;
82 
83  VILLA *db = store;
84  /* Not sure if dbecode is reset on success, so better to explicitly return 0
85  * on success */
86  bool success = vlput(db, key, klen, value, vlen, VL_DOVER);
87  return success ? 0 : dpecode ? dpecode : -1;
88 }

◆ store_rocksdb_store()

static int store_rocksdb_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 121 of file rocksdb.c.

123 {
124  if (!store)
125  return -1;
126 
127  struct RocksDbCtx *ctx = store;
128 
129  rocksdb_put(ctx->db, ctx->write_options, key, klen, value, vlen, &ctx->err);
130  if (ctx->err)
131  {
132  rocksdb_free(ctx->err);
133  ctx->err = NULL;
134  return -1;
135  }
136 
137  return 0;
138 }
Berkeley DB context.
Definition: rocksdb.c:40
rocksdb_writeoptions_t * write_options
Definition: rocksdb.c:44
rocksdb_t * db
Definition: rocksdb.c:41
char * err
Definition: rocksdb.c:45

◆ store_tokyocabinet_store()

static int store_tokyocabinet_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 87 of file tc.c.

89 {
90  if (!store)
91  return -1;
92 
93  TCBDB *db = store;
94  if (!tcbdbput(db, key, klen, value, vlen))
95  {
96  int ecode = tcbdbecode(db);
97  return ecode ? ecode : -1;
98  }
99  return 0;
100 }

◆ store_tdb_store()

static int store_tdb_store ( void *  store,
const char *  key,
size_t  klen,
void *  value,
size_t  vlen 
)
static

Implements StoreOps::store() -.

Definition at line 85 of file tdb.c.

86 {
87  if (!store)
88  return -1;
89 
90  TDB_CONTEXT *db = store;
91  TDB_DATA dkey;
92  TDB_DATA databuf;
93 
94  dkey.dptr = (unsigned char *) key;
95  dkey.dsize = klen;
96 
97  databuf.dsize = vlen;
98  databuf.dptr = value;
99 
100  return tdb_store(db, dkey, databuf, TDB_INSERT);
101 }