]> granicus.if.org Git - mutt/commitdiff
Refactor header cache a bit to provide (fetch|store)_raw functions. These
authorBrendan Cully <brendan@kublai.com>
Tue, 20 Dec 2005 17:50:46 +0000 (17:50 +0000)
committerBrendan Cully <brendan@kublai.com>
Tue, 20 Dec 2005 17:50:46 +0000 (17:50 +0000)
will let me keep folder metadata (UIDVALIDITY, NEXT, msg count etc) in the
cache, which will help to sync more quickly.

Makefile.am
hcache.c
hcache.h [new file with mode: 0644]
imap/imap.c
imap/imap_private.h
imap/message.c
mh.c
protos.h

index 26d39a2e2818cc813d30c221bb13427824d0c3bb..efc98f8c7a4e22a2943b0f9f2c5dd6194a5b93a3 100644 (file)
@@ -63,7 +63,7 @@ EXTRA_mutt_SOURCES = account.c md5c.c mutt_sasl.c mutt_socket.c mutt_ssl.c \
        pgplib.c sha1.c pgpmicalg.c gnupgparse.c resize.c dotlock.c remailer.c \
        browser.h mbyte.h remailer.h url.h \
        crypt-mod-pgp-classic.c crypt-mod-smime-classic.c \
-       pgppacket.c mutt_idna.h hcache.c mutt_ssl_gnutls.c \
+       pgppacket.c mutt_idna.h hcache.h hcache.c mutt_ssl_gnutls.c \
        crypt-gpgme.c crypt-mod-pgp-gpgme.c crypt-mod-smime-gpgme.c
 
 EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO \
index 24c240b12815c5783b2776a93fdc1db821ea6811..6939ced3451b5e863150aad0f43ba2754387d530 100644 (file)
--- a/hcache.c
+++ b/hcache.c
@@ -40,6 +40,7 @@
 #include <sys/time.h>
 #endif
 #include "mutt.h"
+#include "hcache.h"
 #ifdef USE_IMAP
 #include "message.h"
 #endif
@@ -628,6 +629,151 @@ mutt_hcache_restore(const unsigned char *d, HEADER ** oh)
   return h;
 }
 
+void *
+mutt_hcache_fetch(void *db, const char *filename,
+                 size_t(*keylen) (const char *fn))
+{
+  struct header_cache *h = db;
+  void* data;
+  
+  data = mutt_hcache_fetch_raw (db, filename, keylen);
+  
+  if (!crc32_matches(data, h->crc))
+  {
+    FREE(&data);
+    return NULL;
+  }
+  
+  return data;
+}
+
+void *
+mutt_hcache_fetch_raw (void *db, const char *filename,
+                       size_t(*keylen) (const char *fn))
+{
+  struct header_cache *h = db;
+#ifndef HAVE_DB4
+  char path[_POSIX_PATH_MAX];
+  int ksize;
+#endif
+#ifdef HAVE_QDBM
+  char *data = NULL;
+#elif HAVE_GDBM
+  datum key;
+  datum data;
+#elif HAVE_DB4
+  DBT key;
+  DBT data;
+#endif
+  
+  if (!h)
+    return NULL;
+  
+#ifdef HAVE_DB4
+  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);
+  
+  return data.data;
+#else
+  strncpy(path, h->folder, sizeof (path));
+  safe_strcat(path, sizeof (path), filename);
+
+  ksize = strlen (h->folder) + keylen (path + strlen (h->folder));  
+#endif
+#ifdef HAVE_QDBM
+  data = vlget(h->db, path, ksize, NULL);
+  
+  return data;
+#elif HAVE_GDBM
+  key.dptr = path;
+  key.dsize = ksize;
+  
+  data = gdbm_fetch(h->db, key);
+  
+  return data.dptr;
+#endif
+}
+
+int
+mutt_hcache_store(void *db, const char *filename, HEADER * header,
+                 unsigned long uid_validity,
+                 size_t(*keylen) (const char *fn))
+{
+  struct header_cache *h = db;
+  char* data;
+  int dlen;
+  int ret;
+  
+  if (!h)
+    return -1;
+  
+  data = mutt_hcache_dump(db, header, &dlen, uid_validity);
+  ret = mutt_hcache_store_raw (db, filename, data, dlen, keylen);
+  
+  FREE(&data);
+  
+  return ret;
+}
+
+int
+mutt_hcache_store_raw (void* db, const char* filename, char* data,
+                       size_t dlen, size_t(*keylen) (const char* fn))
+{
+  struct header_cache *h = db;
+#ifndef HAVE_DB4
+  char path[_POSIX_PATH_MAX];
+  int ksize;
+#endif
+#if HAVE_QDBM
+  int dsize;
+  char *data = NULL;
+#elif HAVE_GDBM
+  datum key;
+  datum databuf;
+#elif HAVE_DB4
+  DBT key;
+  DBT databuf;
+#endif
+  
+  if (!h)
+    return -1;
+
+#if HAVE_DB4
+  filename++;                  /* skip '/' */
+  
+  mutt_hcache_dbt_init(&key, (void *) filename, keylen(filename));
+  
+  mutt_hcache_dbt_empty_init(&databuf);
+  databuf.flags = DB_DBT_USERMEM;
+  databuf.data = data;
+  databuf.size = dlen;
+  databuf.ulen = dlen;
+  
+  return h->db->put(h->db, NULL, &key, &data, 0);
+#else
+  strncpy(path, h->folder, sizeof (path));
+  safe_strcat(path, sizeof (path), filename);
+
+  ksize = strlen(h->folder) + keylen(path + strlen(h->folder));
+#endif
+#if HAVE_QDBM
+  return vlput(h->db, path, ksize, data, dlen, VL_DOVER);
+#elif HAVE_GDBM
+  key.dptr = path;
+  key.dsize = ksize;
+  
+  databuf.dsize = dlen;
+  databuf.dptr = data;
+  
+  return gdbm_store(h->db, key, databuf, GDBM_REPLACE);
+#endif
+}
+
 #if HAVE_QDBM
 void *
 mutt_hcache_open(const char *path, const char *folder)
