Rocco Rutte:
[apps/madmutt.git] / crypt-gpgme.c
index 4932abd..84bc377 100644 (file)
@@ -148,7 +148,7 @@ static const char *crypt_keyid (crypt_key_t * k)
 
   if (k->kobj && k->kobj->subkeys) {
     s = k->kobj->subkeys->keyid;
-    if ((!option (OPTPGPLONGIDS)) && (mutt_strlen (s) == 16))
+    if ((!option (OPTPGPLONGIDS)) && (safe_strlen (s) == 16))
       /* Return only the short keyID.  */
       s += 8;
   }
@@ -294,11 +294,11 @@ static int crypt_id_matches_addr (ADDRESS * addr, ADDRESS * u_addr,
     rv |= CRYPT_KV_STRONGID;
 
   if (addr->mailbox && u_addr->mailbox
-      && mutt_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
+      && safe_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
     rv |= CRYPT_KV_ADDR;
 
   if (addr->personal && u_addr->personal
-      && mutt_strcasecmp (addr->personal, u_addr->personal) == 0)
+      && safe_strcasecmp (addr->personal, u_addr->personal) == 0)
     rv |= CRYPT_KV_STRING;
 
   return rv;
@@ -1002,7 +1002,7 @@ static int show_sig_summary (unsigned long sum,
       state_attach_puts (": ", s);
       if (t0)
         state_attach_puts (t0, s);
-      if (t1 && !(t0 && !mutt_strcmp (t0, t1))) {
+      if (t1 && !(t0 && !safe_strcmp (t0, t1))) {
         if (t0)
           state_attach_puts (",", s);
         state_attach_puts (t1, s);
@@ -1029,10 +1029,10 @@ static void show_fingerprint (gpgme_key_t key, STATE * state)
     return;
   is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
 
-  buf = safe_malloc (mutt_strlen (prefix) + mutt_strlen (s) * 4 + 2);
+  buf = safe_malloc (safe_strlen (prefix) + safe_strlen (s) * 4 + 2);
   strcpy (buf, prefix);         /* __STRCPY_CHECKED__ */
-  p = buf + mutt_strlen (buf);
-  if (is_pgp && mutt_strlen (s) == 40) {     /* PGP v4 style formatted. */
+  p = buf + safe_strlen (buf);
+  if (is_pgp && safe_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];
@@ -1297,7 +1297,7 @@ static int verify_one (BODY * sigbdy, STATE * s,
             if (notation->value) {
               state_attach_puts (notation->value, s);
               if (!(*notation->value
-                    && (notation->value[mutt_strlen (notation->value) - 1] ==
+                    && (notation->value[safe_strlen (notation->value) - 1] ==
                         '\n')))
                 state_attach_puts ("\n", s);
             }
@@ -1655,10 +1655,10 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b,
   }
 
   while (fgets (buf, sizeof (buf), tfp)) {
-    if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) {
-      if (!mutt_strcmp ("MESSAGE-----\n", buf + 15))
+    if (!safe_strncmp ("-----BEGIN PGP ", buf, 15)) {
+      if (!safe_strcmp ("MESSAGE-----\n", buf + 15))
         enc = 1;
-      else if (!mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15))
+      else if (!safe_strcmp ("SIGNED MESSAGE-----\n", buf + 15))
         sgn = 1;
     }
   }
@@ -1737,7 +1737,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset)
       continue;
     }
 
-    if (!mutt_strcmp (buf, "-----BEGIN PGP SIGNATURE-----\n"))
+    if (!safe_strcmp (buf, "-----BEGIN PGP SIGNATURE-----\n"))
       break;
 
     if (armor_header) {
@@ -1794,21 +1794,21 @@ void pgp_gpgme_application_handler (BODY * m, STATE * s)
       break;
 
     offset = ftell (s->fpin);
-    bytes -= (offset - last_pos);       /* don't rely on mutt_strlen(buf) */
+    bytes -= (offset - last_pos);       /* don't rely on safe_strlen(buf) */
     last_pos = offset;
 
-    if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) {
+    if (!safe_strncmp ("-----BEGIN PGP ", buf, 15)) {
       clearsign = 0;
       start_pos = last_pos;
 
-      if (!mutt_strcmp ("MESSAGE-----\n", buf + 15))
+      if (!safe_strcmp ("MESSAGE-----\n", buf + 15))
         needpass = 1;
-      else if (!mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15)) {
+      else if (!safe_strcmp ("SIGNED MESSAGE-----\n", buf + 15)) {
         clearsign = 1;
         needpass = 0;
       }
       else if (!option (OPTDONTHANDLEPGPKEYS) &&
-               !mutt_strcmp ("PUBLIC KEY BLOCK-----\n", buf + 15)) {
+               !safe_strcmp ("PUBLIC KEY BLOCK-----\n", buf + 15)) {
         needpass = 0;
         pgp_keyblock = 1;
       }
@@ -1824,18 +1824,18 @@ void 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, mutt_strlen (buf));
+      gpgme_data_write (armored_data, buf, safe_strlen (buf));
       while (bytes > 0 && fgets (buf, sizeof (buf) - 1, s->fpin) != NULL) {
         offset = ftell (s->fpin);
-        bytes -= (offset - last_pos);   /* don't rely on mutt_strlen(buf) */
+        bytes -= (offset - last_pos);   /* don't rely on safe_strlen(buf) */
         last_pos = offset;
 
-        gpgme_data_write (armored_data, buf, mutt_strlen (buf));
+        gpgme_data_write (armored_data, buf, safe_strlen (buf));
 
-        if ((needpass && !mutt_strcmp ("-----END PGP MESSAGE-----\n", buf))
+        if ((needpass && !safe_strcmp ("-----END PGP MESSAGE-----\n", buf))
             || (!needpass
-                && (!mutt_strcmp ("-----END PGP SIGNATURE-----\n", buf)
-                    || !mutt_strcmp ("-----END PGP PUBLIC KEY BLOCK-----\n",
+                && (!safe_strcmp ("-----END PGP SIGNATURE-----\n", buf)
+                    || !safe_strcmp ("-----END PGP PUBLIC KEY BLOCK-----\n",
                                      buf))))
           break;
       }
@@ -2367,10 +2367,10 @@ static int _crypt_compare_address (const void *a, const void *b)
   crypt_key_t **t = (crypt_key_t **) b;
   int r;
 
-  if ((r = mutt_strcasecmp ((*s)->uid, (*t)->uid)))
+  if ((r = safe_strcasecmp ((*s)->uid, (*t)->uid)))
     return r > 0;
   else
-    return mutt_strcasecmp (crypt_keyid (*s), crypt_keyid (*t)) > 0;
+    return safe_strcasecmp (crypt_keyid (*s), crypt_keyid (*t)) > 0;
 }
 
 static int crypt_compare_address (const void *a, const void *b)
@@ -2387,10 +2387,10 @@ static int _crypt_compare_keyid (const void *a, const void *b)
   crypt_key_t **t = (crypt_key_t **) b;
   int r;
 
-  if ((r = mutt_strcasecmp (crypt_keyid (*s), crypt_keyid (*t))))
+  if ((r = safe_strcasecmp (crypt_keyid (*s), crypt_keyid (*t))))
     return r > 0;
   else
-    return mutt_strcasecmp ((*s)->uid, (*t)->uid) > 0;
+    return safe_strcasecmp ((*s)->uid, (*t)->uid) > 0;
 }
 
 static int crypt_compare_keyid (const void *a, const void *b)
@@ -2416,7 +2416,7 @@ static int _crypt_compare_date (const void *a, const void *b)
   if (ts < tt)
     return 0;
 
-  return mutt_strcasecmp ((*s)->uid, (*t)->uid) > 0;
+  return safe_strcasecmp ((*s)->uid, (*t)->uid) > 0;
 }
 
 static int crypt_compare_date (const void *a, const void *b)
@@ -2461,9 +2461,9 @@ static int _crypt_compare_trust (const void *a, const void *b)
   if (ts < tt)
     return 0;
 
-  if ((r = mutt_strcasecmp ((*s)->uid, (*t)->uid)))
+  if ((r = safe_strcasecmp ((*s)->uid, (*t)->uid)))
     return r > 0;
-  return (mutt_strcasecmp (crypt_keyid ((*s)), crypt_keyid ((*t)))) > 0;
+  return (safe_strcasecmp (crypt_keyid ((*s)), crypt_keyid ((*t)))) > 0;
 }
 
 static int crypt_compare_trust (const void *a, const void *b)
@@ -2479,10 +2479,10 @@ static int print_dn_part (FILE * fp, struct dn_array_s *dn, const char *key)
   int any = 0;
 
   for (; dn->key; dn++) {
-    if (!mutt_strcmp (dn->key, key)) {
+    if (!safe_strcmp (dn->key, key)) {
       if (any)
         fputs (" + ", fp);
-      print_utf8 (fp, dn->value, mutt_strlen (dn->value));
+      print_utf8 (fp, dn->value, safe_strlen (dn->value));
       any = 1;
     }
   }
@@ -2505,7 +2505,7 @@ static void print_dn_parts (FILE * fp, struct dn_array_s *dn)
   /* now print the rest without any specific ordering */
   for (; dn->key; dn++) {
     for (i = 0; stdpart[i]; i++) {
-      if (!mutt_strcmp (dn->key, stdpart[i]))
+      if (!safe_strcmp (dn->key, stdpart[i]))
         break;
     }
     if (!stdpart[i]) {
@@ -2758,7 +2758,7 @@ static void print_key_info (gpgme_key_t key, FILE * fp)
       putc (' ', fp);
     }
     if (is_pgp)
-      print_utf8 (fp, s, mutt_strlen (s));
+      print_utf8 (fp, s, safe_strlen (s));
     else
       parse_and_print_user_id (fp, s);
     putc ('\n', fp);
@@ -2820,7 +2820,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 && mutt_strlen (s) == 40) {
+    if (is_pgp && safe_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);
@@ -2866,7 +2866,7 @@ static void print_key_info (gpgme_key_t key, FILE * fp)
       s = subkey->keyid;
 
       putc ('\n', fp);
-      if (mutt_strlen (s) == 16)
+      if (safe_strlen (s) == 16)
         s += 8;                 /* display only the short keyID */
       fprintf (fp, "Subkey ....: 0x%s", s);
       if (subkey->revoked) {
@@ -2979,7 +2979,7 @@ static void verify_key (crypt_key_t * key)
 
   k = key->kobj;
   gpgme_key_ref (k);
-  while ((s = k->chain_id) && k->subkeys && mutt_strcmp (s, k->subkeys->fpr)) {
+  while ((s = k->chain_id) && k->subkeys && safe_strcmp (s, k->subkeys->fpr)) {
     putc ('\n', fp);
     err = gpgme_op_keylist_start (listctx, s, 0);
     gpgme_key_release (k);
@@ -3218,7 +3218,7 @@ static LIST *crypt_add_string_to_hints (LIST * hints, const char *str)
 
   for (t = strtok (scratch, " ,.:\"()<>\n"); t;
        t = strtok (NULL, " ,.:\"()<>\n")) {
-    if (mutt_strlen (t) > 3)
+    if (safe_strlen (t) > 3)
       hints = mutt_add_list (hints, t);
   }
 
@@ -3571,13 +3571,13 @@ static crypt_key_t *crypt_getkeybystr (char *p, short abilities,
     dprint (5, (debugfile, "crypt_getkeybystr: matching \"%s\" against "
                 "key %s, \"%s\": ", p, crypt_keyid (k), k->uid));
 
-    if (!*p || !mutt_strcasecmp (p, crypt_keyid (k))
-        || (!mutt_strncasecmp (p, "0x", 2)
-            && !mutt_strcasecmp (p + 2, crypt_keyid (k)))
+    if (!*p || !safe_strcasecmp (p, crypt_keyid (k))
+        || (!safe_strncasecmp (p, "0x", 2)
+            && !safe_strcasecmp (p + 2, crypt_keyid (k)))
         || (option (OPTPGPLONGIDS)
-            && !mutt_strncasecmp (p, "0x", 2)
-            && !mutt_strcasecmp (p + 2, crypt_keyid (k) + 8))
-        || mutt_stristr (k->uid, p)) {
+            && !safe_strncasecmp (p, "0x", 2)
+            && !safe_strcasecmp (p + 2, crypt_keyid (k) + 8))
+        || str_isstr (k->uid, p)) {
       crypt_key_t *tmp;
 
       dprint (5, (debugfile, "match.\n"));
@@ -3623,7 +3623,7 @@ static crypt_key_t *crypt_ask_for_key (char *tag,
   if (whatfor) {
 
     for (l = id_defaults; l; l = l->next)
-      if (!mutt_strcasecmp (whatfor, l->what)) {
+      if (!safe_strcasecmp (whatfor, l->what)) {
         strfcpy (resp, NONULL (l->dflt), sizeof (resp));
         break;
       }
@@ -3637,7 +3637,7 @@ static crypt_key_t *crypt_ask_for_key (char *tag,
 
     if (whatfor) {
       if (l)
-        mutt_str_replace (&l->dflt, resp);
+        str_replace (&l->dflt, resp);
       else {
         l = safe_malloc (sizeof (struct crypt_cache));
         l->next = id_defaults;
@@ -3768,12 +3768,12 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc,
         *r_application &= ~APPLICATION_SMIME;
 #endif
 
-      keylist_size += mutt_strlen (s) + 4 + 1;
+      keylist_size += safe_strlen (s) + 4 + 1;
       safe_realloc (&keylist, keylist_size);
       sprintf (keylist + keylist_used, "%s0x%s%s",      /* __SPRINTF_CHECKED__ */
                keylist_used ? " " : "", s, forced_valid ? "!" : "");
     }
-    keylist_used = mutt_strlen (keylist);
+    keylist_used = safe_strlen (keylist);
 
     crypt_free_key (&key);
     rfc822_free_address (&addr);
@@ -3853,7 +3853,7 @@ static int gpgme_send_menu (HEADER * msg, int *redraw, int is_smime)
                                 is_smime ? APPLICATION_SMIME :
                                 APPLICATION_PGP, NULL))) {
       snprintf (input_signas, sizeof (input_signas), "0x%s", crypt_keyid (p));
-      mutt_str_replace (is_smime ? &SmimeDefaultKey : &PgpSignAs,
+      str_replace (is_smime ? &SmimeDefaultKey : &PgpSignAs,
                         input_signas);
       crypt_free_key (&p);
 
@@ -3923,9 +3923,9 @@ static int verify_sender (HEADER * h, gpgme_protocol_t protocol)
       int sender_length = 0;
       int uid_length = 0;
 
-      sender_length = mutt_strlen (sender->mailbox);
+      sender_length = safe_strlen (sender->mailbox);
       for (uid = key->uids; uid && ret; uid = uid->next) {
-        uid_length = mutt_strlen (uid->email);
+        uid_length = safe_strlen (uid->email);
         if (1 && (uid->email[0] == '<')
             && (uid->email[uid_length - 1] == '>')
             && (uid_length == sender_length + 2)