drop mem_alloc and mem_free, use my own hand crafted optmized macros that
[apps/madmutt.git] / imap / imap.c
index db9901a..8c7cc5e 100644 (file)
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "buffer.h"
@@ -66,7 +68,7 @@ int imap_access (const char *path, int flags)
   if (!(idata = imap_conn_find (&mx.account,
                                 option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW :
                                 0))) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return -1;
   }
 
@@ -74,11 +76,11 @@ int imap_access (const char *path, int flags)
 
   /* we may already be in the folder we're checking */
   if (!ascii_strcmp(idata->mailbox, mx.mbox)) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return 0;
   }
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
 
   if (mutt_bit_isset (idata->capabilities, IMAP4REV1))
@@ -138,7 +140,7 @@ int imap_delete_mailbox (CONTEXT * ctx, IMAP_MBOX mx)
     if (!(idata = imap_conn_find (&mx.account,
                                   option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW
                                   : 0))) {
-      mem_free (&mx.mbox);
+      p_delete(&mx.mbox);
       return -1;
     }
   }
@@ -243,7 +245,7 @@ void imap_expunge_mailbox (IMAP_DATA * idata)
       if (idata->cache[cacheno].uid == HEADER_DATA (h)->uid &&
           idata->cache[cacheno].path) {
         unlink (idata->cache[cacheno].path);
-        mem_free (&idata->cache[cacheno].path);
+        p_delete(&idata->cache[cacheno].path);
       }
 
       imap_free_header_data (&h->data);
@@ -387,7 +389,7 @@ IMAP_DATA *imap_conn_find (const ACCOUNT * account, int flags)
     else
       mutt_account_unsetpass (&idata->conn->account);
 
-    mem_free (&idata->capstr);
+    p_delete(&idata->capstr);
   }
   if (new && idata->state == IMAP_AUTHENTICATED) {
     imap_get_delim (idata);
@@ -462,7 +464,7 @@ int imap_open_connection (IMAP_DATA * idata)
     idata->state = IMAP_AUTHENTICATED;
     if (imap_check_capabilities (idata) != 0)
       goto bail;
-    mem_free (&idata->capstr);
+    p_delete(&idata->capstr);
   }
   else {
     imap_error ("imap_open_connection()", buf);
@@ -475,7 +477,7 @@ err_close_conn:
   mutt_socket_close (idata->conn);
   idata->state = IMAP_DISCONNECTED;
 bail:
-  mem_free (&idata->capstr);
+  p_delete(&idata->capstr);
   return -1;
 }
 
@@ -557,11 +559,11 @@ int imap_open_mailbox (CONTEXT * ctx)
 
   /* Clean up path and replace the one in the ctx */
   imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
-  mem_free (&(idata->mailbox));
+  p_delete(&(idata->mailbox));
   idata->mailbox = str_dup (buf);
   imap_qualify_path (buf, sizeof (buf), &mx, idata->mailbox);
 
-  mem_free (&(ctx->path));
+  p_delete(&(ctx->path));
   ctx->path = str_dup (buf);
 
   idata->ctx = ctx;
@@ -701,14 +703,14 @@ int imap_open_mailbox (CONTEXT * ctx)
   }
 
   debug_print (2, ("msgcount is %d\n", ctx->msgcount));
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
   if (idata->state == IMAP_SELECTED)
     idata->state = IMAP_AUTHENTICATED;
 fail_noidata:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -727,7 +729,7 @@ int imap_open_mailbox_append (CONTEXT * ctx)
    * ctx is brand new and mostly empty */
 
   if (!(idata = imap_conn_find (&(mx.account), 0))) {
-    mem_free(&mx.mbox);
+    p_delete(&mx.mbox);
     return (-1);
   }
   conn = idata->conn;
@@ -737,7 +739,7 @@ int imap_open_mailbox_append (CONTEXT * ctx)
 
   imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));
 
-  mem_free(&mx.mbox);
+  p_delete(&mx.mbox);
 
   /* really we should also check for W_OK */
   if (!imap_access (ctx->path, F_OK))
