X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=hcache.c;h=496fd09074f2a5574d5a006adba097352421e486;hp=e513c76b478f3b540e407e3dbbb408d201589dae;hb=9eb3b25249e78d778b6d0583b06a7c5615709e63;hpb=c6b9d35ed9361e4defab9762a7480d5126405ae9 diff --git a/hcache.c b/hcache.c index e513c76..496fd09 100644 --- a/hcache.c +++ b/hcache.c @@ -16,74 +16,65 @@ #define MUTTNG_HCACHE_ID "0x004" -# if HAVE_INTTYPES_H +# ifdef HAVE_INTTYPES_H # include # else -# if HAVE_STDINT_H +# ifdef HAVE_STDINT_H # include # endif # endif -#if HAVE_QDBM +#if defined(HAVE_QDBM) #include #include #include -#elif HAVE_GDBM +#elif defined(HAVE_GDBM) #include -#elif HAVE_DB4 +#elif defined(HAVE_DB4) #include #endif #include #include -#if HAVE_SYS_TIME_H +#ifdef HAVE_SYS_TIME_H #include #endif #include #include +#include + +#include #include "mutt.h" -#ifdef USE_IMAP -#include "message.h" -#endif -#include "mime.h" +#include #include "mx.h" #include "lib.h" -#include "lib/debug.h" - -#if HAVE_QDBM -static struct - header_cache { +static struct header_cache { +#if defined(HAVE_QDBM) VILLA *db; char *folder; unsigned int crc; -} HEADER_CACHE; -#elif HAVE_GDBM -static struct - header_cache { +#elif defined(HAVE_GDBM) GDBM_FILE db; char *folder; unsigned int crc; -} HEADER_CACHE; -#elif HAVE_DB4 -static struct - header_cache { +#elif defined(HAVE_DB4) DB_ENV *env; DB *db; unsigned int crc; int fd; char lockfile[_POSIX_PATH_MAX]; -} HEADER_CACHE; #endif +} HEADER_CACHE; typedef union { struct timeval timeval; unsigned long uid_validity; } validate; -static void *lazy_malloc (size_t siz) +static void *lazy_malloc (ssize_t siz) { if (0 < siz && siz < 4096) { siz = 4096; @@ -92,15 +83,15 @@ static void *lazy_malloc (size_t siz) return xmalloc(siz); } -static void lazy_realloc (void *ptr, size_t siz) +static void lazy_realloc(void *ptr, ssize_t siz) { - void **p = (void **) ptr; + char **p = ptr; if (p != NULL && 0 < siz && siz < 4096) { return; } - p_realloc(ptr, siz); + p_realloc(&p, siz); } static unsigned char *dump_int (unsigned int i, unsigned char *d, int *off) @@ -171,7 +162,7 @@ static void restore_char (char **c, const unsigned char *d, int *off) *off += size; } -static unsigned char *dump_address (ADDRESS * a, unsigned char *d, int *off) +static unsigned char *dump_address (address_t * a, unsigned char *d, int *off) { unsigned int counter = 0; unsigned int start_off = *off; @@ -191,14 +182,14 @@ static unsigned char *dump_address (ADDRESS * a, unsigned char *d, int *off) return d; } -static void restore_address (ADDRESS ** a, const unsigned char *d, int *off) +static void restore_address (address_t ** a, const unsigned char *d, int *off) { unsigned int counter; restore_int (&counter, d, off); while (counter) { - *a = p_new(ADDRESS, 1); + *a = p_new(address_t, 1); restore_char (&(*a)->personal, d, off); restore_char (&(*a)->mailbox, d, off); restore_int ((unsigned int *) &(*a)->group, d, off); @@ -209,7 +200,7 @@ static void restore_address (ADDRESS ** a, const unsigned char *d, int *off) *a = NULL; } -static unsigned char *dump_list (LIST * l, unsigned char *d, int *off) +static unsigned char *dump_list (string_list_t * l, unsigned char *d, int *off) { unsigned int counter = 0; unsigned int start_off = *off; @@ -227,14 +218,14 @@ static unsigned char *dump_list (LIST * l, unsigned char *d, int *off) return d; } -static void restore_list (LIST ** l, const unsigned char *d, int *off) +static void restore_list (string_list_t ** l, const unsigned char *d, int *off) { unsigned int counter; restore_int (&counter, d, off); while (counter) { - *l = p_new(LIST, 1); + *l = p_new(string_list_t, 1); restore_char (&(*l)->data, d, off); l = &(*l)->next; counter--; @@ -433,7 +424,7 @@ static void restore_envelope (ENVELOPE * e, const unsigned char *d, int *off) } static -unsigned int crc32 (unsigned int crc, unsigned char const *p, size_t len) +unsigned int crc32 (unsigned int crc, unsigned char const *p, ssize_t len) { int i; @@ -454,32 +445,23 @@ static int generate_crc32 () m_strlen (MUTTNG_HCACHE_ID "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613")); -#if HAVE_LANGINFO_CODESET - crc = crc32 (crc, (unsigned char const *) Charset, m_strlen(Charset)); - crc = - crc32 (crc, (unsigned char const *) "HAVE_LANGINFO_CODESET", - m_strlen("HAVE_LANGINFO_CODESET")); +#ifdef HAVE_LANGINFO_CODESET + crc = crc32(crc, (unsigned char const *) Charset, m_strlen(Charset)); + crc = crc32(crc, (unsigned char const *) "HAVE_LANGINFO_CODESET", + m_strlen("HAVE_LANGINFO_CODESET")); #endif -#ifdef USE_POP - crc = - crc32 (crc, (unsigned char const *) "USE_POP", m_strlen("USE_POP")); -#endif + crc = crc32(crc, (unsigned char const *) "USE_POP", m_strlen("USE_POP")); #ifdef MIXMASTER - crc = - crc32 (crc, (unsigned char const *) "MIXMASTER", - m_strlen("MIXMASTER")); + crc = crc32(crc, (unsigned char const *) "MIXMASTER", + m_strlen("MIXMASTER")); #endif -#ifdef USE_IMAP - crc = - crc32 (crc, (unsigned char const *) "USE_IMAP", m_strlen("USE_IMAP")); -#endif + crc = crc32(crc, (unsigned char const *) "USE_IMAP", m_strlen("USE_IMAP")); #ifdef USE_NNTP - crc = - crc32 (crc, (unsigned char const *) "USE_NNTP", m_strlen("USE_NNTP")); + crc = crc32(crc, (unsigned char const *) "USE_NNTP", m_strlen("USE_NNTP")); #endif return crc; } @@ -575,7 +557,7 @@ static void *mutt_hcache_dump (void *_db, HEADER * h, int *off, HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) { int off = 0; - HEADER *h = mutt_new_header (); + HEADER *h = header_new(); /* skip validate */ off += sizeof (validate); @@ -586,7 +568,7 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) memcpy (h, d + off, sizeof (HEADER)); off += sizeof (HEADER); - h->env = mutt_new_envelope (); + h->env = envelope_new(); restore_envelope (h->env, d, &off); h->content = mutt_new_body (); @@ -598,17 +580,17 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) if (oh) { h->old = (*oh)->old; h->path = m_strdup((*oh)->path); - mutt_free_header (oh); + header_delete(oh); } return h; } -#if HAVE_QDBM +#if defined(HAVE_QDBM) void * mutt_hcache_open(const char *path, const char *folder) { - struct header_cache *h = p_new(HEADER_CACHE, 1); + struct header_cache *h = p_new(struct header_cache, 1); int flags = VL_OWRITER | VL_OCREAT; h->db = NULL; h->folder = m_strdup(folder); @@ -653,7 +635,7 @@ mutt_hcache_close(void *db) void * mutt_hcache_fetch(void *db, const char *filename, - size_t(*keylen) (const char *fn)) + ssize_t(*keylen) (const char *fn)) { struct header_cache *h = db; char path[_POSIX_PATH_MAX]; @@ -664,13 +646,13 @@ mutt_hcache_fetch(void *db, const char *filename, return NULL; m_strcpy(path, sizeof(path), h->folder); - str_cat(path, sizeof (path), filename); + m_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)) + if (!crc32_matches(data, h->crc)) { p_delete(&data); return NULL; @@ -682,7 +664,7 @@ mutt_hcache_fetch(void *db, const char *filename, int mutt_hcache_store(void *db, const char *filename, HEADER * header, unsigned long uid_validity, - size_t(*keylen) (const char *fn)) + ssize_t(*keylen) (const char *fn)) { struct header_cache *h = db; char path[_POSIX_PATH_MAX]; @@ -694,7 +676,7 @@ mutt_hcache_store(void *db, const char *filename, HEADER * header, return -1; m_strcpy(path, sizeof(path), h->folder); - str_cat(path, sizeof (path), filename); + m_strcat(path, sizeof(path), filename); ksize = strlen(h->folder) + keylen(path + strlen(h->folder)); @@ -709,7 +691,7 @@ mutt_hcache_store(void *db, const char *filename, HEADER * header, int mutt_hcache_delete(void *db, const char *filename, - size_t(*keylen) (const char *fn)) + ssize_t(*keylen) (const char *fn)) { struct header_cache *h = db; char path[_POSIX_PATH_MAX]; @@ -719,18 +701,18 @@ mutt_hcache_delete(void *db, const char *filename, return -1; m_strcpy(path, sizeof(path), h->folder); - str_cat(path, sizeof (path), filename); + m_strcat(path, sizeof(path), filename); ksize = strlen(h->folder) + keylen(path + strlen(h->folder)); return vlout(h->db, path, ksize); } -#elif HAVE_GDBM +#elif defined(HAVE_GDBM) void *mutt_hcache_open (const char *path, const char *folder) { - struct header_cache *h = p_new(HEADER_CACHE, 1); + struct header_cache *h = p_new(struct header_cache, 1); int pagesize = atoi (HeaderCachePageSize) ? atoi (HeaderCachePageSize) : 16384; h->db = NULL; @@ -777,7 +759,7 @@ void mutt_hcache_close (void *db) } void *mutt_hcache_fetch (void *db, const char *filename, - size_t (*keylen) (const char *fn)) + ssize_t (*keylen) (const char *fn)) { struct header_cache *h = db; datum key; @@ -806,7 +788,7 @@ void *mutt_hcache_fetch (void *db, const char *filename, int mutt_hcache_store (void *db, const char *filename, HEADER * header, - unsigned long uid_validity, size_t (*keylen) (const char *fn)) + unsigned long uid_validity, ssize_t (*keylen) (const char *fn)) { struct header_cache *h = db; datum key; @@ -835,7 +817,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, int mutt_hcache_delete (void *db, const char *filename, - size_t (*keylen) (const char *fn)) + ssize_t (*keylen) (const char *fn)) { datum key; struct header_cache *h = db; @@ -853,9 +835,9 @@ mutt_hcache_delete (void *db, const char *filename, return gdbm_delete (h->db, key); } -#elif HAVE_DB4 +#elif defined(HAVE_DB4) -static void mutt_hcache_dbt_init (DBT * dbt, void *data, size_t len) +static void mutt_hcache_dbt_init (DBT * dbt, void *data, ssize_t len) { dbt->data = data; dbt->size = dbt->ulen = len; @@ -957,7 +939,7 @@ void mutt_hcache_close (void *db) } void *mutt_hcache_fetch (void *db, const char *filename, - size_t (*keylen) (const char *fn)) + ssize_t (*keylen) (const char *fn)) { DBT key; DBT data; @@ -985,7 +967,7 @@ void *mutt_hcache_fetch (void *db, const char *filename, int mutt_hcache_store (void *db, const char *filename, HEADER * header, - unsigned long uid_validity, size_t (*keylen) (const char *fn)) + unsigned long uid_validity, ssize_t (*keylen) (const char *fn)) { DBT key; DBT data; @@ -1015,7 +997,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header, int mutt_hcache_delete (void *db, const char *filename, - size_t (*keylen) (const char *fn)) + ssize_t (*keylen) (const char *fn)) { DBT key; struct header_cache *h = db;