summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuele Giaquinta <e.giaquinta@glauco.it>2008-09-25 15:07:16 -0700
committerEmanuele Giaquinta <e.giaquinta@glauco.it>2008-09-25 15:07:16 -0700
commit7fedd3e902e7aec814d2c966b02ff6d52cb29233 (patch)
tree63b10565f57ad8f237436e09cbfe95a1ab4b33cb
parentc8aead4e6d2f54e40def5c339d31f1867e1f915a (diff)
Support tokyocabinet (successor to qdbm). Closes #3112
-rw-r--r--configure.ac40
-rw-r--r--hcache.c71
-rw-r--r--init.h2
-rw-r--r--mutt.h2
4 files changed, 106 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 05f063cc..214c5889 100644
--- a/configure.ac
+++ b/configure.ac
@@ -812,9 +812,11 @@ AC_ARG_ENABLE(exact-address, AC_HELP_STRING([--enable-exact-address], [Enable re
fi])
dnl -- start cache --
-use_qdbm=no
+db_found=no
AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache],
[Enable header caching]))
+AC_ARG_WITH(tokyocabinet, AC_HELP_STRING([--without-tokyocabinet],
+ [Don't use tokyocabinet even if it is available]))
AC_ARG_WITH(qdbm, AC_HELP_STRING([--without-qdbm],
[Don't use qdbm even if it is available]))
AC_ARG_WITH(gdbm, AC_HELP_STRING([--without-gdbm],
@@ -833,8 +835,30 @@ then
need_md5="yes"
+ dnl -- Tokyo Cabinet --
+ if test "$with_tokyocabinet" != "no"
+ then
+ if test -n "$with_tokyocabinet" && test "$with_tokyocabinet" != "yes"
+ then
+ CPPFLAGS="$CPPFLAGS -I$with_tc/include"
+ LDFLAGS="$LDFLAGS -L$with_tc/lib"
+ fi
+
+ AC_CHECK_HEADER(tcbdb.h,
+ AC_CHECK_LIB(tokyocabinet, tcbdbopen,
+ [MUTTLIBS="$MUTTLIBS -ltokyocabinet"
+ AC_DEFINE(HAVE_TC, 1, [Tokyo Cabinet Support])
+ db_found=yes],
+ [CPPFLAGS="$OLDCPPFLAGS"
+ LDFLAGS="$OLDLDFLAGS"]))
+ if test -n "$with_tokyocabinet" && test "$use_tokyocabinet" != yes
+ then
+ AC_MSG_ERROR([Tokyo Cabinet could not be used. Check config.log for details.])
+ fi
+ fi
+
dnl -- QDBM --
- if test "$with_qdbm" != "no"
+ if test "$with_qdbm" != "no" && test $db_found != yes
then
if test -n "$with_qdbm" && test "$with_qdbm" != "yes"
then
@@ -855,7 +879,7 @@ then
AC_CHECK_LIB(qdbm, vlopen,
[MUTTLIBS="$MUTTLIBS -lqdbm"
AC_DEFINE(HAVE_QDBM, 1, [QDBM Support])
- use_qdbm=yes],
+ db_found=yes],
[CPPFLAGS="$OLDCPPFLAGS"
LDFLAGS="$OLDLDFLAGS"])
LIBS="$saved_LIBS"
@@ -866,7 +890,7 @@ then
fi
dnl -- GDBM --
- if test x$with_gdbm != xno && test $use_qdbm != yes
+ if test x$with_gdbm != xno && test $db_found != yes
then
if test "$with_gdbm" != "yes"
then
@@ -884,6 +908,7 @@ then
then
AC_DEFINE(HAVE_GDBM, 1, [GDBM Support])
MUTTLIBS="$MUTTLIBS -lgdbm"
+ db_found=yes
elif test -n "$with_gdbm"
then
AC_MSG_ERROR([GDBM could not be used. Check config.log for details.])
@@ -892,7 +917,7 @@ then
dnl -- BDB --
ac_bdb_prefix="$with_bdb"
- if test x$ac_bdb_prefix != xno && test x$ac_cv_gdbmopen != xyes && test $use_qdbm != yes
+ if test x$ac_bdb_prefix != xno && test $db_found != yes
then
if test x$ac_bdb_prefix = xyes || test x$ac_bdb_prefix = x
then
@@ -942,14 +967,15 @@ then
CPPFLAGS="$OLDCPPFLAGS -I$BDB_INCLUDE_DIR"
LIBS="$OLDLIBS -L$BDB_LIB_DIR -l$BDB_LIB"
AC_DEFINE(HAVE_DB4, 1, [Berkeley DB4 Support])
+ db_found=yes
else
AC_MSG_RESULT(no)
fi
fi
- if test x$use_qdbm != xyes && test x$ac_cv_gdbmopen != xyes && test x$ac_cv_dbcreate != xyes
+ if test $db_found != yes
then
- AC_MSG_ERROR([You need QDBM, GDBM or Berkeley DB4 for hcache])
+ AC_MSG_ERROR([You need Tokyo Cabinet, QDBM, GDBM or Berkeley DB4 for hcache])
fi
fi
dnl -- end cache --
diff --git a/hcache.c b/hcache.c
index 2a988f5f..1184e97a 100644
--- a/hcache.c
+++ b/hcache.c
@@ -26,6 +26,8 @@
#include <depot.h>
#include <cabin.h>
#include <villa.h>
+#elif HAVE_TC
+#include <tcbdb.h>
#elif HAVE_GDBM
#include <gdbm.h>
#elif HAVE_DB4
@@ -55,6 +57,13 @@ static struct header_cache
char *folder;
unsigned int crc;
} HEADER_CACHE;
+#elif HAVE_TC
+static struct header_cache
+{
+ TCBDB *db;
+ char *folder;
+ unsigned int crc;
+} HEADER_CACHE;
#elif HAVE_GDBM
static struct header_cache
{
@@ -701,6 +710,9 @@ mutt_hcache_fetch_raw (header_cache_t *h, const char *filename,
#endif
#ifdef HAVE_QDBM
char *data = NULL;
+#elif HAVE_TC
+ void *data;
+ int sp;
#elif HAVE_GDBM
datum key;
datum data;
@@ -733,6 +745,10 @@ mutt_hcache_fetch_raw (header_cache_t *h, const char *filename,
data = vlget(h->db, path, ksize, NULL);
return data;
+#elif HAVE_TC
+ data = tcbdbget(h->db, path, ksize, &sp);
+
+ return data;
#elif HAVE_GDBM
key.dptr = path;
key.dsize = ksize;
@@ -803,6 +819,8 @@ mutt_hcache_store_raw (header_cache_t* h, const char* filename, void* data,
#endif
#if HAVE_QDBM
return vlput(h->db, path, ksize, data, dlen, VL_DOVER);
+#elif HAVE_TC
+ return tcbdbput(h->db, path, ksize, data, dlen);
#elif HAVE_GDBM
key.dptr = path;
key.dsize = ksize;
@@ -876,6 +894,52 @@ mutt_hcache_delete(header_cache_t *h, const char *filename,
return vlout(h->db, path, ksize);
}
+#elif HAVE_TC
+static int
+hcache_open_tc (struct header_cache* h, const char* path)
+{
+ h->db = tcbdbnew();
+ if (option(OPTHCACHECOMPRESS))
+ tcbdbtune(h->db, 0, 0, 0, -1, -1, BDBTDEFLATE);
+ if (tcbdbopen(h->db, path, BDBOWRITER | BDBOCREAT))
+ return 0;
+ else
+ {
+ tcbdbdel(h->db);
+ return -1;
+ }
+}
+
+void
+mutt_hcache_close(header_cache_t *h)
+{
+ if (!h)
+ return;
+
+ tcbdbclose(h->db);
+ tcbdbdel(h->db);
+ FREE(&h->folder);
+ FREE(&h);
+}
+
+int
+mutt_hcache_delete(header_cache_t *h, const char *filename,
+ size_t(*keylen) (const char *fn))
+{
+ char path[_POSIX_PATH_MAX];
+ int ksize;
+
+ if (!h)
+ return -1;
+
+ strncpy(path, h->folder, sizeof (path));
+ safe_strcat(path, sizeof (path), filename);
+
+ ksize = strlen(h->folder) + keylen(path + strlen(h->folder));
+
+ return tcbdbout(h->db, path, ksize);
+}
+
#elif HAVE_GDBM
static int
hcache_open_gdbm (struct header_cache* h, const char* path)
@@ -1039,6 +1103,8 @@ mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
#if HAVE_QDBM
hcache_open = hcache_open_qdbm;
+#elif HAVE_TC
+ hcache_open= hcache_open_tc;
#elif HAVE_GDBM
hcache_open = hcache_open_gdbm;
#elif HAVE_DB4
@@ -1090,4 +1156,9 @@ const char *mutt_hcache_backend (void)
{
return "qdbm " _QDBM_VERSION;
}
+#elif HAVE_TC
+const char *mutt_hcache_backend (void)
+{
+ return "tokyocabinet " _TC_VERSION;
+}
#endif
diff --git a/init.h b/init.h
index f55fbf2a..2a8cfaae 100644
--- a/init.h
+++ b/init.h
@@ -1223,7 +1223,7 @@ struct option_t MuttVars[] = {
** or less optimal for most use cases.
*/
#endif /* HAVE_GDBM || HAVE_DB4 */
-#if defined(HAVE_QDBM)
+#if defined(HAVE_QDBM) || defined(HAVE_TC)
{ "header_cache_compress", DT_BOOL, R_NONE, OPTHCACHECOMPRESS, 1 },
/*
** .pp
diff --git a/mutt.h b/mutt.h
index 09e2f559..94a7d4f5 100644
--- a/mutt.h
+++ b/mutt.h
@@ -339,7 +339,7 @@ enum
OPTFORWQUOTE,
#ifdef USE_HCACHE
OPTHCACHEVERIFY,
-#ifdef HAVE_QDBM
+#if defined(HAVE_QDBM) || defined(HAVE_TC)
OPTHCACHECOMPRESS,
#endif /* HAVE_QDBM */
#endif