use m_strdup and m_strlen that are inlined for efficiency
[apps/madmutt.git] / crypt-gpgme.c
index 5879e59..af921cd 100644 (file)
@@ -19,6 +19,7 @@
 #ifdef CRYPT_BACKEND_GPGME
 
 #include <lib-lib/mem.h>
+#include <lib-lib/str.h>
 #include <lib-lib/macros.h>
 
 #include "mutt.h"
@@ -34,7 +35,6 @@
 #include "recvattach.h"
 #include "sort.h"
 
-#include "lib/str.h"
 #include "lib/debug.h"
 
 #include <sys/wait.h>
@@ -152,7 +152,7 @@ static const char *crypt_keyid (crypt_key_t * k)
 
   if (k->kobj && k->kobj->subkeys) {
     s = k->kobj->subkeys->keyid;
-    if ((!option (OPTPGPLONGIDS)) && (str_len (s) == 16))
+    if ((!option (OPTPGPLONGIDS)) && (m_strlen(s) == 16))
       /* Return only the short keyID.  */
       s += 8;
   }
@@ -508,7 +508,7 @@ static char *data_object_to_tempfile (gpgme_data_t data, FILE ** ret_fp)
   }
   if (ret_fp)
     *ret_fp = fp;
-  return str_dup (tempfile);
+  return m_strdup(tempfile);
 }
 
 
@@ -760,7 +760,7 @@ static BODY *sign_message (BODY * a, int use_smime)
 
   t = mutt_new_body ();
   t->type = TYPEMULTIPART;
-  t->subtype = str_dup ("signed");
+  t->subtype = m_strdup("signed");
   t->encoding = ENC7BIT;
   t->use_disp = 0;
   t->disposition = DISPINLINE;
@@ -784,15 +784,15 @@ static BODY *sign_message (BODY * a, int use_smime)
   t = t->parts->next;
   t->type = TYPEAPPLICATION;
   if (use_smime) {
-    t->subtype = str_dup ("pkcs7-signature");
+    t->subtype = m_strdup("pkcs7-signature");
     mutt_set_parameter ("name", "smime.p7s", &t->parameter);
     t->encoding = ENCBASE64;
     t->use_disp = 1;
     t->disposition = DISPATTACH;
-    t->d_filename = str_dup ("smime.p7s");
+    t->d_filename = m_strdup("smime.p7s");
   }
   else {
-    t->subtype = str_dup ("pgp-signature");
+    t->subtype = m_strdup("pgp-signature");
     t->use_disp = 0;
     t->disposition = DISPINLINE;
     t->encoding = ENC7BIT;
@@ -847,7 +847,7 @@ BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign)
 
   t = mutt_new_body ();
   t->type = TYPEMULTIPART;
-  t->subtype = str_dup ("encrypted");
+  t->subtype = m_strdup("encrypted");
   t->encoding = ENC7BIT;
   t->use_disp = 0;
   t->disposition = DISPINLINE;
@@ -857,18 +857,18 @@ BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign)
 
   t->parts = mutt_new_body ();
   t->parts->type = TYPEAPPLICATION;
-  t->parts->subtype = str_dup ("pgp-encrypted");
+  t->parts->subtype = m_strdup("pgp-encrypted");
   t->parts->encoding = ENC7BIT;
 
   t->parts->next = mutt_new_body ();
   t->parts->next->type = TYPEAPPLICATION;
-  t->parts->next->subtype = str_dup ("octet-stream");
+  t->parts->next->subtype = m_strdup("octet-stream");
   t->parts->next->encoding = ENC7BIT;
   t->parts->next->filename = outfile;
   t->parts->next->use_disp = 1;
   t->parts->next->disposition = DISPINLINE;
   t->parts->next->unlink = 1;   /* delete after sending the message */
-  t->parts->next->d_filename = str_dup ("msg.asc"); /* non pgp/mime
+  t->parts->next->d_filename = m_strdup("msg.asc"); /* non pgp/mime
                                                            can save */
 
   return t;
@@ -905,13 +905,13 @@ BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist)
 
   t = mutt_new_body ();
   t->type = TYPEAPPLICATION;
-  t->subtype = str_dup ("pkcs7-mime");
+  t->subtype = m_strdup("pkcs7-mime");
   mutt_set_parameter ("name", "smime.p7m", &t->parameter);
   mutt_set_parameter ("smime-type", "enveloped-data", &t->parameter);
   t->encoding = ENCBASE64;      /* The output of OpenSSL SHOULD be binary */
   t->use_disp = 1;
   t->disposition = DISPATTACH;
-  t->d_filename = str_dup ("smime.p7m");
+  t->d_filename = m_strdup("smime.p7m");
   t->filename = outfile;
   t->unlink = 1;                /*delete after sending the message */
   t->parts = 0;
@@ -1033,10 +1033,10 @@ static void show_fingerprint (gpgme_key_t key, STATE * state)
     return;
   is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
 
-  buf = xmalloc(str_len (prefix) + str_len (s) * 4 + 2);
+  buf = xmalloc(m_strlen(prefix) + m_strlen(s) * 4 + 2);
   strcpy (buf, prefix);         /* __STRCPY_CHECKED__ */
