From: David Levine Date: Fri, 15 Mar 2013 03:02:30 +0000 (-0500) Subject: Changed c_cefile member of struct Content from pointer to X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/859d1e1a78f6c61a062bfb534652f5ce3ffb672f?ds=sidebyside;hp=--cc Changed c_cefile member of struct Content from pointer to struct cefile. The memory cost will be negligible and it simplifies the MIME parser code a bit. --- 859d1e1a78f6c61a062bfb534652f5ce3ffb672f diff --git a/h/mhparse.h b/h/mhparse.h index 57bdabd3..e8e7be88 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -97,7 +97,7 @@ struct Content { 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 */ diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 8bac6d37..121978d7 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -347,12 +347,6 @@ finish_field: 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 */ @@ -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); - ce = ct->c_cefile; + ce = &ct->c_cefile; 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); - pe = p->c_cefile; + pe = &p->c_cefile; 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) { - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; 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; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; /* * 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; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; char *infilename = ce->ce_file ? ce->ce_file : ct->c_file; FILE *in; diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index 25ac9ab0..7fa27ab3 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -96,7 +96,7 @@ cache_content (CT ct) { 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); diff --git a/uip/mhfree.c b/uip/mhfree.c index cf9e548e..2328b78a 100644 --- a/uip/mhfree.c +++ b/uip/mhfree.c @@ -262,10 +262,7 @@ free_external (CT ct) 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); @@ -279,10 +276,7 @@ free_encoding (CT ct, int toplevel) ce->ce_file = NULL; } - if (toplevel) { - free ((char *) ce); - ct->c_cefile = NULL; - } else { + if (! toplevel) { ct->c_ceopenfnx = NULL; } } diff --git a/uip/mhlistsbr.c b/uip/mhlistsbr.c index bc29243b..b39ed3d7 100644 --- a/uip/mhlistsbr.c +++ b/uip/mhlistsbr.c @@ -280,7 +280,7 @@ list_debug (CT ct) /* 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) @@ -422,12 +422,11 @@ list_application (CT ct, int toplevel, int realsize, int verbose, int debug) 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; } diff --git a/uip/mhoutsbr.c b/uip/mhoutsbr.c index db64c4b8..4845f7e1 100644 --- a/uip/mhoutsbr.c +++ b/uip/mhoutsbr.c @@ -300,7 +300,7 @@ write8Bit (CT ct, FILE *out) 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) @@ -329,7 +329,7 @@ writeQuoted (CT ct, FILE *out) 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) @@ -400,7 +400,7 @@ writeBase64ct (CT ct, FILE *out) { 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) diff --git a/uip/mhparse.c b/uip/mhparse.c index 4a70610e..7dc988b6 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -1631,12 +1631,6 @@ InitApplication (CT ct) 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; @@ -1648,10 +1642,7 @@ init_encoding (CT ct, OpenCEFunc openfnx) 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); @@ -1666,12 +1657,9 @@ size_encoding (CT ct) int fd; unsigned long size; char *file; - CE ce; + CE ce = &ct->c_cefile; 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; @@ -1740,10 +1728,9 @@ openBase64 (CT ct, char **file) char *cp, *ep, buffer[BUFSIZ]; /* sbeck -- handle suffixes */ CI ci; - CE ce; + CE ce = &ct->c_cefile; MD5_CTX mdContext; - ce = ct->c_cefile; 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; - CE ce; + CE ce = &ct->c_cefile; /* 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; @@ -2201,9 +2187,8 @@ open7Bit (CT ct, char **file) /* 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; @@ -2422,7 +2407,7 @@ openFile (CT ct, char **file) 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: @@ -2505,12 +2490,11 @@ openFTP (CT ct, char **file) 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; - ce = ct->c_cefile; 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; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; 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; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; char *urlprog, *program; char buffer[BUFSIZ], cachefile[BUFSIZ]; int fd, caching, cachetype;