use m_strdup and m_strlen that are inlined for efficiency
[apps/madmutt.git] / pgpkey.c
index 42dc0ff..eeb0048 100644 (file)
--- a/pgpkey.c
+++ b/pgpkey.c
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+#include <lib-lib/macros.h>
+
 #include "mutt.h"
+#include "enter.h"
+#include "ascii.h"
+#include "recvattach.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "mime.h"
@@ -20,9 +27,6 @@
 #include "pager.h"
 #include "sort.h"
 
-#include "lib/mem.h"
-#include "lib/intl.h"
-#include "lib/str.h"
 #include "lib/debug.h"
 
 #include <string.h>
@@ -278,10 +282,10 @@ static int _pgp_compare_address (const void *a, const void *b)
   pgp_uid_t **s = (pgp_uid_t **) a;
   pgp_uid_t **t = (pgp_uid_t **) b;
 
-  if ((r = safe_strcasecmp ((*s)->addr, (*t)->addr)))
+  if ((r = str_casecmp ((*s)->addr, (*t)->addr)))
     return r > 0;
   else
-    return (safe_strcasecmp (_pgp_keyid ((*s)->parent),
+    return (str_casecmp (_pgp_keyid ((*s)->parent),
                              _pgp_keyid ((*t)->parent)) > 0);
 }
 
@@ -300,11 +304,11 @@ static int _pgp_compare_keyid (const void *a, const void *b)
   pgp_uid_t **s = (pgp_uid_t **) a;
   pgp_uid_t **t = (pgp_uid_t **) b;
 
-  if ((r = safe_strcasecmp (_pgp_keyid ((*s)->parent),
+  if ((r = str_casecmp (_pgp_keyid ((*s)->parent),
                             _pgp_keyid ((*t)->parent))))
     return r > 0;
   else
-    return (safe_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
+    return (str_casecmp ((*s)->addr, (*t)->addr)) > 0;
 }
 
 static int pgp_compare_keyid (const void *a, const void *b)
@@ -321,7 +325,7 @@ static int _pgp_compare_date (const void *a, const void *b)
 
   if ((r = ((*s)->parent->gen_time - (*t)->parent->gen_time)))
     return r > 0;
-  return (safe_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
+  return (str_casecmp ((*s)->addr, (*t)->addr)) > 0;
 }
 
 static int pgp_compare_date (const void *a, const void *b)
@@ -346,9 +350,9 @@ static int _pgp_compare_trust (const void *a, const void *b)
     return r < 0;
   if ((r = ((*s)->parent->gen_time - (*t)->parent->gen_time)))
     return r < 0;
-  if ((r = safe_strcasecmp ((*s)->addr, (*t)->addr)))
+  if ((r = str_casecmp ((*s)->addr, (*t)->addr)))
     return r > 0;
-  return (safe_strcasecmp (_pgp_keyid ((*s)->parent),
+  return (str_casecmp (_pgp_keyid ((*s)->parent),
                            _pgp_keyid ((*t)->parent))) > 0;
 }
 
@@ -407,11 +411,11 @@ static int pgp_id_matches_addr (ADDRESS * addr, ADDRESS * u_addr,
     rv |= PGP_KV_STRONGID;
 
   if (addr->mailbox && u_addr->mailbox
-      && safe_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
+      && str_casecmp (addr->mailbox, u_addr->mailbox) == 0)
     rv |= PGP_KV_ADDR;
 
   if (addr->personal && u_addr->personal
-      && safe_strcasecmp (addr->personal, u_addr->personal) == 0)
+      && str_casecmp (addr->personal, u_addr->personal) == 0)
     rv |= PGP_KV_STRING;
 
   return rv;
@@ -450,7 +454,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s)
 
       if (i == keymax) {
         keymax += 5;
-        safe_realloc (&KeyTable, sizeof (pgp_uid_t *) * keymax);
+        p_realloc(&KeyTable, keymax);
       }
 
       KeyTable[i++] = a;
@@ -578,7 +582,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s)
       if (option (OPTPGPCHECKTRUST) &&
           (!pgp_id_is_valid (KeyTable[menu->current])
            || !pgp_id_is_strong (KeyTable[menu->current]))) {
-        char *s = "";
+        const char *s = "";
         char buff[LONG_STRING];
 
         if (KeyTable[menu->current]->flags & KEYFLAG_CANTUSE)
@@ -622,7 +626,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s)
   }
 
   mutt_menuDestroy (&menu);
-  FREE (&KeyTable);
+  p_delete(&KeyTable);
 
   set_option (OPTNEEDREDRAW);
 
@@ -642,7 +646,7 @@ pgp_key_t pgp_ask_for_key (char *tag, char *whatfor,
   if (whatfor) {
 
     for (l = id_defaults; l; l = l->next)
-      if (!safe_strcasecmp (whatfor, l->what)) {
+      if (!str_casecmp (whatfor, l->what)) {
         strfcpy (resp, NONULL (l->dflt), sizeof (resp));
         break;
       }
@@ -658,11 +662,11 @@ pgp_key_t pgp_ask_for_key (char *tag, char *whatfor,
       if (l)
         str_replace (&l->dflt, resp);
       else {
-        l = safe_malloc (sizeof (struct pgp_cache));
+        l = p_new(struct pgp_cache, 1);
         l->next = id_defaults;
         id_defaults = l;
-        l->what = safe_strdup (whatfor);
-        l->dflt = safe_strdup (resp);
+        l->what = m_strdup(whatfor);
+        l->dflt = m_strdup(resp);
       }
     }
 
@@ -738,13 +742,13 @@ BODY *pgp_make_key_attachment (char *tempf)
   fclose (devnull);
 
   att = mutt_new_body ();
-  att->filename = safe_strdup (tempf);
+  att->filename = m_strdup(tempf);
   att->unlink = 1;
   att->use_disp = 0;
   att->type = TYPEAPPLICATION;
-  att->subtype = safe_strdup ("pgp-keys");
+  att->subtype = m_strdup("pgp-keys");
   snprintf (buff, sizeof (buff), _("PGP Key %s."), tmp);
-  att->description = safe_strdup (buff);
+  att->description = m_strdup(buff);
   mutt_update_encoding (att);
 
   stat (tempf, &sb);
@@ -758,16 +762,16 @@ static LIST *pgp_add_string_to_hints (LIST * hints, const char *str)
   char *scratch;
   char *t;
 
-  if ((scratch = safe_strdup (str)) == NULL)
+  if ((scratch = m_strdup(str)) == NULL)
     return hints;
 
   for (t = strtok (scratch, " ,.:\"()<>\n"); t;
        t = strtok (NULL, " ,.:\"()<>\n")) {
-    if (safe_strlen (t) > 3)
+    if (m_strlen(t) > 3)
       hints = mutt_add_list (hints, t);
   }
 
-  FREE (&scratch);
+  p_delete(&scratch);
   return hints;
 }
 
@@ -928,11 +932,11 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring)
 
     for (a = k->address; a; a = a->next) {
       debug_print (5, ("matching \"%s\" against key %s, \"%s\":\n", p, pgp_keyid (k), a->addr));
-      if (!*p || safe_strcasecmp (p, pgp_keyid (k)) == 0
-          || (!safe_strncasecmp (p, "0x", 2)
-              && !safe_strcasecmp (p + 2, pgp_keyid (k)))
-          || (option (OPTPGPLONGIDS) && !safe_strncasecmp (p, "0x", 2)
-              && !safe_strcasecmp (p + 2, k->keyid + 8))
+      if (!*p || str_casecmp (p, pgp_keyid (k)) == 0
+          || (!str_ncasecmp (p, "0x", 2)
+              && !str_casecmp (p + 2, pgp_keyid (k)))
+          || (option (OPTPGPLONGIDS) && !str_ncasecmp (p, "0x", 2)
+              && !str_casecmp (p + 2, k->keyid + 8))
           || str_isstr (a->addr, p)) {
         debug_print (5, ("match.\n"));
         match = 1;