@@ -675,62 +821,6 @@ mutt_hcache_close(void *db)
   FREE(&h);
 }
 
-void *
-mutt_hcache_fetch(void *db, const char *filename,
-                 size_t(*keylen) (const char *fn))
-{
-  struct header_cache *h = db;
-  char path[_POSIX_PATH_MAX];
-  int ksize;
-  char *data = NULL;
-
-  if (!h)
-    return NULL;
-
-  strncpy(path, h->folder, sizeof (path));
-  safe_strcat(path, sizeof (path), filename);
-
-  ksize = strlen(h->folder) + keylen(path + strlen(h->folder));
-
-  data = vlget(h->db, path, ksize, NULL);
-
-  if (! crc32_matches(data, h->crc))
-  {
-    FREE(&data);
-    return NULL;
-  }
-
-  return data;
-}
-
-int
-mutt_hcache_store(void *db, const char *filename, HEADER * header,
-                 unsigned long uid_validity,
-                 size_t(*keylen) (const char *fn))
-{
-  struct header_cache *h = db;
-  char path[_POSIX_PATH_MAX];
-  int ret;
-  int ksize, dsize;
-  char *data = NULL;
-
-  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));
-
-  data  = mutt_hcache_dump(db, header, &dsize, uid_validity);
-
-  ret = vlput(h->db, path, ksize, data, dsize, VL_DOVER);
-
-  FREE(&data);
-
-  return ret;
-}
-
 int
 mutt_hcache_delete(void *db, const char *filename,
                   size_t(*keylen) (const char *fn))
@@ -800,64 +890,6 @@ mutt_hcache_close(void *db)
   FREE(&h);
 }
 
-void *
-mutt_hcache_fetch(void *db, const char *filename,
-                 size_t(*keylen) (const char *fn))
-{
-  struct header_cache *h = db;
-  datum key;
-  datum data;
-  char path[_POSIX_PATH_MAX];
-
-  if (!h)
-    return NULL;
-
-  strncpy(path, h->folder, sizeof (path));
-  safe_strcat(path, sizeof (path), filename);
-
-  key.dptr = path;
-  key.dsize = strlen(h->folder) + keylen(path + strlen(h->folder));
-
-  data = gdbm_fetch(h->db, key);
-
-  if (!crc32_matches(data.dptr, h->crc))
-  {
-    FREE(&data.dptr);
-    return NULL;
-  }
-
-  return data.dptr;
-}
-
-int
-mutt_hcache_store(void *db, const char *filename, HEADER * header,
-                 unsigned long uid_validity,
-                 size_t(*keylen) (const char *fn))
-{
-  struct header_cache *h = db;
-  datum key;
-  datum data;
-  char path[_POSIX_PATH_MAX];
-  int ret;
-
-  if (!h)
-    return -1;
-
-  strncpy(path, h->folder, sizeof (path));
-  safe_strcat(path, sizeof (path), filename);
-
-  key.dptr = path;
-  key.dsize = strlen(h->folder) + keylen(path + strlen(h->folder));
-
-  data.dptr = mutt_hcache_dump(db, header, &data.dsize, uid_validity);
-
-  ret = gdbm_store(h->db, key, data, GDBM_REPLACE);
-
-  FREE(&data.dptr);
-
-  return ret;
-}
-
 int
 mutt_hcache_delete(void *db, const char *filename,
                   size_t(*keylen) (const char *fn))
@@ -990,64 +1022,6 @@ mutt_hcache_close(void *db)
   FREE(&h);
 }
 