-  p = buf + str_len (buf);
-  if (is_pgp && str_len (s) == 40) {     /* PGP v4 style formatted. */
+  p = buf + m_strlen(buf);
+  if (is_pgp && m_strlen(s) == 40) {     /* PGP v4 style formatted. */
     for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) {
       *p++ = s[0];
       *p++ = s[1];
@@ -1301,7 +1301,7 @@ static int verify_one (BODY * sigbdy, STATE * s,
             if (notation->value) {
               state_attach_puts (notation->value, s);
               if (!(*notation->value
-                    && (notation->value[str_len (notation->value) - 1] ==
+                    && (notation->value[m_strlen(notation->value) - 1] ==
                         '\n')))
                 state_attach_puts ("\n", s);
             }
@@ -1799,7 +1799,7 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s)
       break;
 
     offset = ftello (s->fpin);
-    bytes -= (offset - last_pos);       /* don't rely on str_len(buf) */
+    bytes -= (offset - last_pos);       /* don't rely on m_strlen(buf) */
     last_pos = offset;
 
     if (!str_ncmp ("-----BEGIN PGP ", buf, 15)) {
@@ -1829,13 +1829,13 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s)
 
       /* Copy PGP material to an data container */
       armored_data = create_gpgme_data ();
-      gpgme_data_write (armored_data, buf, str_len (buf));
+      gpgme_data_write (armored_data, buf, m_strlen(buf));
       while (bytes > 0 && fgets (buf, sizeof (buf) - 1, s->fpin) != NULL) {
         offset = ftello (s->fpin);
-        bytes -= (offset - last_pos);   /* don't rely on str_len(buf) */
+        bytes -= (offset - last_pos);   /* don't rely on m_strlen(buf) */
         last_pos = offset;
 
-        gpgme_data_write (armored_data, buf, str_len (buf));
+        gpgme_data_write (armored_data, buf, m_strlen(buf));
 
         if ((needpass && !str_cmp ("-----END PGP MESSAGE-----\n", buf))
             || (!needpass
@@ -2485,7 +2485,7 @@ static int print_dn_part (FILE * fp, struct dn_array_s *dn, const char *key)
     if (!str_cmp (dn->key, key)) {
       if (any)
         fputs (" + ", fp);
-      print_utf8 (fp, dn->value, str_len (dn->value));
+      print_utf8 (fp, dn->value, m_strlen(dn->value));
       any = 1;
     }
   }
@@ -2760,7 +2760,7 @@ static void print_key_info (gpgme_key_t key, FILE * fp)
       putc (' ', fp);
     }
     if (is_pgp)
-      print_utf8 (fp, s, str_len (s));
+      print_utf8 (fp, s, m_strlen(s));
     else
       parse_and_print_user_id (fp, s);
     putc ('\n', fp);
@@ -2822,7 +2822,7 @@ static void print_key_info (gpgme_key_t key, FILE * fp)
   if (key->subkeys) {
     s = key->subkeys->fpr;
     fputs (_("Fingerprint: "), fp);
-    if (is_pgp && str_len (s) == 40) {
+    if (is_pgp && m_strlen(s) == 40) {
       for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) {
         putc (*s, fp);
         putc (s[1], fp);
@@ -2868,7 +2868,7 @@ static void print_key_info (gpgme_key_t key, FILE * fp)
       s = subkey->keyid;
 
       putc ('\n', fp);
-      if (str_len (s) == 16)
+      if (m_strlen(s) == 16)
         s += 8;                 /* display only the short keyID */
       fprintf (fp, _("Subkey ....: 0x%s"), s);
       if (subkey->revoked) {
@@ -3110,7 +3110,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app,
     patarr = p_new(char *, n + 1);
     for (l = hints, n = 0; l; l = l->next) {
       if (l->data && *l->data)
-        patarr[n++] = str_dup (l->data);
+        patarr[n++] = m_strdup(l->data);
     }
     patarr[n] = NULL;
     err = gpgme_op_keylist_ext_start (ctx, (const char **) patarr, secret, 0);
@@ -3215,12 +3215,12 @@ static LIST *crypt_add_string_to_hints (LIST * hints, const char *str)
   char *scratch;
   char *t;
 
-  if ((scratch = str_dup (str)) == NULL)
+  if ((scratch = m_strdup(str)) == NULL)
     return hints;
 
   for (t = strtok (scratch, " ,.:\"()<>\n"); t;
        t = strtok (NULL, " ,.:\"()<>\n")) {
-    if (str_len (t) > 3)
+    if (m_strlen(t) > 3)
       hints = mutt_add_list (hints, t);
   }
 
@@ -3640,8 +3640,8 @@ static crypt_key_t *crypt_ask_for_key (char *tag,
         l = p_new(struct crypt_cache, 1);
         l->next = id_defaults;
         id_defaults = l;
-        l->what = str_dup (whatfor);
-        l->dflt = str_dup (resp);
+        l->what = m_strdup(whatfor);
+        l->dflt = m_strdup(resp);
       }
     }
 
@@ -3766,12 +3766,12 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc,
         *r_application &= ~APPLICATION_SMIME;
 #endif
 
-      keylist_size += str_len (s) + 4 + 1;
+      keylist_size += m_strlen(s) + 4 + 1;
       p_realloc(&keylist, keylist_size);
       sprintf (keylist + keylist_used, "%s0x%s%s",      /* __SPRINTF_CHECKED__ */
                keylist_used ? " " : "", s, forced_valid ? "!" : "");
     }
-    keylist_used = str_len (keylist);
+    keylist_used = m_strlen(keylist);
 
     crypt_free_key (&key);
     rfc822_free_address (&addr);
@@ -3925,9 +3925,9 @@ static int verify_sender (HEADER * h, gpgme_protocol_t protocol)
       int sender_length = 0;
       int uid_length = 0;
 
-      sender_length = str_len (sender->mailbox);
+      sender_length = m_strlen(sender->mailbox);
       for (uid = key->uids; uid && ret; uid = uid->next) {
-        uid_length = str_len (uid->email);
+        uid_length = m_strlen(uid->email);
         if (1 && (uid->email[0] == '<')
             && (uid->email[uid_length - 1] == '>')
             && (uid_length == sender_length + 2)