X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mx%2Fhcache.c;h=01db5bdd955058ce44677f280228ebf6a08ce43a;hp=1b781d2f9486f409210cda1fe42812558a2e865c;hb=799c3f5aec72b8230f9c3c284e2b2e9d67ecf366;hpb=15aeb79a9b30f4037ec0898452090e90da28f7f1 diff --git a/lib-mx/hcache.c b/lib-mx/hcache.c index 1b781d2..01db5bd 100644 --- a/lib-mx/hcache.c +++ b/lib-mx/hcache.c @@ -13,14 +13,13 @@ #ifdef USE_HCACHE -#if defined(HAVE_QDBM) -#include -#include -#include +#if defined(HAVE_TOKYOCABINET) +#include +#include #elif defined(HAVE_GDBM) #include #else -#error neither HAVE_QDBM nor HAVE_GDBM are set ?! +#error no supported DB library found ? #endif #include "charset.h" @@ -28,8 +27,8 @@ #include "hcache.h" struct hcache_t { -#if defined(HAVE_QDBM) - VILLA *db; +#if defined(HAVE_TOKYOCABINET) + TCHDB *db; #elif defined(HAVE_GDBM) GDBM_FILE db; #endif @@ -60,9 +59,6 @@ static int generate_crc32(void) #endif crc = crc32(crc, "USE_POP", m_strlen("USE_POP")); crc = crc32(crc, "USE_IMAP", m_strlen("USE_IMAP")); -#ifdef USE_NNTP - crc = crc32(crc, "USE_NNTP", m_strlen("USE_NNTP")); -#endif return crc; } @@ -276,12 +272,6 @@ static void dump_envelope(buffer_t *buf, ENVELOPE * e) dump_cstr(buf, e->x_label); dump_cstr(buf, e->list_post); -#ifdef USE_NNTP - dump_cstr(buf, e->newsgroups); - dump_cstr(buf, e->xref); - dump_cstr(buf, e->followup_to); -#endif - dump_list(buf, e->references); dump_list(buf, e->in_reply_to); dump_list(buf, e->userhdrs); @@ -313,16 +303,9 @@ static const void *restore_envelope(const char *d, ENVELOPE *e) d = restore_cstr(d, &e->x_label); d = restore_cstr(d, &e->list_post); -#ifdef USE_NNTP - d = restore_cstr(d, &e->newsgroups); - d = restore_cstr(d, &e->xref); - d = restore_cstr(d, &e->followup_to); -#endif - d = restore_list(d, &e->references); d = restore_list(d, &e->in_reply_to); d = restore_list(d, &e->userhdrs); - return d; } @@ -390,8 +373,12 @@ hcache_t *mutt_hcache_open(const char *folder) path = mutt_hcache_per_folder(mod_core.cachedir, folder); { -#if defined(HAVE_QDBM) - h->db = vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX); +#if defined(HAVE_TOKYOCABINET) + h->db = tchdbnew(); + if (!tchdbopen(h->db, path, HDBOWRITER | HDBOCREAT)) { + tchdbdel(h->db); + h->db = NULL; + } #elif defined(HAVE_GDBM) h->db = gdbm_open((char *) path, 16384, GDBM_WRCREAT, 00600, NULL); #endif @@ -409,8 +396,9 @@ void mutt_hcache_close(hcache_t **db) if (!*db) return; -#if defined(HAVE_QDBM) - vlclose((*db)->db); +#if defined(HAVE_TOKYOCABINET) + tchdbdel((*db)->db); + (*db)->db = NULL; #elif defined(HAVE_GDBM) gdbm_close((*db)->db); #endif @@ -431,11 +419,12 @@ void *mutt_hcache_fetch(hcache_t *db, const char *filename, snprintf(path, sizeof(path), "%s%s", db->folder, filename); { -#if defined(HAVE_QDBM) - int ksize = strlen(db->folder) + keylen(path + strlen(db->folder)); - data = vlget(db->db, path, ksize, NULL); + int ksize = keylen(path); +#if defined(HAVE_TOKYOCABINET) + int unused; + data = tchdbget(db->db, path, ksize, &unused); #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 @@ -466,12 +455,11 @@ int mutt_hcache_store(hcache_t *db, const char *filename, HEADER *header, 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_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); @@ -482,23 +470,23 @@ int mutt_hcache_store(hcache_t *db, const char *filename, HEADER *header, 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]; if (!db) - return -1; + return; 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_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 } }