drop list2_t from sendlib.c as well.
[apps/madmutt.git] / hcache.c
index 714c204..953e70f 100644 (file)
--- a/hcache.c
+++ b/hcache.c
@@ -8,22 +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 */
+
+#include <lib-lib/lib-lib.h>
 
 #ifdef USE_HCACHE
 
 #define MUTTNG_HCACHE_ID        "0x004"
 
-# ifdef HAVE_INTTYPES_H
-#  include <inttypes.h>
-# else
-#  ifdef HAVE_STDINT_H
-#   include <stdint.h>
-#  endif
-# endif
-
 #if defined(HAVE_QDBM)
 #include <depot.h>
 #include <cabin.h>
 #include <db.h>
 #endif
 
-#include <errno.h>
-#include <fcntl.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#include <lib-lib/mem.h>
 #include <lib-hash/hash.h>
-#include <lib-lib/debug.h>
-
 #include <lib-mime/mime.h>
 
+#include "charset.h"
 #include "mutt.h"
 #include <imap/message.h>
 #include "mx.h"
 #include "lib.h"
 
-static struct header_cache {
+struct header_cache {
 #if defined(HAVE_QDBM)
   VILLA *db;
   char *folder;
@@ -67,31 +50,23 @@ static struct header_cache {
   int fd;
   char lockfile[_POSIX_PATH_MAX];
 #endif
-} HEADER_CACHE;
+};
 
 typedef union {
   struct timeval timeval;
   unsigned long uid_validity;
 } validate;
 
-static void *lazy_malloc (size_t siz)
-{
-  if (0 < siz && siz < 4096) {
-    siz = 4096;
-  }
+#define UPPER4K(i)  ((i & ~(4096 - 1)) + 4096)
 
-  return xmalloc(siz);
+static unsigned char *lazy_malloc(ssize_t siz)
+{
+    return p_new(unsigned char, UPPER4K(siz));
 }
 
-static void lazy_realloc(void *ptr, ssize_t siz)
+static void lazy_realloc(unsigned char **p, ssize_t siz)
 {
-  void **p = (void **) ptr;
-
-  if (p != NULL && 0 < siz && siz < 4096) {
-    return;
-  }
-
-  p_realloc(p, siz);
+    p_realloc(p, UPPER4K(siz));
 }
 
 static unsigned char *dump_int (unsigned int i, unsigned char *d, int *off)
@@ -128,25 +103,6 @@ static unsigned char *dump_char (char *c, unsigned char *d, int *off)
   return d;
 }
 
-#if 0
-static unsigned char *dump_char_size (char *c, unsigned char *d, int *off,
-                                      ssize_t size)
-{
-  if (c == NULL) {
-    size = 0;
-    d = dump_int (size, d, off);
-    return d;
-  }
-
-  d = dump_int (size, d, off);
-  lazy_realloc (&d, *off + size);
-  memcpy (d + *off, c, size);
-  *off += size;
-
-  return d;
-}
-#endif
-
 static void restore_char (char **c, const unsigned char *d, int *off)
 {
   unsigned int size;
@@ -234,46 +190,7 @@ static void restore_list (string_list_t ** l, const unsigned char *d, int *off)
   *l = NULL;
 }
 
-#if 0
-static unsigned char *dump_buffer (BUFFER * b, unsigned char *d, int *off)
-{
-  if (!b) {
-    d = dump_int (0, d, off);
-    return d;
-  }
-  else {
-    d = dump_int (1, d, off);
-  }
-
-  d = dump_char_size (b->data, d, off, b->dsize + 1);
-  d = dump_int (b->dptr - b->data, d, off);
-  d = dump_int (b->dsize, d, off);
-  d = dump_int (b->destroy, d, off);
-
-  return d;
-}
-
-static void restore_buffer (BUFFER ** b, const unsigned char *d, int *off)
-{
-  unsigned int used;
-  unsigned int offset;
-
-  restore_int (&used, d, off);
-  if (!used) {
-    return;
-  }
-
-  *b = p_new(BUFFER, 1);
-
-  restore_char (&(*b)->data, d, off);
-  restore_int (&offset, d, off);
-  (*b)->dptr = (*b)->data + offset;
-  restore_int (&(*b)->dsize, d, off);
-  restore_int ((unsigned int *) &(*b)->destroy, d, off);
-}
-#endif
-
-static unsigned char *dump_parameter (PARAMETER * p, unsigned char *d,
+static unsigned char *dump_parameter (parameter_t * p, unsigned char *d,
                                       int *off)
 {
   unsigned int counter = 0;
@@ -294,21 +211,19 @@ static unsigned char *dump_parameter (PARAMETER * p, unsigned char *d,
 }
 
 static void
-restore_parameter (PARAMETER ** p, const unsigned char *d, int *off)
+restore_parameter (parameter_t ** p, const unsigned char *d, int *off)
 {
   unsigned int counter;
 
   restore_int (&counter, d, off);
 
   while (counter) {
-    *p = p_new(PARAMETER, 1);
+    *p = parameter_new();
     restore_char (&(*p)->attribute, d, off);
     restore_char (&(*p)->value, d, off);
     p = &(*p)->next;
     counter--;
   }
-
-  *p = NULL;
 }
 
 static unsigned char *dump_body (BODY * c, unsigned char *d, int *off)
@@ -424,7 +339,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;
 
@@ -571,7 +486,7 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh)
   h->env = envelope_new();
   restore_envelope (h->env, d, &off);
 
-  h->content = mutt_new_body ();
+  h->content = body_new();
   restore_body (h->content, d, &off);
 
   restore_char (&h->maildir_flags, d, &off);
@@ -635,7 +550,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,7 +579,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];
@@ -691,7 +606,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];
@@ -712,7 +627,7 @@ mutt_hcache_delete(void *db, const char *filename,
 
 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;
@@ -759,7 +674,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;
@@ -788,7 +703,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;
@@ -817,7 +732,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;
@@ -837,7 +752,7 @@ mutt_hcache_delete (void *db, const char *filename,
 }
 #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;
@@ -857,7 +772,7 @@ void *mutt_hcache_open (const char *path, const char *folder)
   struct stat sb;
   u_int32_t createflags = DB_CREATE;
   int ret;
-  struct header_cache *h = calloc (1, sizeof (HEADER_CACHE));
+  struct header_cache *h = p_new(struct header_cache, 1);
   int pagesize = atoi (HeaderCachePageSize);
 
 
@@ -939,7 +854,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;
@@ -967,7 +882,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;
@@ -997,7 +912,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;