From: Pierre Habouzit Date: Tue, 20 Nov 2007 11:06:12 +0000 (+0100) Subject: Add tokyocabinet support X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=90f0c4dfb0480b5ce043c54f001d53ba6efc531b;p=apps%2Fmadmutt.git Add tokyocabinet support Signed-off-by: Pierre Habouzit --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d079eb4..338c0e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,10 +170,18 @@ ENDIF(NOT WITH_LOCKFILE) LIST(APPEND MUTTLIBS -llockfile) IF(USE_HCACHE) - OPTION(WITH_QDBM "Use qdbm for header caching [default: on]" ON) + OPTION(WITH_TC "Use tokyocabinet for header caching [default: on]" ON) + OPTION(WITH_QDBM "Use qdbm for header caching [default: off]" OFF) OPTION(WITH_GDBM "Use gdbm for header caching [default: off]") SET(USE_HCACHE) + if(WITH_TC) + pkg_search_module(TC REQUIRED tokyocabinet) + ADD_DEFINITIONS(${TC_CFLAGS}) + LIST(APPEND MUTTLIBS ${TC_LDFLAGS}) + SET(USE_HCACHE 1) + SET(HAVE_TOKYOCABINET 1) + ENDIF(WITH_TC) IF(WITH_QDBM) pkg_search_module(QDBM REQUIRED qdbm) ADD_DEFINITIONS(${QDBM_CFLAGS}) diff --git a/config.h.cmake b/config.h.cmake index 32d8734..61058b1 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -50,6 +50,7 @@ #cmakedefine HAVE_GPGME 1 #cmakedefine HAVE_LIBIDN 1 #cmakedefine HAVE_QDBM 1 +#cmakedefine HAVE_TOKYOCABINET 1 #cmakedefine USE_FCNTL 1 #cmakedefine USE_FLOCK 1 #cmakedefine USE_HCACHE 1 diff --git a/lib-lua/madmutt.cpkg b/lib-lua/madmutt.cpkg index 88479db..b47a867 100644 --- a/lib-lua/madmutt.cpkg +++ b/lib-lua/madmutt.cpkg @@ -113,7 +113,9 @@ static void madmutt_update_cachedir(const char *dir) } -#if defined(HAVE_QDBM) +#if defined(HAVE_TOKYOCABINET) +# define HCACHE_BACKEND "tokyocabinet" +#elif defined(HAVE_QDBM) # define HCACHE_BACKEND "qdbm" #elif defined(HAVE_GDBM) # define HCACHE_BACKEND "gdbm" diff --git a/lib-mx/hcache.c b/lib-mx/hcache.c index bb38c81..63ea970 100644 --- a/lib-mx/hcache.c +++ b/lib-mx/hcache.c @@ -13,14 +13,17 @@ #ifdef USE_HCACHE -#if defined(HAVE_QDBM) +#if defined(HAVE_TOKYOCABINET) +#include +#include +#elif defined(HAVE_QDBM) #include #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,7 +31,9 @@ #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; @@ -374,7 +379,13 @@ hcache_t *mutt_hcache_open(const char *folder) 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); @@ -393,7 +404,10 @@ void mutt_hcache_close(hcache_t **db) 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); @@ -415,11 +429,14 @@ 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)); + 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 @@ -450,12 +467,13 @@ 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_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); @@ -466,7 +484,7 @@ 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]; @@ -477,12 +495,14 @@ int mutt_hcache_delete(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)); - 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 } } diff --git a/lib-mx/hcache.h b/lib-mx/hcache.h index a3495c3..bdd1538 100644 --- a/lib-mx/hcache.h +++ b/lib-mx/hcache.h @@ -23,8 +23,8 @@ void *mutt_hcache_fetch(hcache_t *db, const char *filename, int mutt_hcache_store(hcache_t *db, const char *filename, HEADER *h, long uid_validity, ssize_t (*keylen)(const char *fn)); -int mutt_hcache_delete(hcache_t *db, const char *filename, - ssize_t (*keylen)(const char *fn)); +void mutt_hcache_delete(hcache_t *db, const char *filename, + ssize_t (*keylen)(const char *fn)); #endif /* USE_HCACHE */ #endif /* !_MUTT_HCACHE_H */