#ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
+#if defined(HAVE_TOKYOCABINET)
+#include <tcutil.h>
+#include <tchdb.h>
+#elif defined(HAVE_QDBM)
#include <depot.h>
#include <cabin.h>
#include <villa.h>
#elif defined(HAVE_GDBM)
#include <gdbm.h>
#else
-#error neither HAVE_QDBM nor HAVE_GDBM are set ?!
+#error no supported DB library found ?
#endif
#include "charset.h"
#include "hcache.h"
struct hcache_t {
-#if defined(HAVE_QDBM)
+#if defined(HAVE_TOKYOCABINET)
+ TCHDB *db;
+#elif defined(HAVE_QDBM)
VILLA *db;
#elif defined(HAVE_GDBM)
GDBM_FILE db;
path = mutt_hcache_per_folder(mod_core.cachedir, folder);
{
-#if defined(HAVE_QDBM)
+#if defined(HAVE_TOKYOCABINET)
+ h->db = tchdbnew();
+ if (!tchdbopen(h->db, path, HDBOWRITER | HDBOCREAT)) {
+ tchdbdel(h->db);
+ h->db = NULL;
+ }
+#elif defined(HAVE_QDBM)
h->db = vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX);
#elif defined(HAVE_GDBM)
h->db = gdbm_open((char *) path, 16384, GDBM_WRCREAT, 00600, NULL);
if (!*db)
return;
-#if defined(HAVE_QDBM)
+#if defined(HAVE_TOKYOCABINET)
+ tchdbdel((*db)->db);
+ (*db)->db = NULL;
+#elif defined(HAVE_QDBM)
vlclose((*db)->db);
#elif defined(HAVE_GDBM)
gdbm_close((*db)->db);
snprintf(path, sizeof(path), "%s%s", db->folder, filename);
{
-#if defined(HAVE_QDBM)
- int ksize = strlen(db->folder) + keylen(path + strlen(db->folder));
+ int ksize = keylen(path);
+#if defined(HAVE_TOKYOCABINET)
+ int unused;
+ data = tchdbget(db->db, path, ksize, &unused);
+#elif defined(HAVE_QDBM)
data = vlget(db->db, path, ksize, NULL);
#elif defined(HAVE_GDBM)
- datum k = { .dptr = path, .dsize = keylen(path) };
+ datum k = { .dptr = path, .dsize = ksize };
data = gdbm_fetch(db->db, k).dtpr;
#endif
data = mutt_hcache_dump(db, header, uid_validity);
{
-#if defined(HAVE_QDBM)
- int ksize = strlen(db->folder) + keylen(path + strlen(db->folder));
-
- ret = vlput(db->db, path, ksize, data->data, data->len, VL_DOVER);
+ int ksize = keylen(path);
+#if defined(HAVE_TOKYOCABINET)
+ ret = !!tchdbput(db->db, path, ksize, data->data, data->len) - 1;
+#elif defined(HAVE_QDBM)
+ ret = !!vlput(db->db, path, ksize, data->data, data->len, VL_DOVER) - 1;
#elif defined(HAVE_GDBM)
- datum k = { .dptr = path, .dsize = keylen(path) };
+ datum k = { .dptr = path, .dsize = ksize };
datum v = { .dptr = data->data, .dsize = data->len };
ret = gdbm_store(db->db, k, v, GDBM_REPLACE);
return ret;
}
-int mutt_hcache_delete(hcache_t *db, const char *filename,
+void mutt_hcache_delete(hcache_t *db, const char *filename,
ssize_t (*keylen)(const char *fn))
{
char path[_POSIX_PATH_MAX];
snprintf(path, sizeof(path), "%s%s", db->folder, filename);
{
-#if defined(HAVE_QDBM)
- int ksize = strlen(db->folder) + keylen(path + strlen(db->folder));
- return vlout(db->db, path, ksize);
+ int ksize = keylen(path);
+#if defined(HAVE_TOKYOCABINET)
+ tchdbout(db->db, path, ksize);
+#elif defined(HAVE_QDBM)
+ vlout(db->db, path, ksize);
#elif defined(HAVE_GDBM)
- datum k = { .dptr = path, .dsize = keylen(path) };
- return gdbm_delete(db->db, k);
+ datum k = { .dptr = path, .dsize = ksize };
+ gdbm_delete(db->db, k);
#endif
}
}