@@ -761,8 +763,8 @@ void imap_logout (IMAP_DATA * idata)
   idata->status = IMAP_BYE;
   imap_cmd_start (idata, "LOGOUT");
   while (imap_cmd_step (idata) == IMAP_CMD_CONTINUE);
-  mem_free (&idata->cmd.buf);
-  mem_free (&idata);
+  p_delete(&idata->cmd.buf);
+  p_delete(&idata);
 }
 
 /*
@@ -870,7 +872,7 @@ int imap_make_msg_set (IMAP_DATA * idata, BUFFER * buf, int flag, int changed)
     }
   }
 
-  mem_free (&hdrs);
+  p_delete(&hdrs);
 
   return count;
 }
@@ -1053,10 +1055,10 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint)
   rc = 0;
 out:
   if (cmd.data)
-    mem_free (&cmd.data);
+    p_delete(&cmd.data);
   if (appendctx) {
     mx_fastclose_mailbox (appendctx);
-    mem_free (&appendctx);
+    p_delete(&appendctx);
   }
   return rc;
 }
@@ -1082,7 +1084,7 @@ void imap_close_mailbox (CONTEXT * ctx)
     }
 
     idata->reopen &= IMAP_REOPEN_ALLOW;
-    mem_free (&(idata->mailbox));
+    p_delete(&(idata->mailbox));
     mutt_free_list (&idata->flags);
     idata->ctx = NULL;
   }
@@ -1094,7 +1096,7 @@ void imap_close_mailbox (CONTEXT * ctx)
   for (i = 0; i < IMAP_CACHE_LEN; i++) {
     if (idata->cache[i].path) {
       unlink (idata->cache[i].path);
-      mem_free (&idata->cache[i].path);
+      p_delete(&idata->cache[i].path);
     }
   }
 }
@@ -1166,13 +1168,13 @@ int imap_mailbox_check (char *path, int new)
     connflags = M_IMAP_CONN_NONEW;
 
   if (!(idata = imap_conn_find (&(mx.account), connflags))) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return -1;
   }
   conn = idata->conn;
 
   imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
 
   imap_munge_mbox_name (mbox, sizeof (mbox), buf);
   strfcpy (mbox_unquoted, buf, sizeof (mbox_unquoted));
@@ -1348,15 +1350,15 @@ int imap_search (CONTEXT* ctx, const pattern_t* pat) {
   memset (&buf, 0, sizeof (buf));
   mutt_buffer_addstr (&buf, "UID SEARCH ");
   if (imap_compile_search (pat, &buf) < 0) {
-    mem_free (&buf.data);
+    p_delete(&buf.data);
     return -1;
   }
   if (imap_exec (idata, buf.data, 0) < 0) {
-    mem_free (&buf.data);
+    p_delete(&buf.data);
     return -1;
   }
 
-  mem_free (&buf.data);
+  p_delete(&buf.data);
   return 0;
 }
 
@@ -1464,7 +1466,7 @@ int imap_subscribe (char *path, int subscribe)
               subscribe ? "" : "un", path);
     if (mutt_parse_rc_line (mbox, &token, &err))
       debug_print (1, ("Error adding subscribed mailbox: %s\n", errstr));
-    mem_free (&token.data);
+    p_delete(&token.data);
   }
 
   if (subscribe)
@@ -1478,11 +1480,11 @@ int imap_subscribe (char *path, int subscribe)
   if (imap_exec (idata, buf, 0) < 0)
     goto fail;
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -1569,7 +1571,7 @@ int imap_complete (char *dest, size_t dlen, char *path) {
   /* don't open a new socket just for completion. Instead complete over
    * known mailboxes/hooks/etc */
   if (!(idata = imap_conn_find (&(mx.account), M_IMAP_CONN_NONEW))) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     strfcpy (dest, path, dlen);
     return imap_complete_hosts (dest, dlen);
   }
@@ -1625,7 +1627,7 @@ int imap_complete (char *dest, size_t dlen, char *path) {
     imap_qualify_path (dest, dlen, &mx, completion);
     mutt_pretty_mailbox (dest);
 
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return 0;
   }