]> diplodocus.org Git - nmh/commitdiff
Add extra argument to add_param() so it can use the passed-in pointers
authorKen Hornstein <kenh@pobox.com>
Wed, 5 Mar 2014 23:22:56 +0000 (18:22 -0500)
committerKen Hornstein <kenh@pobox.com>
Wed, 5 Mar 2014 23:22:56 +0000 (18:22 -0500)
directly without making copies first.

h/mhparse.h
uip/mhbuildsbr.c
uip/mhfixmsg.c
uip/mhparse.c

index b67547942b14e79a199064d65fc0c7f144456e47..9b058e6887bc7bb5af0b4df60bd50065ff934215 100644 (file)
@@ -418,10 +418,14 @@ char *output_params(size_t initialwidth, PM params, int *offsetout,
  * last                - Pointer to tail of linked list
  * name                - Name of parameter
  * value       - Value of parameter
  * last                - Pointer to tail of linked list
  * name                - Name of parameter
  * value       - Value of parameter
+ * nocopy      - If set, will use the pointer values directly for "name"
+ *               and "value" instead of making their own copy.  These
+ *               pointers will be free()'d later by the MIME routines, so
+ *               they should not be used after calling this function!
  *
  *
- * Returned allocated parameter element
+ * Returns allocated parameter element
  */
  */
-PM add_param(PM *first, PM *last, const char *name, const char *value);
+PM add_param(PM *first, PM *last, char *name, char *value, int nocopy);
 
 /*
  * Retrieve a parameter value from a parameter linked list.  Convert to the
 
 /*
  * Retrieve a parameter value from a parameter linked list.  Convert to the
index 95bbd4149f098c1427bd6915764662920c505426..555e3b5c673d9fe70cac83acd493a09c5f71badb 100644 (file)
@@ -1468,7 +1468,7 @@ scan_content (CT ct, size_t maxunencoded)
            CI ci = &ct->c_ctinfo;
 
            add_param(&ci->ci_first_pm, &ci->ci_last_pm, "charset",
            CI ci = &ct->c_ctinfo;
 
            add_param(&ci->ci_first_pm, &ci->ci_last_pm, "charset",
-                     contains8bit ? write_charset_8bit() : "us-ascii");
+                     contains8bit ? write_charset_8bit() : "us-ascii", 0);
            t->tx_charset = CHARSET_SPECIFIED;
        }
     }
            t->tx_charset = CHARSET_SPECIFIED;
        }
     }
@@ -1536,7 +1536,7 @@ build_headers (CT ct, int header_encoding)
        static int level = 0;   /* store nesting level */
 
        snprintf (buffer, sizeof(buffer), "%s%d", prefix, level++);
        static int level = 0;   /* store nesting level */
 
        snprintf (buffer, sizeof(buffer), "%s%d", prefix, level++);
-       add_param(&ci->ci_first_pm, &ci->ci_last_pm, "boundary", buffer);
+       add_param(&ci->ci_first_pm, &ci->ci_last_pm, "boundary", buffer, 0);
     }
 
     /*
     }
 
     /*
@@ -1907,7 +1907,7 @@ setup_attach_content(CT ct, char *filename)
 
     if (pm == NULL)
        add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
 
     if (pm == NULL)
        add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
-                 "name", simplename);
+                 "name", simplename, 0);
 
     ct->c_descr = getcpy(simplename);
     ct->c_descr = add("\n", ct->c_descr);
 
     ct->c_descr = getcpy(simplename);
     ct->c_descr = add("\n", ct->c_descr);
@@ -1926,5 +1926,5 @@ setup_attach_content(CT ct, char *filename)
        ct->c_dispo_type = getcpy("attachment");
     }
 
        ct->c_dispo_type = getcpy("attachment");
     }
 
-    add_param(&ct->c_dispo_first, &ct->c_dispo_last, "filename", simplename);
+    add_param(&ct->c_dispo_first, &ct->c_dispo_last, "filename", simplename, 0);
 }
 }
index 9f317acdcac39d3bea97a83ea9cb9dfd0848ff9d..07433377ef2003cbff00906753d3c3a43ebe0468 100644 (file)
@@ -1080,7 +1080,7 @@ copy_ctinfo (CI dest, CI src) {
 
     for (s_pm = src->ci_first_pm; s_pm; s_pm = s_pm->pm_next) {
        d_pm = add_param(&dest->ci_first_pm, &dest->ci_last_pm, s_pm->pm_name,
 
     for (s_pm = src->ci_first_pm; s_pm; s_pm = s_pm->pm_next) {
        d_pm = add_param(&dest->ci_first_pm, &dest->ci_last_pm, s_pm->pm_name,
-                        s_pm->pm_value);
+                        s_pm->pm_value, 0);
        if (s_pm->pm_charset)
            d_pm->pm_charset = getcpy(s_pm->pm_charset);
        if (s_pm->pm_lang)
        if (s_pm->pm_charset)
            d_pm->pm_charset = getcpy(s_pm->pm_charset);
        if (s_pm->pm_lang)
@@ -1314,7 +1314,7 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) {
     }
 
     add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
     }
 
     add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
-             "boundary", boundary);
+             "boundary", boundary, 0);
 
     p = (struct part *) mh_xmalloc (sizeof *p);
     p->mp_next = (struct part *) mh_xmalloc (sizeof *p->mp_next);
 
     p = (struct part *) mh_xmalloc (sizeof *p);
     p->mp_next = (struct part *) mh_xmalloc (sizeof *p->mp_next);
index 0ec76071cb123f698beb55f0ef95bd4652bfc1d5..943e4233325b0a2dcf706d2a78283c94aa6cbf51 100644 (file)
@@ -838,7 +838,7 @@ magic_skip:
             if (ct->c_dispo_type &&
                !get_param(ct->c_dispo_first, "filename", '_', 1)) {
                add_param(&ct->c_dispo_first, &ct->c_dispo_last, "filename",
             if (ct->c_dispo_type &&
                !get_param(ct->c_dispo_first, "filename", '_', 1)) {
                add_param(&ct->c_dispo_first, &ct->c_dispo_last, "filename",
-                         r1bindex(ci->ci_magic, '/'));
+                         r1bindex(ci->ci_magic, '/'), 0);
            }
         }
        else
            }
         }
        else
@@ -3590,9 +3590,7 @@ bad_quote:
                pp->lang = lang;
            }
        } else {
                pp->lang = lang;
            }
        } else {
-           pm = add_param(param_head, param_tail, nameptr, valptr);
-           free(nameptr);
-           free(valptr);
+           pm = add_param(param_head, param_tail, nameptr, valptr, 1);
            pm->pm_charset = charset;
            pm->pm_lang = lang;
        }
            pm->pm_charset = charset;
            pm->pm_lang = lang;
        }
@@ -3637,11 +3635,9 @@ bad_quote:
 
        p[tlen] = '\0';
 
 
        p[tlen] = '\0';
 
-       pm = add_param(param_head, param_tail, pp->name, p);
+       pm = add_param(param_head, param_tail, pp->name, p, 1);
        pm->pm_charset = pp->charset;
        pm->pm_lang = pp->lang;
        pm->pm_charset = pp->charset;
        pm->pm_lang = pp->lang;
-       free(pp->name);
-       free(p);
        pp2 = pp->next;
        free(pp);
        pp = pp2;
        pp2 = pp->next;
        free(pp);
        pp = pp2;
@@ -4058,14 +4054,14 @@ normal_param(PM pm, char *output, size_t len, size_t valuelen,
  */
 
 PM
  */
 
 PM
-add_param(PM *first, PM *last, const char *name, const char *value)
+add_param(PM *first, PM *last, char *name, char *value, int nocopy)
 {
     PM pm = mh_xmalloc(sizeof(*pm));
 
     memset(pm, 0, sizeof(*pm));
 
 {
     PM pm = mh_xmalloc(sizeof(*pm));
 
     memset(pm, 0, sizeof(*pm));
 
-    pm->pm_name = getcpy(name);
-    pm->pm_value = getcpy(value);
+    pm->pm_name = nocopy ? name : getcpy(name);
+    pm->pm_value = nocopy ? value : getcpy(value);
 
     if (*first) {
        (*last)->pm_next = pm;
 
     if (*first) {
        (*last)->pm_next = pm;