mutt_*mktemp--
[apps/madmutt.git] / pgppubring.c
index e5f729e..d7e5612 100644 (file)
  *
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
 
-#include "lib/mem.h"
-#include "lib/str.h"
+#include <lib-hash/hash.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
 #ifdef HAVE_GETOPT_H
 # include <getopt.h>
-#endif
-#include <errno.h>
-
+#else
 extern char *optarg;
 extern int optind;
+#endif
 
-short Umask;                    /* dirty hack because we need Umask in lib.c but don't want globals.h there */
+short Umask;   /* dirty hack because we need Umask in lib.c but don't want globals.h there */
 
-#include "sha1.h"
-#include "md5.h"
 #include "lib.h"
-#include "pgplib.h"
-#include "pgppacket.h"
+#include <lib-crypt/pgplib.h>
+#include <lib-crypt/pgppacket.h>
 
 #define MD5_DIGEST_LENGTH  16
 
@@ -56,8 +45,8 @@ short Umask;                    /* dirty hack because we need Umask in lib.c but
 #define FGETPOS(fp,pos) fgetpos((fp),&(pos))
 #define FSETPOS(fp,pos) fsetpos((fp),&(pos))
 #else
-#define FGETPOS(fp,pos) pos=ftell((fp));
-#define FSETPOS(fp,pos) fseek((fp),(pos),SEEK_SET)
+#define FGETPOS(fp,pos) pos=ftello((fp));
+#define FSETPOS(fp,pos) fseeko((fp),(pos),SEEK_SET)
 #endif
 
 
@@ -126,10 +115,10 @@ int main (int argc, char *const argv[])
   }
 
   if (_kring)
-    strfcpy (kring, _kring, sizeof (kring));
+    m_strcpy(kring, sizeof(kring), _kring);
   else {
     if ((env_pgppath = getenv ("PGPPATH")))
-      strfcpy (pgppath, env_pgppath, sizeof (pgppath));
+      m_strcpy(pgppath, sizeof(pgppath), env_pgppath);
     else if ((env_home = getenv ("HOME")))
       snprintf (pgppath, sizeof (pgppath), "%s/.pgp", env_home);
     else {
@@ -223,7 +212,7 @@ static pgp_key_t pgp_parse_pgp2_key (unsigned char *buff, size_t l)
     memcpy (p->fingerprint, digest, MD5_DIGEST_LENGTH);
   }
   else                          /* just to be usre */
-    memset (p->fingerprint, 0, MD5_DIGEST_LENGTH);
+    p_clear(p->fingerprint, MD5_DIGEST_LENGTH);
 
   expl = 0;
   for (i = 0; i < 2; i++)
@@ -246,13 +235,13 @@ static pgp_key_t pgp_parse_pgp2_key (unsigned char *buff, size_t l)
               "%08lX", id);
   }
 
-  p->keyid = safe_strdup ((char *) scratch);
+  p->keyid = m_strdup((char *) scratch);
 
   return p;
 
 bailout:
 
-  FREE (&p);
+  p_delete(&p);
   return NULL;
 }
 
@@ -348,7 +337,7 @@ static pgp_key_t pgp_parse_pgp3_key (unsigned char *buff, size_t l)
               id);
   }
 
-  p->keyid = safe_strdup ((char *) scratch);
+  p->keyid = m_strdup((char *) scratch);
 
   return p;
 }
@@ -579,7 +568,7 @@ static pgp_key_t pgp_parse_keyblock (FILE * fp)
 #ifdef HAVE_FGETPOS
   fpos_t pos;
 #else
-  long pos;
+  off_t pos;
 #endif
 
   pgp_key_t root = NULL;
@@ -636,7 +625,7 @@ static pgp_key_t pgp_parse_keyblock (FILE * fp)
     case PT_SIG:
       {
         if (lsig) {
-          pgp_sig_t *signature = safe_calloc (sizeof (pgp_sig_t), 1);
+          pgp_sig_t *signature = p_new(pgp_sig_t, 1);
 
           *lsig = signature;
           lsig = &signature->next;
@@ -667,12 +656,9 @@ static pgp_key_t pgp_parse_keyblock (FILE * fp)
         if (!addr)
           break;
 
-        chr = safe_malloc (l);
-        memcpy (chr, buff + 1, l - 1);
-        chr[l - 1] = '\0';
-
+        chr = p_dupstr(buff + 1, l - 1);
 
-        *addr = uid = safe_calloc (1, sizeof (pgp_uid_t));      /* XXX */
+        *addr = uid = p_new(pgp_uid_t, 1);      /* XXX */
         uid->addr = chr;
         uid->parent = p;
         uid->trust = 0;
@@ -710,7 +696,7 @@ static int pgpring_string_matches_hint (const char *s, const char *hints[],
     return 1;
 
   for (i = 0; i < nhints; i++) {
-    if (str_isstr (s, hints[i]) != NULL)
+    if (m_stristr(s, hints[i]) != NULL)
       return 1;
   }
 
@@ -730,7 +716,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
 #ifdef HAVE_FGETPOS
   fpos_t pos, keypos;
 #else
-  long pos, keypos;
+  off_t pos, keypos;
 #endif
 
   unsigned char *buff = NULL;
@@ -743,11 +729,11 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
     char *error_buf;
     size_t error_buf_len;
 
-    error_buf_len = sizeof ("fopen: ") - 1 + safe_strlen (ringfile) + 1;
-    error_buf = safe_malloc (error_buf_len);
+    error_buf_len = sizeof ("fopen: ") - 1 + m_strlen(ringfile) + 1;
+    error_buf = p_new(char, error_buf_len);
     snprintf (error_buf, error_buf_len, "fopen: %s", ringfile);
     perror (error_buf);
-    FREE (&error_buf);
+    p_delete(&error_buf);
     return;
   }
 
@@ -764,10 +750,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
       keypos = pos;
     }
     else if (pt == PT_NAME) {
-      char *tmp = safe_malloc (l);
-
-      memcpy (tmp, buff + 1, l - 1);
-      tmp[l - 1] = '\0';
+      char *tmp = p_dupstr(buff + 1, l - 1);
 
       /* mutt_decode_utf8_string (tmp, chs); */
 
@@ -785,14 +768,12 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
         pgp_free_key (&p);
       }
 
-      FREE (&tmp);
+      p_delete(&tmp);
     }
 
     FGETPOS (rfp, pos);
   }
-
-  fclose (rfp);
-
+  m_fclose(&rfp);
 }
 
 static void print_userid (const char *id)
@@ -915,13 +896,3 @@ static void pgpring_dump_keyblock (pgp_key_t p)
     }
   }
 }
-
-/*
- * The mutt_gettext () defined in gettext.c requires iconv,
- * so we do without charset conversion here.
- */
-
-char *mutt_gettext (const char *message)
-{
-  return (char *) message;
-}