-void *
-mutt_hcache_fetch(void *db, const char *filename,
-                 size_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))
-  {
-    FREE(&data.data);
-    return NULL;
-  }
-
-  return data.data;
-}
-
-int
-mutt_hcache_store(void *db, const char *filename, HEADER * header,
-                 unsigned long uid_validity,
-                 size_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);
-
-  FREE(&data.data);
-
-  return ret;
-}
-
 int
 mutt_hcache_delete(void *db, const char *filename,
                   size_t(*keylen) (const char *fn))
diff --git a/hcache.h b/hcache.h
new file mode 100644 (file)
index 0000000..24ad89c
--- /dev/null
+++ b/hcache.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2004 Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
+ * Copyright (C) 2004 Tobias Werth <sitowert@stud.uni-erlangen.de>
+ * Copyright (C) 2004 Brian Fundakowski Feldman <green@FreeBSD.org>
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     This program is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ *     You should have received a copy of the GNU General Public License
+ *     along with this program; if not, write to the Free Software
+ *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef _HCACHE_H_
+#define _HCACHE_H_ 1
+
+void *mutt_hcache_open(const char *path, const char *folder);
+void mutt_hcache_close(void *db);
+HEADER *mutt_hcache_restore(const unsigned char *d, HEADER **oh);
+void *mutt_hcache_fetch(void *db, const char *filename, size_t (*keylen)(const char *fn));
+void *mutt_hcache_fetch_raw (void *db, const char *filename,
+                             size_t (*keylen)(const char *fn));
+int mutt_hcache_store(void *db, const char *filename, HEADER *h,
+                      unsigned long uid_validity, size_t (*keylen)(const char *fn));
+int mutt_hcache_store_raw (void* db, const char* filename, char* data,
+                           size_t dlen, size_t(*keylen) (const char* fn));
+int mutt_hcache_delete(void *db, const char *filename, size_t (*keylen)(const char *fn));
+
+#endif /* _HCACHE_H_ */
index 0d1a0ffd38b3966647803d44eca367b757602224..8976a998b8729bd8c5430effcd31813c1063aadb 100644 (file)
@@ -36,6 +36,9 @@
 # include "mutt_ssl.h"
 #endif
 #include "buffy.h"
+#if USE_HCACHE
+#include "hcache.h"
+#endif
 
 #include <unistd.h>
 #include <ctype.h>
index 0d01df5d819920a9c0f0650f6a944de8a6d7f5a5..c9d0fd722d4e4382a1f48589b32308f5c87c0b80 100644 (file)
@@ -288,10 +288,8 @@ void imap_utf7_encode (char **s);
 void imap_utf7_decode (char **s);
 
 #if USE_HCACHE
-static size_t imap_hcache_keylen (const char *fn)
-{
-  return mutt_strlen(fn);
-}
+/* typedef size_t (*hcache_keylen_t)(const char* fn); */
+#define imap_hcache_keylen mutt_strlen
 #endif /* USE_HCACHE */
 
 #endif
index 1aee87851571a4c80dd4593f122a1c001922a620..0226551841cbf92c39e6f8e32b3dfc7f662af566 100644 (file)
 #include "pgp.h"
 #endif
 
+#if USE_HCACHE
+#include "hcache.h"
+#endif
+
 static void flush_buffer(char* buf, size_t* len, CONNECTION* conn);
 static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf,
   FILE* fp);
diff --git a/mh.c b/mh.c
index d81f00954730f197e4ed6f96dd7ca2596150049d..0248d584b52465d4497659789f6ebee0f58683e1 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -32,6 +32,9 @@
 #include "copy.h"
 #include "buffy.h"
 #include "sort.h"
+#if USE_HCACHE
+#include "hcache.h"
+#endif
 
 #include <sys/stat.h>
 #include <sys/types.h>
index 9b11ee1e4b7e698f0a5e3c8e2bdc3e236c1eddb0..ffda04476945c2df6e9bf95c24dcfe23353a4a6b 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -109,16 +109,6 @@ char *mutt_read_rfc822_line (FILE *, char *, size_t *);
 ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short);
 HEADER *mutt_dup_header (HEADER *);
 
-#if USE_HCACHE
-void *mutt_hcache_open(const char *path, const char *folder);
-void mutt_hcache_close(void *db);
-HEADER *mutt_hcache_restore(const unsigned char *d, HEADER **oh);
-void *mutt_hcache_fetch(void *db, const char *filename, size_t (*keylen)(const char *fn));
-int mutt_hcache_store(void *db, const char *filename, HEADER *h, unsigned long uid_validity, size_t (*keylen)(const char *fn));
-int mutt_hcache_delete(void *db, const char *filename, size_t (*keylen)(const char *fn));
-#endif /* USE_HCACHE */
-
-
 time_t mutt_decrease_mtime (const char *, struct stat *);
 time_t mutt_local_tz (time_t);
 time_t mutt_mktime (struct tm *, int);