X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=hcache.c;h=fd706db266aac446d5efd897c26cf9a685835e0e;hp=734014d6fd649ddfee9cf1ef7c574da59e08abd6;hb=1dc7032b59cc5b91d70076ed228bda8caf65a7f3;hpb=39066752e08757d65381c18b27b2df0860574472 diff --git a/hcache.c b/hcache.c index 734014d..fd706db 100644 --- a/hcache.c +++ b/hcache.c @@ -8,6 +8,13 @@ * It's licensed under the GNU General Public License, * please see the file GPL in the top level source directory. */ +#if HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#ifdef USE_HCACHE + +#define MUTTNG_HCACHE_ID "0x004" # if HAVE_INTTYPES_H # include @@ -17,12 +24,6 @@ # endif # endif -#if HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#ifdef USE_HCACHE - #if HAVE_QDBM #include #include @@ -38,6 +39,9 @@ #if HAVE_SYS_TIME_H #include #endif + +#include + #include "mutt.h" #ifdef USE_IMAP #include "message.h" @@ -47,7 +51,6 @@ #include "lib.h" #include "md5.h" -#include "lib/mem.h" #include "lib/debug.h" #if HAVE_QDBM @@ -86,7 +89,7 @@ static void *lazy_malloc (size_t siz) siz = 4096; } - return safe_malloc (siz); + return xmalloc(siz); } static void lazy_realloc (void *ptr, size_t siz) @@ -97,7 +100,7 @@ static void lazy_realloc (void *ptr, size_t siz) return; } - safe_realloc (ptr, siz); + p_realloc(ptr, siz); } static unsigned char *dump_int (unsigned int i, unsigned char *d, int *off) @@ -125,7 +128,7 @@ static unsigned char *dump_char (char *c, unsigned char *d, int *off) return d; } - size = safe_strlen (c) + 1; + size = str_len (c) + 1; d = dump_int (size, d, off); lazy_realloc (&d, *off + size); memcpy (d + *off, c, size); @@ -164,8 +167,7 @@ static void restore_char (char **c, const unsigned char *d, int *off) return; } - *c = safe_malloc (size); - memcpy (*c, d + *off, size); + *c = p_dup(d + *off, size); *off += size; } @@ -177,9 +179,6 @@ static unsigned char *dump_address (ADDRESS * a, unsigned char *d, int *off) d = dump_int (0xdeadbeef, d, off); while (a) { -#ifdef EXACT_ADDRESS - d = dump_char (a->val, d, off); -#endif d = dump_char (a->personal, d, off); d = dump_char (a->mailbox, d, off); d = dump_int (a->group, d, off); @@ -199,10 +198,7 @@ static void restore_address (ADDRESS ** a, const unsigned char *d, int *off) restore_int (&counter, d, off); while (counter) { - *a = safe_malloc (sizeof (ADDRESS)); -#ifdef EXACT_ADDRESS - restore_char (&(*a)->val, d, off); -#endif + *a = p_new(ADDRESS, 1); restore_char (&(*a)->personal, d, off); restore_char (&(*a)->mailbox, d, off); restore_int ((unsigned int *) &(*a)->group, d, off); @@ -238,7 +234,7 @@ static void restore_list (LIST ** l, const unsigned char *d, int *off) restore_int (&counter, d, off); while (counter) { - *l = safe_malloc (sizeof (LIST)); + *l = p_new(LIST, 1); restore_char (&(*l)->data, d, off); l = &(*l)->next; counter--; @@ -276,7 +272,7 @@ static void restore_buffer (BUFFER ** b, const unsigned char *d, int *off) return; } - *b = safe_malloc (sizeof (BUFFER)); + *b = p_new(BUFFER, 1); restore_char (&(*b)->data, d, off); restore_int (&offset, d, off); @@ -314,7 +310,7 @@ restore_parameter (PARAMETER ** p, const unsigned char *d, int *off) restore_int (&counter, d, off); while (counter) { - *p = safe_malloc (sizeof (PARAMETER)); + *p = p_new(PARAMETER, 1); restore_char (&(*p)->attribute, d, off); restore_char (&(*p)->value, d, off); p = &(*p)->next; @@ -381,6 +377,7 @@ static unsigned char *dump_envelope (ENVELOPE * e, unsigned char *d, int *off) d = dump_char (e->supersedes, d, off); d = dump_char (e->date, d, off); d = dump_char (e->x_label, d, off); + d = dump_char (e->list_post, d, off); #ifdef USE_NNTP d = dump_char (e->newsgroups, d, off); @@ -421,7 +418,8 @@ static void restore_envelope (ENVELOPE * e, const unsigned char *d, int *off) restore_char (&e->supersedes, d, off); restore_char (&e->date, d, off); restore_char (&e->x_label, d, off); - + restore_char (&e->list_post, d, off); + #ifdef USE_NNTP restore_char (&e->newsgroups, d, off); restore_char (&e->xref, d, off); @@ -452,42 +450,36 @@ static int generate_crc32 () int crc = 0; crc = crc32 (crc, (unsigned char const *) - "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613", - safe_strlen - ("sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613")); + MUTTNG_HCACHE_ID "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613", + str_len + (MUTTNG_HCACHE_ID "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613")); #if HAVE_LANGINFO_CODESET - crc = crc32 (crc, (unsigned char const *) Charset, safe_strlen (Charset)); + crc = crc32 (crc, (unsigned char const *) Charset, str_len (Charset)); crc = crc32 (crc, (unsigned char const *) "HAVE_LANGINFO_CODESET", - safe_strlen ("HAVE_LANGINFO_CODESET")); -#endif - -#if EXACT_ADDRESS - crc = - crc32 (crc, (unsigned char const *) "EXACT_ADDRESS", - safe_strlen ("EXACT_ADDRESS")); + str_len ("HAVE_LANGINFO_CODESET")); #endif #ifdef USE_POP crc = - crc32 (crc, (unsigned char const *) "USE_POP", safe_strlen ("USE_POP")); + crc32 (crc, (unsigned char const *) "USE_POP", str_len ("USE_POP")); #endif #ifdef MIXMASTER crc = crc32 (crc, (unsigned char const *) "MIXMASTER", - safe_strlen ("MIXMASTER")); + str_len ("MIXMASTER")); #endif #ifdef USE_IMAP crc = - crc32 (crc, (unsigned char const *) "USE_IMAP", safe_strlen ("USE_IMAP")); + crc32 (crc, (unsigned char const *) "USE_IMAP", str_len ("USE_IMAP")); #endif #ifdef USE_NNTP crc = - crc32 (crc, (unsigned char const *) "USE_NNTP", safe_strlen ("USE_NNTP")); + crc32 (crc, (unsigned char const *) "USE_NNTP", str_len ("USE_NNTP")); #endif return crc; } @@ -526,7 +518,7 @@ static const char *mutt_hcache_per_folder (const char *path, } MD5Init (&md5); - MD5Update (&md5, (unsigned char *) folder, safe_strlen (folder)); + MD5Update (&md5, (unsigned char *) folder, str_len (folder)); MD5Final (md5sum, &md5); ret = snprintf (mutt_hcache_per_folder_path, _POSIX_PATH_MAX, @@ -605,7 +597,7 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) /* this is needed for maildir style mailboxes */ if (oh) { h->old = (*oh)->old; - h->path = safe_strdup ((*oh)->path); + h->path = str_dup ((*oh)->path); mutt_free_header (oh); } @@ -616,19 +608,16 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) void * mutt_hcache_open(const char *path, const char *folder) { - struct header_cache *h = safe_calloc(1, sizeof (HEADER_CACHE)); + struct header_cache *h = p_new(HEADER_CACHE, 1); int flags = VL_OWRITER | VL_OCREAT; -#if 0 /* FIXME */ - int pagesize = atoi(HeaderCachePageSize) ? atoi(HeaderCachePageSize) : 16384; -#endif h->db = NULL; - h->folder = safe_strdup(folder); + h->folder = str_dup(folder); h->crc = generate_crc32(); if (!path || path[0] == '\0') { - FREE(&h->folder); - FREE(&h); + p_delete(&h->folder); + p_delete(&h); return NULL; } @@ -642,8 +631,8 @@ mutt_hcache_open(const char *path, const char *folder) return h; else { - FREE(&h->folder); - FREE(&h); + p_delete(&h->folder); + p_delete(&h); return NULL; } @@ -658,8 +647,8 @@ mutt_hcache_close(void *db) return; vlclose(h->db); - FREE(&h->folder); - FREE(&h); + p_delete(&h->folder); + p_delete(&h); } void * @@ -675,7 +664,7 @@ mutt_hcache_fetch(void *db, const char *filename, return NULL; strncpy(path, h->folder, sizeof (path)); - safe_strcat(path, sizeof (path), filename); + str_cat(path, sizeof (path), filename); ksize = strlen(h->folder) + keylen(path + strlen(h->folder)); @@ -683,9 +672,7 @@ mutt_hcache_fetch(void *db, const char *filename, if (! crc32_matches(data, h->crc)) { - if (data) { - FREE(&data); - } + p_delete(&data); return NULL; } @@ -707,7 +694,7 @@ mutt_hcache_store(void *db, const char *filename, HEADER * header, return -1; strncpy(path, h->folder, sizeof (path)); - safe_strcat(path, sizeof (path), filename); + str_cat(path, sizeof (path), filename); ksize = strlen(h->folder) + keylen(path + strlen(h->folder)); @@ -715,7 +702,7 @@ mutt_hcache_store(void *db, const char *filename, HEADER * header, ret = vlput(h->db, path, ksize, data, dsize, VL_DOVER); - FREE(&data); + p_delete(&data); return ret; } @@ -732,7 +719,7 @@ mutt_hcache_delete(void *db, const char *filename, return -1; strncpy(path, h->folder, sizeof (path)); - safe_strcat(path, sizeof (path), filename); + str_cat(path, sizeof (path), filename); ksize = strlen(h->folder) + keylen(path + strlen(h->folder)); @@ -743,16 +730,16 @@ mutt_hcache_delete(void *db, const char *filename, void *mutt_hcache_open (const char *path, const char *folder) { - struct header_cache *h = safe_calloc (1, sizeof (HEADER_CACHE)); + struct header_cache *h = p_new(HEADER_CACHE, 1); int pagesize = atoi (HeaderCachePageSize) ? atoi (HeaderCachePageSize) : 16384; h->db = NULL; - h->folder = safe_strdup (folder); + h->folder = str_dup (folder); h->crc = generate_crc32 (); if (!path || path[0] == '\0') { - FREE (&h->folder); - FREE (&h); + p_delete(&h->folder); + p_delete(&h); return NULL; } @@ -769,8 +756,8 @@ void *mutt_hcache_open (const char *path, const char *folder) return h; } else { - FREE (&h->folder); - FREE (&h); + p_delete(&h->folder); + p_delete(&h); return NULL; } @@ -785,8 +772,8 @@ void mutt_hcache_close (void *db) } gdbm_close (h->db); - FREE (&h->folder); - FREE (&h); + p_delete(&h->folder); + p_delete(&h); } void *mutt_hcache_fetch (void *db, const char *filename, @@ -802,7 +789,7 @@ void *mutt_hcache_fetch (void *db, const char *filename, } strncpy (path, h->folder, sizeof (path)); - strncat (path, filename, sizeof (path) - safe_strlen (path)); + strncat (path, filename, sizeof (path) - str_len (path)); key.dptr = path; key.dsize = keylen (path); @@ -810,7 +797,7 @@ void *mutt_hcache_fetch (void *db, const char *filename, data = gdbm_fetch (h->db, key); if (!crc32_matches (data.dptr, h->crc)) { - free (data.dptr); + p_delete(&data.dptr); return NULL; } @@ -832,7 +819,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, } strncpy (path, h->folder, sizeof (path)); - strncat (path, filename, sizeof (path) - safe_strlen (path)); + strncat (path, filename, sizeof (path) - str_len (path)); key.dptr = path; key.dsize = keylen (path); @@ -841,7 +828,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, ret = gdbm_store (h->db, key, data, GDBM_REPLACE); - FREE (&data.dptr); + p_delete(&data.dptr); return ret; } @@ -859,7 +846,7 @@ mutt_hcache_delete (void *db, const char *filename, } strncpy (path, h->folder, sizeof (path)); - strncat (path, filename, sizeof (path) - safe_strlen (path)); + strncat (path, filename, sizeof (path) - str_len (path)); key.dptr = path; key.dsize = keylen (path); @@ -895,7 +882,7 @@ void *mutt_hcache_open (const char *path, const char *folder) h->crc = generate_crc32 (); if (!path || path[0] == '\0') { - FREE (&h); + p_delete(&h); return NULL; } @@ -905,13 +892,13 @@ void *mutt_hcache_open (const char *path, const char *folder) h->fd = open (h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (h->fd < 0) { - FREE (&h); + p_delete(&h); return NULL; } if (mx_lock_file (h->lockfile, h->fd, 1, 0, 5)) { close (h->fd); - FREE (&h); + p_delete(&h); return NULL; } @@ -919,19 +906,19 @@ void *mutt_hcache_open (const char *path, const char *folder) if (ret) { mx_unlock_file (h->lockfile, h->fd, 0); close (h->fd); - FREE (&h); + p_delete(&h); return NULL; } ret = - h->env->open (h->env, NULL, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0600); + (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); - FREE (&h); + p_delete(&h); return NULL; } } @@ -941,13 +928,13 @@ void *mutt_hcache_open (const char *path, const char *folder) h->db->set_pagesize (h->db, pagesize); } - ret = h->db->open (h->db, NULL, path, folder, DB_BTREE, createflags, 0600); + 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); - FREE (&h); + p_delete(&h); return NULL; } @@ -957,7 +944,6 @@ void *mutt_hcache_open (const char *path, const char *folder) void mutt_hcache_close (void *db) { struct header_cache *h = db; - int ret; if (!h) { return; @@ -967,7 +953,7 @@ void mutt_hcache_close (void *db) h->env->close (h->env, 0); mx_unlock_file (h->lockfile, h->fd, 0); close (h->fd); - FREE (&h); + p_delete(&h); } void *mutt_hcache_fetch (void *db, const char *filename, @@ -990,7 +976,7 @@ void *mutt_hcache_fetch (void *db, const char *filename, h->db->get (h->db, NULL, &key, &data, 0); if (!crc32_matches (data.data, h->crc)) { - free (data.data); + p_delete(&data.data); return NULL; } @@ -1022,7 +1008,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, ret = h->db->put (h->db, NULL, &key, &data, 0); - FREE (&data.data); + p_delete(&data.data); return ret; }