diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | hcache.c | 318 | ||||
-rw-r--r-- | hcache.h | 36 | ||||
-rw-r--r-- | imap/imap.c | 3 | ||||
-rw-r--r-- | imap/imap_private.h | 6 | ||||
-rw-r--r-- | imap/message.c | 4 | ||||
-rw-r--r-- | mh.c | 3 | ||||
-rw-r--r-- | protos.h | 10 |
8 files changed, 195 insertions, 187 deletions
diff --git a/Makefile.am b/Makefile.am index 26d39a2e..efc98f8c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ @@ -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 index 00000000..24ad89ce --- /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_ */ diff --git a/imap/imap.c b/imap/imap.c index 0d1a0ffd..8976a998 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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> diff --git a/imap/imap_private.h b/imap/imap_private.h index 0d01df5d..c9d0fd72 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -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 diff --git a/imap/message.c b/imap/message.c index 1aee8785..02265518 100644 --- a/imap/message.c +++ b/imap/message.c @@ -36,6 +36,10 @@ #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); @@ -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> @@ -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); |