simplify count_body_parts drastically.
[apps/madmutt.git] / mutt_socket.c
index 9029b3e..664f61f 100644 (file)
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+#include <lib-lib/macros.h>
+
 #include "mutt.h"
 #include "globals.h"
 #include "mutt_socket.h"
@@ -23,9 +27,6 @@
 
 #include "mutt_idna.h"
 
-#include "lib/mem.h"
-#include "lib/intl.h"
-#include "lib/str.h"
 #include "lib/debug.h"
 
 #include <unistd.h>
@@ -103,7 +104,7 @@ int mutt_socket_write_d (CONNECTION * conn, const char *buf, int dbg)
     return -1;
   }
 
-  len = str_len (buf);
+  len = m_strlen(buf);
   if ((rc = conn->conn_write (conn, buf, len)) < 0) {
     debug_print (1, ("error writing, closing socket\n"));
     mutt_socket_close (conn);
@@ -144,11 +145,11 @@ int mutt_socket_readchar (CONNECTION * conn, char *c)
   return 1;
 }
 
-int mutt_socket_readln_d (char *buf, size_t buflen, CONNECTION * conn,
+int mutt_socket_readln_d (char *buf, ssize_t buflen, CONNECTION * conn,
                           int dbg)
 {
   char ch;
-  int i;
+  ssize_t i;
 
   for (i = 0; i < buflen - 1; i++) {
     if (mutt_socket_readchar (conn, &ch) != 1) {
@@ -169,7 +170,7 @@ int mutt_socket_readln_d (char *buf, size_t buflen, CONNECTION * conn,
 
   debug_print (dbg, ("< %s\n", buf));
 
-  /* number of bytes read, not str_len */
+  /* number of bytes read, not m_strlen*/
   return i + 1;
 }
 
@@ -189,7 +190,7 @@ void mutt_socket_free (CONNECTION * conn)
   /* head is special case, doesn't need prev updated */
   if (iter == conn) {
     Connections = iter->next;
-    mem_free (&iter);
+    p_delete(&iter);
     return;
   }
 
@@ -197,7 +198,7 @@ void mutt_socket_free (CONNECTION * conn)
     if (iter->next == conn) {
       tmp = iter->next;
       iter->next = tmp->next;
-      mem_free (&tmp);
+      p_delete(&tmp);
       return;
     }
     iter = iter->next;
@@ -266,7 +267,7 @@ static int socket_preconnect (void)
   int rc;
   int save_errno;
 
-  if (str_len (Preconnect)) {
+  if (m_strlen(Preconnect)) {
     debug_print (2, ("Executing preconnect: %s\n", Preconnect));
     rc = mutt_system (Preconnect);
     debug_print (2, ("Preconnect result: %d\n", rc));
@@ -324,7 +325,7 @@ static CONNECTION *socket_new_conn (void)
 {
   CONNECTION *conn;
 
-  conn = (CONNECTION *) mem_calloc (1, sizeof (CONNECTION));
+  conn = p_new(CONNECTION, 1);
   conn->fd = -1;
 
   return conn;
@@ -378,7 +379,7 @@ int raw_socket_open (CONNECTION * conn)
   struct addrinfo *cur;
 
   /* we accept v4 or v6 STREAM sockets */
-  memset (&hints, 0, sizeof (hints));
+  p_clear(&hints, 1);
 
   if (option (OPTUSEIPV6))
     hints.ai_family = AF_UNSPEC;
@@ -404,7 +405,7 @@ int raw_socket_open (CONNECTION * conn)
   rc = getaddrinfo (host_idna, port, &hints, &res);
 
 # ifdef HAVE_LIBIDN
-  mem_free (&host_idna);
+  p_delete(&host_idna);
 # endif
 
   if (rc) {
@@ -438,7 +439,7 @@ int raw_socket_open (CONNECTION * conn)
   struct hostent *he;
   int i;
 
-  memset (&sin, 0, sizeof (sin));
+  p_clear(&sin, 1);
   sin.sin_port = htons (conn->account.port);
   sin.sin_family = AF_INET;
 
@@ -455,7 +456,7 @@ int raw_socket_open (CONNECTION * conn)
 
   if ((he = gethostbyname (host_idna)) == NULL) {
 # ifdef HAVE_LIBIDN
-    mem_free (&host_idna);
+    p_delete(&host_idna);
 # endif
     mutt_error (_("Could not find the host \"%s\""), conn->account.host);
 
@@ -463,7 +464,7 @@ int raw_socket_open (CONNECTION * conn)
   }
 
 # ifdef HAVE_LIBIDN
-  mem_free (&host_idna);
+  p_delete(&host_idna);
 # endif
 
   mutt_message (_("Connecting to %s..."), conn->account.host);