]> diplodocus.org Git - nmh/commitdiff
Changed c_cefile member of struct Content from pointer to
authorDavid Levine <levinedl@acm.org>
Fri, 15 Mar 2013 03:02:30 +0000 (22:02 -0500)
committerDavid Levine <levinedl@acm.org>
Fri, 15 Mar 2013 03:02:30 +0000 (22:02 -0500)
struct cefile.  The memory cost will be negligible and it
simplifies the MIME parser code a bit.

h/mhparse.h
uip/mhbuildsbr.c
uip/mhcachesbr.c
uip/mhfree.c
uip/mhlistsbr.c
uip/mhoutsbr.c
uip/mhparse.c

index 57bdabd396e9419504bb3e03e33477e7815d53e7..e8e7be880c307bed392915d89717c6be4157dfe0 100644 (file)
@@ -97,7 +97,7 @@ struct Content {
     int        c_subtype;              /* internal flag for content subtype */
 
     /* Content-Transfer-Encoding info (decoded contents) */
     int        c_subtype;              /* internal flag for content subtype */
 
     /* Content-Transfer-Encoding info (decoded contents) */
-    CE c_cefile;               /* structure holding decoded content */
+    struct cefile c_cefile;    /* structure holding decoded content */
     int        c_encoding;             /* internal flag for encoding type   */
 
     /* Content-MD5 info */
     int        c_encoding;             /* internal flag for encoding type   */
 
     /* Content-MD5 info */
index 8bac6d37c477c41c67a449fbe997bd4bc026ae8d..121978d71e8fc969f93eb16cfc7e0c9c06af0644 100644 (file)
@@ -347,12 +347,6 @@ finish_field:
 static int
 init_decoded_content (CT ct)
 {
 static int
 init_decoded_content (CT ct)
 {
-    CE ce;
-
-    if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL)
-       adios (NULL, "out of memory");
-
-    ct->c_cefile     = ce;
     ct->c_ceopenfnx  = open7Bit;       /* since unencoded */
     ct->c_ceclosefnx = close_encoding;
     ct->c_cesizefnx  = NULL;           /* since unencoded */
     ct->c_ceopenfnx  = open7Bit;       /* since unencoded */
     ct->c_ceclosefnx = close_encoding;
     ct->c_cesizefnx  = NULL;           /* since unencoded */
@@ -430,7 +424,7 @@ user_content (FILE *in, char *file, char *buf, CT *ctp)
 
     /* allocate basic structure for handling decoded content */
     init_decoded_content (ct);
 
     /* allocate basic structure for handling decoded content */
     init_decoded_content (ct);
-    ce = ct->c_cefile;
+    ce = &ct->c_cefile;
 
     ci = &ct->c_ctinfo;
     set_id (ct, 0);
 
     ci = &ct->c_ctinfo;
     set_id (ct, 0);
@@ -791,7 +785,7 @@ use_forw:
                    if ((p = (CT) calloc (1, sizeof(*p))) == NULL)
                        adios (NULL, "out of memory");
                    init_decoded_content (p);
                    if ((p = (CT) calloc (1, sizeof(*p))) == NULL)
                        adios (NULL, "out of memory");
                    init_decoded_content (p);
-                   pe = p->c_cefile;
+                   pe = &p->c_cefile;
                    if (get_ctinfo ("message/rfc822", p, 0) == NOTOK)
                        done (1);
                    p->c_type = CT_MESSAGE;
                    if (get_ctinfo ("message/rfc822", p, 0) == NOTOK)
                        done (1);
                    p->c_type = CT_MESSAGE;
@@ -926,7 +920,7 @@ set_id (CT ct, int top)
 static int
 compose_content (CT ct)
 {
 static int
 compose_content (CT ct)
 {
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     switch (ct->c_type) {
     case CT_MULTIPART:
 
     switch (ct->c_type) {
     case CT_MULTIPART:
@@ -1163,7 +1157,7 @@ scan_content (CT ct)
     char *cp = NULL, buffer[BUFSIZ];
     struct text *t = NULL;
     FILE *in = NULL;
     char *cp = NULL, buffer[BUFSIZ];
     struct text *t = NULL;
     FILE *in = NULL;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     /*
      * handle multipart by scanning all subparts
 
     /*
      * handle multipart by scanning all subparts
@@ -1632,7 +1626,7 @@ calculate_digest (CT ct, int asciiP)
     unsigned char digest[16];
     unsigned char outbuf[25];
     MD5_CTX mdContext;
     unsigned char digest[16];
     unsigned char outbuf[25];
     MD5_CTX mdContext;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
     char *infilename = ce->ce_file ? ce->ce_file : ct->c_file;
     FILE *in;
 
     char *infilename = ce->ce_file ? ce->ce_file : ct->c_file;
     FILE *in;
 
index 25ac9ab0b7a430654b9747e870dcf8752b9c08f7..7fa27ab39f9f30c5af145227782037e51de567c9 100644 (file)
@@ -96,7 +96,7 @@ cache_content (CT ct)
 {
     int        cachetype;
     char *file, cachefile[BUFSIZ];
 {
     int        cachetype;
     char *file, cachefile[BUFSIZ];
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     if (!ct->c_id) {
        advise (NULL, "no %s: field in %s", ID_FIELD, ct->c_file);
 
     if (!ct->c_id) {
        advise (NULL, "no %s: field in %s", ID_FIELD, ct->c_file);
index cf9e548e1fc0ed19bcca2be6a3cb5ff98bf90635..2328b78a56c3251c1ad1032c2ee15f0da655a823 100644 (file)
@@ -262,10 +262,7 @@ free_external (CT ct)
 void
 free_encoding (CT ct, int toplevel)
 {
 void
 free_encoding (CT ct, int toplevel)
 {
-    CE ce;
-
-    if (!(ce = ct->c_cefile))
-       return;
+    CE ce = &ct->c_cefile;
 
     if (ce->ce_fp) {
        fclose (ce->ce_fp);
 
     if (ce->ce_fp) {
        fclose (ce->ce_fp);
@@ -279,10 +276,7 @@ free_encoding (CT ct, int toplevel)
        ce->ce_file = NULL;
     }
 
        ce->ce_file = NULL;
     }
 
-    if (toplevel) {
-       free ((char *) ce);
-       ct->c_cefile = NULL;
-    } else {
+    if (! toplevel) {
        ct->c_ceopenfnx = NULL;
     }
 }
        ct->c_ceopenfnx = NULL;
     }
 }
index bc29243b8e6ee1e4d2b41c49745685f055ff0ed0..b39ed3d79a553a935501210f53a1aa2bdf9c60d4 100644 (file)
@@ -280,7 +280,7 @@ list_debug (CT ct)
 
     /* print internal flags for transfer encoding */
     fprintf (stderr, "    transfer encoding 0x%x params 0x%x\n",
 
     /* print internal flags for transfer encoding */
     fprintf (stderr, "    transfer encoding 0x%x params 0x%x\n",
-            ct->c_encoding, (unsigned int)(unsigned long) ct->c_cefile);
+            ct->c_encoding, (unsigned int)(unsigned long) &ct->c_cefile);
 
     /* print Content-ID */
     if (ct->c_id)
 
     /* print Content-ID */
     if (ct->c_id)
@@ -422,12 +422,11 @@ list_application (CT ct, int toplevel, int realsize, int verbose, int debug)
 static int
 list_encoding (CT ct)
 {
 static int
 list_encoding (CT ct)
 {
-    CE ce;
+    CE ce = &ct->c_cefile;
 
 
-    if ((ce = ct->c_cefile))
-       fprintf (stderr, "    decoded fp 0x%x file \"%s\"\n",
-                (unsigned int)(unsigned long) ce->ce_fp,
-                ce->ce_file ? ce->ce_file : "");
+    fprintf (stderr, "    decoded fp 0x%x file \"%s\"\n",
+            (unsigned int)(unsigned long) ce->ce_fp,
+            ce->ce_file ? ce->ce_file : "");
 
     return OK;
 }
 
     return OK;
 }
index db64c4b87d1e2af79e4e448d4ed3a5bf86ea6b6a..4845f7e1a3cffcc43bf82dd11936b7c7e0a25b1f 100644 (file)
@@ -300,7 +300,7 @@ write8Bit (CT ct, FILE *out)
     int fd;
     size_t inbytes;
     char c, *file, buffer[BUFSIZ];
     int fd;
     size_t inbytes;
     char c, *file, buffer[BUFSIZ];
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
 
     file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
@@ -329,7 +329,7 @@ writeQuoted (CT ct, FILE *out)
     int fd;
     char *cp, *file;
     char c, buffer[BUFSIZ];
     int fd;
     char *cp, *file;
     char c, buffer[BUFSIZ];
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
 
     file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
@@ -400,7 +400,7 @@ writeBase64ct (CT ct, FILE *out)
 {
     int        fd, result;
     char *file;
 {
     int        fd, result;
     char *file;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
 
     file = NULL;
     if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
index 4a70610e0f9c4ae0dda2299c59c99b9144919c2e..7dc988b6e39fd14308c7af6cd4813ef70b0fb42b 100644 (file)
@@ -1631,12 +1631,6 @@ InitApplication (CT ct)
 static int
 init_encoding (CT ct, OpenCEFunc openfnx)
 {
 static int
 init_encoding (CT ct, OpenCEFunc openfnx)
 {
-    CE ce;
-
-    if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL)
-       adios (NULL, "out of memory");
-
-    ct->c_cefile     = ce;
     ct->c_ceopenfnx  = openfnx;
     ct->c_ceclosefnx = close_encoding;
     ct->c_cesizefnx  = size_encoding;
     ct->c_ceopenfnx  = openfnx;
     ct->c_ceclosefnx = close_encoding;
     ct->c_cesizefnx  = size_encoding;
@@ -1648,10 +1642,7 @@ init_encoding (CT ct, OpenCEFunc openfnx)
 void
 close_encoding (CT ct)
 {
 void
 close_encoding (CT ct)
 {
-    CE ce;
-
-    if (!(ce = ct->c_cefile))
-       return;
+    CE ce = &ct->c_cefile;
 
     if (ce->ce_fp) {
        fclose (ce->ce_fp);
 
     if (ce->ce_fp) {
        fclose (ce->ce_fp);
@@ -1666,12 +1657,9 @@ size_encoding (CT ct)
     int        fd;
     unsigned long size;
     char *file;
     int        fd;
     unsigned long size;
     char *file;
-    CE ce;
+    CE ce = &ct->c_cefile;
     struct stat st;
 
     struct stat st;
 
-    if (!(ce = ct->c_cefile))
-       return (ct->c_end - ct->c_begin);
-
     if (ce->ce_fp && fstat (fileno (ce->ce_fp), &st) != NOTOK)
        return (long) st.st_size;
 
     if (ce->ce_fp && fstat (fileno (ce->ce_fp), &st) != NOTOK)
        return (long) st.st_size;
 
@@ -1740,10 +1728,9 @@ openBase64 (CT ct, char **file)
     char *cp, *ep, buffer[BUFSIZ];
     /* sbeck -- handle suffixes */
     CI ci;
     char *cp, *ep, buffer[BUFSIZ];
     /* sbeck -- handle suffixes */
     CI ci;
-    CE ce;
+    CE ce = &ct->c_cefile;
     MD5_CTX mdContext;
 
     MD5_CTX mdContext;
 
-    ce = ct->c_cefile;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
@@ -1973,12 +1960,11 @@ openQuoted (CT ct, char **file)
     char *cp, *ep;
     char buffer[BUFSIZ];
     unsigned char mask;
     char *cp, *ep;
     char buffer[BUFSIZ];
     unsigned char mask;
-    CE ce;
+    CE ce = &ct->c_cefile;
     /* sbeck -- handle suffixes */
     CI ci;
     MD5_CTX mdContext;
 
     /* sbeck -- handle suffixes */
     CI ci;
     MD5_CTX mdContext;
 
-    ce = ct->c_cefile;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
@@ -2201,9 +2187,8 @@ open7Bit (CT ct, char **file)
     /* sbeck -- handle suffixes */
     char *cp;
     CI ci;
     /* sbeck -- handle suffixes */
     char *cp;
     CI ci;
-    CE ce;
+    CE ce = &ct->c_cefile;
 
 
-    ce = ct->c_cefile;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
@@ -2422,7 +2407,7 @@ openFile (CT ct, char **file)
     int        fd, cachetype;
     char cachefile[BUFSIZ];
     struct exbody *e = ct->c_ctexbody;
     int        fd, cachetype;
     char cachefile[BUFSIZ];
     struct exbody *e = ct->c_ctexbody;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) {
        case NOTOK:
 
     switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) {
        case NOTOK:
@@ -2505,12 +2490,11 @@ openFTP (CT ct, char **file)
     char *bp, *ftp, *user, *pass;
     char buffer[BUFSIZ], cachefile[BUFSIZ];
     struct exbody *e;
     char *bp, *ftp, *user, *pass;
     char buffer[BUFSIZ], cachefile[BUFSIZ];
     struct exbody *e;
-    CE ce;
+    CE ce = &ct->c_cefile;
     static char *username = NULL;
     static char *password = NULL;
 
     e  = ct->c_ctexbody;
     static char *username = NULL;
     static char *password = NULL;
 
     e  = ct->c_ctexbody;
-    ce = ct->c_cefile;
 
     if ((ftp = context_find (nmhaccessftp)) && !*ftp)
        ftp = NULL;
 
     if ((ftp = context_find (nmhaccessftp)) && !*ftp)
        ftp = NULL;
@@ -2717,7 +2701,7 @@ openMail (CT ct, char **file)
     int len, buflen;
     char *bp, buffer[BUFSIZ], *vec[7];
     struct exbody *e = ct->c_ctexbody;
     int len, buflen;
     char *bp, buffer[BUFSIZ], *vec[7];
     struct exbody *e = ct->c_ctexbody;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) {
        case NOTOK:
 
     switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) {
        case NOTOK:
@@ -2836,7 +2820,7 @@ static int
 openURL (CT ct, char **file)
 {
     struct exbody *e = ct->c_ctexbody;
 openURL (CT ct, char **file)
 {
     struct exbody *e = ct->c_ctexbody;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
     char *urlprog, *program;
     char buffer[BUFSIZ], cachefile[BUFSIZ];
     int fd, caching, cachetype;
     char *urlprog, *program;
     char buffer[BUFSIZ], cachefile[BUFSIZ];
     int fd, caching, cachetype;