[if test x$enableval = xyes; then
AC_DEFINE(USE_HCACHE, 1, [Enable header caching])
OLDCPPFLAGS="$CPPFLAGS"
- need_md5="yes"
ac_prefer_qdbm=yes
AC_ARG_WITH(qdbm, AC_HELP_STRING([--without-qdbm], [Don't use qdbm even if it is available]),
fi
fi
- ac_bdb_prefix=yes
- AC_ARG_WITH(bdb, AC_HELP_STRING([--with-bdb[=DIR]], [Use BerkeleyDB4 if gdbm is not available ]),
- ac_bdb_prefix=$withval)
- if test x$ac_bdb_prefix != xno -a x$ac_cv_gdbmopen != xyes -a x$ac_qdbm_here != xyes; then
- test x$ac_bdb_prefix = xyes && ac_bdb_prefix="${prefix} /opt/csw/bdb4 /opt /usr/local /usr"
- for d in $ac_bdb_prefix; do
- bdbpfx="$bdbpfx $d"
- for v in BerkeleyDB.4.3 BerkeleyDB.4.2 BerkeleyDB.4.1; do
- bdbpfx="$bdbpfx $d/$v"
- done
- done
- BDB_VERSIONS="db-4 db4 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db ''"
- AC_MSG_CHECKING([for BerkeleyDB > 4.0])
- for d in $bdbpfx; do
- BDB_INCLUDE_DIR=""
- BDB_LIB_DIR=""
- for v in / $BDB_VERSIONS; do
- if test -r "$d/include/$v/db.h"; then
- BDB_INCLUDE_DIR="$d/include/$v"
- if test -d "$d/lib/$v"; then
- BDB_LIB_DIR="$d/lib/$v"
- for l in `echo $BDB_VERSIONS`; do
- CPPFLAGS="-I$BDB_INCLUDE_DIR $OLDCPPFLAGS"
- LIBS="$MUTTLIBS -L$BDB_LIB_DIR -l$l"
- AC_TRY_LINK([
- #include <stdlib.h>
- #include <db.h>
- ],[
- DB *db = NULL;
- db->open(db,NULL,NULL,NULL,0,0,0);
- ],[
- ac_cv_dbcreate=yes
- BDB_LIB="$l"
- break
- ])
- done
- test x$ac_cv_dbcreate = xyes && break
- fi
- fi
- done
- test x$BDB_LIB != x && break
- done
- if test x$ac_cv_dbcreate = xyes; then
- AC_MSG_RESULT(yes)
- else
- AC_MSG_RESULT(no)
- fi
- fi
-
if test x$ac_qdbm_here = xyes; then
CPPFLAGS="$OLDCPPFLAGS $QDBM_CFLAGS"
MUTTLIBS="$MUTTLIBS -lqdbm"
CPPFLAGS="$OLDCPPFLAGS $GDBM_INC"
MUTTLIBS="$MUTTLIBS $GDBM_LIB -lgdbm";
AC_DEFINE(HAVE_GDBM, 1, [GDBM Support])
- elif test x$ac_cv_dbcreate = xyes; then
- CPPFLAGS="-I$BDB_INCLUDE_DIR $OLDCPPFLAGS"
- MUTTLIBS="$MUTTLIBS -L$BDB_LIB_DIR -l$BDB_LIB"
- AC_DEFINE(HAVE_DB4, 1, [Sleepycat DB4 Support])
else
AC_MSG_ERROR([You need one of: QDBM, GDBM or Sleepycat DB4 for --enable-hcache])
fi
#include <villa.h>
#elif defined(HAVE_GDBM)
#include <gdbm.h>
-#elif defined(HAVE_DB4)
-#include <db.h>
#endif
#include <imap/message.h>
GDBM_FILE db;
char *folder;
unsigned int crc;
-#elif defined(HAVE_DB4)
- DB_ENV *env;
- DB *db;
- unsigned int crc;
- int fd;
- char lockfile[_POSIX_PATH_MAX];
#endif
};
return gdbm_delete (h->db, key);
}
-#elif defined(HAVE_DB4)
-
-static void mutt_hcache_dbt_init (DBT * dbt, void *data, ssize_t len)
-{
- dbt->data = data;
- dbt->size = dbt->ulen = len;
- dbt->dlen = dbt->doff = 0;
- dbt->flags = DB_DBT_USERMEM;
-}
-
-static void mutt_hcache_dbt_empty_init (DBT * dbt)
-{
- dbt->data = NULL;
- dbt->size = dbt->ulen = dbt->dlen = dbt->doff = 0;
- dbt->flags = 0;
-}
-
-void *mutt_hcache_open (const char *path, const char *folder)
-{
- struct stat sb;
- u_int32_t createflags = DB_CREATE;
- int ret;
- struct header_cache *h = p_new(struct header_cache, 1);
- int pagesize = atoi (HeaderCachePageSize);
-
-
- h->crc = generate_crc32 ();
-
- if (!path || path[0] == '\0') {
- p_delete(&h);
- return NULL;
- }
-
- path = mutt_hcache_per_folder (path, folder);
-
- snprintf (h->lockfile, _POSIX_PATH_MAX, "%s-lock-hack", path);
-
- h->fd = open (h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
- if (h->fd < 0) {
- p_delete(&h);
- return NULL;
- }
-
- if (mx_lock_file (h->lockfile, h->fd, 1, 0, 5)) {
- close (h->fd);
- p_delete(&h);
- return NULL;
- }
-
- ret = db_env_create (&h->env, 0);
- if (ret) {
- mx_unlock_file (h->lockfile, h->fd, 0);
- close (h->fd);
- p_delete(&h);
- return NULL;
- }
-
- ret =
- (h->env->open)(h->env, NULL, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0600);
- if (!ret) {
- ret = db_create (&h->db, h->env, 0);
- if (ret) {
- h->env->close (h->env, 0);
- mx_unlock_file (h->lockfile, h->fd, 0);
- close (h->fd);
- p_delete(&h);
- return NULL;
- }
- }
-
- if (stat (path, &sb) != 0 && errno == ENOENT) {
- createflags |= DB_EXCL;
- h->db->set_pagesize (h->db, pagesize);
- }
-
- ret = (h->db->open)(h->db, NULL, path, folder, DB_BTREE, createflags, 0600);
- if (ret) {
- h->db->close (h->db, 0);
- h->env->close (h->env, 0);
- mx_unlock_file (h->lockfile, h->fd, 0);
- close (h->fd);
- p_delete(&h);
- return NULL;
- }
-
- return h;
-}
-
-void mutt_hcache_close (void *db)
-{
- struct header_cache *h = db;
-
- if (!h) {
- return;
- }
-
- h->db->close (h->db, 0);
- h->env->close (h->env, 0);
- mx_unlock_file (h->lockfile, h->fd, 0);
- close (h->fd);
- p_delete(&h);
-}
-
-void *mutt_hcache_fetch (void *db, const char *filename,
- ssize_t (*keylen) (const char *fn))
-{
- DBT key;
- DBT data;
- struct header_cache *h = db;
-
- if (!h) {
- return NULL;
- }
-
- filename++; /* skip '/' */
-
- mutt_hcache_dbt_init (&key, (void *) filename, keylen (filename));
- mutt_hcache_dbt_empty_init (&data);
- data.flags = DB_DBT_MALLOC;
-
- h->db->get (h->db, NULL, &key, &data, 0);
-
- if (!crc32_matches (data.data, h->crc)) {
- p_delete(&data.data);
- return NULL;
- }
-
- return data.data;
-}
-
-int
-mutt_hcache_store (void *db, const char *filename, HEADER * header,
- unsigned long uid_validity, ssize_t (*keylen) (const char *fn))
-{
- DBT key;
- DBT data;
- int ret;
- struct header_cache *h = db;
-
- if (!h) {
- return -1;
- }
-
- filename++; /* skip '/' */
-
- mutt_hcache_dbt_init (&key, (void *) filename, keylen (filename));
-
- mutt_hcache_dbt_empty_init (&data);
- data.flags = DB_DBT_USERMEM;
- data.data =
- mutt_hcache_dump (db, header, (signed int *) &data.size, uid_validity);
- data.ulen = data.size;
-
- ret = h->db->put (h->db, NULL, &key, &data, 0);
-
- p_delete(&data.data);
-
- return ret;
-}
-
-int
-mutt_hcache_delete (void *db, const char *filename,
- ssize_t (*keylen) (const char *fn))
-{
- DBT key;
- struct header_cache *h = db;
-
- if (!h) {
- return -1;
- }
-
- filename++; /* skip '/' */
-
- mutt_hcache_dbt_init (&key, (void *) filename, keylen (filename));
- return h->db->del (h->db, NULL, &key, 0);
-}
#endif
#endif /* USE_HCACHE */