X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=hcache.c;h=1a86d4c5690c68229fafbadc69e30014b5b78b85;hp=f64a60102aa795bb1ee144202930e2c69b5044a2;hb=5945a5016adb82ec9a29c9f7741cea269484e608;hpb=debd2491451020d9fd5f0440bb2dada0b9eac6e7 diff --git a/hcache.c b/hcache.c index f64a601..1a86d4c 100644 --- a/hcache.c +++ b/hcache.c @@ -8,6 +8,11 @@ * 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 # if HAVE_INTTYPES_H # include @@ -17,12 +22,6 @@ # endif # endif -#if HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#ifdef USE_HCACHE - #if HAVE_QDBM #include #include @@ -86,7 +85,7 @@ static void *lazy_malloc (size_t siz) siz = 4096; } - return safe_malloc (siz); + return mem_malloc (siz); } static void lazy_realloc (void *ptr, size_t siz) @@ -97,7 +96,7 @@ static void lazy_realloc (void *ptr, size_t siz) return; } - safe_realloc (ptr, siz); + mem_realloc (ptr, siz); } static unsigned char *dump_int (unsigned int i, unsigned char *d, int *off) @@ -125,7 +124,7 @@ static unsigned char *dump_char (char *c, unsigned char *d, int *off) return d; } - size = mutt_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,7 +163,7 @@ static void restore_char (char **c, const unsigned char *d, int *off) return; } - *c = safe_malloc (size); + *c = mem_malloc (size); memcpy (*c, d + *off, size); *off += size; } @@ -196,7 +195,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)); + *a = mem_malloc (sizeof (ADDRESS)); restore_char (&(*a)->personal, d, off); restore_char (&(*a)->mailbox, d, off); restore_int ((unsigned int *) &(*a)->group, d, off); @@ -232,7 +231,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 = mem_malloc (sizeof (LIST)); restore_char (&(*l)->data, d, off); l = &(*l)->next; counter--; @@ -270,7 +269,7 @@ static void restore_buffer (BUFFER ** b, const unsigned char *d, int *off) return; } - *b = safe_malloc (sizeof (BUFFER)); + *b = mem_malloc (sizeof (BUFFER)); restore_char (&(*b)->data, d, off); restore_int (&offset, d, off); @@ -308,7 +307,7 @@ restore_parameter (PARAMETER ** p, const unsigned char *d, int *off) restore_int (&counter, d, off); while (counter) { - *p = safe_malloc (sizeof (PARAMETER)); + *p = mem_malloc (sizeof (PARAMETER)); restore_char (&(*p)->attribute, d, off); restore_char (&(*p)->value, d, off); p = &(*p)->next; @@ -387,15 +386,12 @@ static unsigned char *dump_envelope (ENVELOPE * e, unsigned char *d, int *off) d = dump_list (e->in_reply_to, d, off); d = dump_list (e->userhdrs, d, off); - d = dump_int (e->irt_changed, d, off); - d = dump_int (e->refs_changed, d, off); - return d; } static void restore_envelope (ENVELOPE * e, const unsigned char *d, int *off) { - int tmp = 0; + int real_subj_off; restore_address (&e->return_path, d, off); restore_address (&e->from, d, off); @@ -407,9 +403,9 @@ static void restore_envelope (ENVELOPE * e, const unsigned char *d, int *off) restore_address (&e->mail_followup_to, d, off); restore_char (&e->subject, d, off); - restore_int ((unsigned int *) (&tmp), d, off); - if (0 <= tmp) { - e->real_subj = e->subject + tmp; + restore_int ((unsigned int *) (&real_subj_off), d, off); + if (0 <= real_subj_off) { + e->real_subj = e->subject + real_subj_off; } else { e->real_subj = NULL; @@ -429,11 +425,6 @@ static void restore_envelope (ENVELOPE * e, const unsigned char *d, int *off) restore_list (&e->references, d, off); restore_list (&e->in_reply_to, d, off); restore_list (&e->userhdrs, d, off); - - restore_int ((unsigned int *) &tmp, d, off); - e->irt_changed = tmp; - restore_int ((unsigned int *) &tmp, d, off); - e->refs_changed = tmp; } static @@ -455,35 +446,35 @@ static int generate_crc32 () crc = crc32 (crc, (unsigned char const *) "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613", - mutt_strlen + str_len ("sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613")); #if HAVE_LANGINFO_CODESET - crc = crc32 (crc, (unsigned char const *) Charset, mutt_strlen (Charset)); + crc = crc32 (crc, (unsigned char const *) Charset, str_len (Charset)); crc = crc32 (crc, (unsigned char const *) "HAVE_LANGINFO_CODESET", - mutt_strlen ("HAVE_LANGINFO_CODESET")); + str_len ("HAVE_LANGINFO_CODESET")); #endif #ifdef USE_POP crc = - crc32 (crc, (unsigned char const *) "USE_POP", mutt_strlen ("USE_POP")); + crc32 (crc, (unsigned char const *) "USE_POP", str_len ("USE_POP")); #endif #ifdef MIXMASTER crc = crc32 (crc, (unsigned char const *) "MIXMASTER", - mutt_strlen ("MIXMASTER")); + str_len ("MIXMASTER")); #endif #ifdef USE_IMAP crc = - crc32 (crc, (unsigned char const *) "USE_IMAP", mutt_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", mutt_strlen ("USE_NNTP")); + crc32 (crc, (unsigned char const *) "USE_NNTP", str_len ("USE_NNTP")); #endif return crc; } @@ -522,7 +513,7 @@ static const char *mutt_hcache_per_folder (const char *path, } MD5Init (&md5); - MD5Update (&md5, (unsigned char *) folder, mutt_strlen (folder)); + MD5Update (&md5, (unsigned char *) folder, str_len (folder)); MD5Final (md5sum, &md5); ret = snprintf (mutt_hcache_per_folder_path, _POSIX_PATH_MAX, @@ -601,7 +592,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); } @@ -612,16 +603,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 = mem_calloc(1, sizeof (HEADER_CACHE)); int flags = VL_OWRITER | VL_OCREAT; 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); + mem_free(&h->folder); + mem_free(&h); return NULL; } @@ -635,8 +626,8 @@ mutt_hcache_open(const char *path, const char *folder) return h; else { - FREE(&h->folder); - FREE(&h); + mem_free(&h->folder); + mem_free(&h); return NULL; } @@ -651,8 +642,8 @@ mutt_hcache_close(void *db) return; vlclose(h->db); - FREE(&h->folder); - FREE(&h); + mem_free(&h->folder); + mem_free(&h); } void * @@ -668,7 +659,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)); @@ -676,7 +667,7 @@ mutt_hcache_fetch(void *db, const char *filename, if (! crc32_matches(data, h->crc)) { - FREE(&data); + mem_free(&data); return NULL; } @@ -698,7 +689,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)); @@ -706,7 +697,7 @@ mutt_hcache_store(void *db, const char *filename, HEADER * header, ret = vlput(h->db, path, ksize, data, dsize, VL_DOVER); - FREE(&data); + mem_free(&data); return ret; } @@ -723,7 +714,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)); @@ -734,16 +725,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 = mem_calloc (1, sizeof (HEADER_CACHE)); 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); + mem_free (&h->folder); + mem_free (&h); return NULL; } @@ -760,8 +751,8 @@ void *mutt_hcache_open (const char *path, const char *folder) return h; } else { - FREE (&h->folder); - FREE (&h); + mem_free (&h->folder); + mem_free (&h); return NULL; } @@ -776,8 +767,8 @@ void mutt_hcache_close (void *db) } gdbm_close (h->db); - FREE (&h->folder); - FREE (&h); + mem_free (&h->folder); + mem_free (&h); } void *mutt_hcache_fetch (void *db, const char *filename, @@ -793,7 +784,7 @@ void *mutt_hcache_fetch (void *db, const char *filename, } strncpy (path, h->folder, sizeof (path)); - strncat (path, filename, sizeof (path) - mutt_strlen (path)); + strncat (path, filename, sizeof (path) - str_len (path)); key.dptr = path; key.dsize = keylen (path); @@ -801,7 +792,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); + mem_free(&data.dptr); return NULL; } @@ -823,7 +814,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, } strncpy (path, h->folder, sizeof (path)); - strncat (path, filename, sizeof (path) - mutt_strlen (path)); + strncat (path, filename, sizeof (path) - str_len (path)); key.dptr = path; key.dsize = keylen (path); @@ -832,7 +823,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, ret = gdbm_store (h->db, key, data, GDBM_REPLACE); - FREE (&data.dptr); + mem_free (&data.dptr); return ret; } @@ -850,7 +841,7 @@ mutt_hcache_delete (void *db, const char *filename, } strncpy (path, h->folder, sizeof (path)); - strncat (path, filename, sizeof (path) - mutt_strlen (path)); + strncat (path, filename, sizeof (path) - str_len (path)); key.dptr = path; key.dsize = keylen (path); @@ -886,7 +877,7 @@ void *mutt_hcache_open (const char *path, const char *folder) h->crc = generate_crc32 (); if (!path || path[0] == '\0') { - FREE (&h); + mem_free (&h); return NULL; } @@ -896,13 +887,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); + mem_free (&h); return NULL; } if (mx_lock_file (h->lockfile, h->fd, 1, 0, 5)) { close (h->fd); - FREE (&h); + mem_free (&h); return NULL; } @@ -910,7 +901,7 @@ 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); + mem_free (&h); return NULL; } @@ -922,7 +913,7 @@ void *mutt_hcache_open (const char *path, const char *folder) h->env->close (h->env, 0); mx_unlock_file (h->lockfile, h->fd, 0); close (h->fd); - FREE (&h); + mem_free (&h); return NULL; } } @@ -938,7 +929,7 @@ void *mutt_hcache_open (const char *path, const char *folder) h->env->close (h->env, 0); mx_unlock_file (h->lockfile, h->fd, 0); close (h->fd); - FREE (&h); + mem_free (&h); return NULL; } @@ -957,7 +948,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); + mem_free (&h); } void *mutt_hcache_fetch (void *db, const char *filename, @@ -980,7 +971,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); + mem_free(&data.data); return NULL; } @@ -1012,7 +1003,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, ret = h->db->put (h->db, NULL, &key, &data, 0); - FREE (&data.data); + mem_free (&data.data); return ret; }