exit strfcpy, only use m_strcpy.
[apps/madmutt.git] / rfc2231.c
index 19a4add..0f9a2f5 100644 (file)
--- a/rfc2231.c
+++ b/rfc2231.c
@@ -1,22 +1,10 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
  *
- *     This program is free software; you can redistribute it
- *     and/or modify it under the terms of the GNU General Public
- *     License as published by the Free Software Foundation; either
- *     version 2 of the License, or (at your option) any later
- *     version.
- * 
- *     This program is distributed in the hope that it will be
- *     useful, but WITHOUT ANY WARRANTY; without even the implied
- *     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- *     PURPOSE.  See the GNU General Public License for more
- *     details.
- * 
- *     You should have received a copy of the GNU General Public
- *     License along with this program; if not, write to the Free
- *     Software Foundation, Inc., 59 Temple Place - Suite 330,
- *     Boston, MA  02111, USA.
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
  */
 
 /*
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+#include <lib-lib/ascii.h>
+
 #include "mutt.h"
 #include "mime.h"
 #include "charset.h"
@@ -154,7 +146,7 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
 
       p->attribute = NULL;
       p->value = NULL;
-      FREE (&p);
+      p_delete(&p);
 
       rfc2231_list_insert (&conthead, conttmp);
     }
@@ -173,15 +165,15 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
 
 static struct rfc2231_parameter *rfc2231_new_parameter (void)
 {
-  return safe_calloc (sizeof (struct rfc2231_parameter), 1);
+  return p_new(struct rfc2231_parameter, 1);
 }
 
 static void rfc2231_free_parameter (struct rfc2231_parameter **p)
 {
   if (*p) {
-    FREE (&(*p)->attribute);
-    FREE (&(*p)->value);
-    FREE (p);
+    p_delete(&(*p)->attribute);
+    p_delete(&(*p)->value);
+    p_delete(p);
   }
 }
 
@@ -195,7 +187,7 @@ static char *rfc2231_get_charset (char *value, char *charset, size_t chslen)
   }
 
   *t = '\0';
-  strfcpy (charset, value, chslen);
+  m_strcpy(charset, chslen, value);
 
   if ((u = strchr (t + 1, '\'')))
     return u + 1;
@@ -239,7 +231,7 @@ static void rfc2231_list_insert (struct rfc2231_parameter **list,
     q = p;
     p = p->next;
 
-    c = strcmp (par->value, q->value);
+    c = m_strcmp(par->value, q->value);
     if ((c > 0) || (c == 0 && par->index >= q->index))
       break;
   }
@@ -267,7 +259,7 @@ static void rfc2231_join_continuations (PARAMETER ** head,
     value = NULL;
     l = 0;
 
-    strfcpy (attribute, par->attribute, sizeof (attribute));
+    m_strcpy(attribute, sizeof(attribute), par->attribute);
 
     if ((encoded = par->encoded))
       valp = rfc2231_get_charset (par->value, charset, sizeof (charset));
@@ -278,9 +270,9 @@ static void rfc2231_join_continuations (PARAMETER ** head,
       if (encoded && par->encoded)
         rfc2231_decode_one (par->value, valp);
 
-      vl = strlen (par->value);
+      vl = m_strlen(par->value);
 
-      safe_realloc (&value, l + vl + 1);
+      p_realloc(&value, l + vl + 1);
       strcpy (value + l, par->value);   /* __STRCPY_CHECKED__ */
       l += vl;
 
@@ -288,13 +280,13 @@ static void rfc2231_join_continuations (PARAMETER ** head,
       rfc2231_free_parameter (&par);
       if ((par = q))
         valp = par->value;
-    } while (par && !strcmp (par->attribute, attribute));
+    } while (par && !m_strcmp(par->attribute, attribute));
 
     if (value) {
       if (encoded)
         mutt_convert_string (&value, charset, Charset, M_ICONV_HOOK_FROM);
       *head = mutt_new_parameter ();
-      (*head)->attribute = safe_strdup (attribute);
+      (*head)->attribute = m_strdup(attribute);
       (*head)->value = value;
       head = &(*head)->next;
     }
@@ -323,10 +315,10 @@ int rfc2231_encode_string (char **pd)
 
   if (!Charset || !SendCharset ||
       !(charset = mutt_choose_charset (Charset, SendCharset,
-                                       *pd, strlen (*pd), &d, &dlen))) {
-    charset = safe_strdup (Charset ? Charset : "unknown-8bit");
+                                       *pd, m_strlen(*pd), &d, &dlen))) {
+    charset = m_strdup(Charset ? Charset : "unknown-8bit");
     d = *pd;
-    dlen = strlen (d);
+    dlen = m_strlen(d);
   }
 
   if (!mutt_is_us_ascii (charset))
@@ -339,9 +331,9 @@ int rfc2231_encode_string (char **pd)
       ++ext;
 
   if (encode) {
-    e = safe_malloc (dlen + 2 * ext + strlen (charset) + 3);
+    e = p_new(char, dlen + 2 * ext + m_strlen(charset) + 3);
     sprintf (e, "%s''", charset);       /* __SPRINTF_CHECKED__ */
-    t = e + strlen (e);
+    t = e + m_strlen(e);
     for (s = d, slen = dlen; slen; s++, slen--)
       if (*s < 0x20 || *s >= 0x7f ||
           strchr (MimeSpecials, *s) || strchr ("*'%", *s)) {
@@ -353,16 +345,16 @@ int rfc2231_encode_string (char **pd)
     *t = '\0';
 
     if (d != *pd)
-      FREE (&d);
-    FREE (pd);
+      p_delete(&d);
+    p_delete(pd);
     *pd = e;
   }
   else if (d != *pd) {
-    FREE (pd);
+    p_delete(pd);
     *pd = d;
   }
 
-  FREE (&charset);
+  p_delete(&charset);
 
   return encode;
 }