X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fmhparse.c;h=4c3a19460b0cdfe27214b23568e651457bf28e3e;hb=1888a6885e0c4049755578814462cad4259e85df;hp=bca794228593a63f5660b9cd6c54eb0f73d2f831;hpb=2f689a1cb907a5de04e6d39ffd217a69af3216c7;p=mmh diff --git a/uip/mhparse.c b/uip/mhparse.c index bca7942..4c3a194 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -2,8 +2,6 @@ /* * mhparse.c -- routines to parse the contents of MIME messages * - * $Id$ - * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. @@ -14,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -22,10 +19,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - extern int debugsw; @@ -92,16 +85,12 @@ struct k2v SubApplication[] = { }; -/* ftpsbr.c */ -int ftp_get (char *, char *, char *, char *, char *, char *, int, int); - /* mhcachesbr.c */ int find_cache (CT, int, int *, char *, char *, int); /* mhmisc.c */ int part_ok (CT, int); int type_ok (CT, int); -int make_intermediates (char *); void content_error (char *, CT, char *, ...); /* mhfree.c */ @@ -1048,6 +1037,8 @@ invalid: static int InitGeneric (CT ct) { + NMH_UNUSED (ct); + return OK; /* not much to do here */ } @@ -1736,7 +1727,7 @@ static int openBase64 (CT ct, char **file) { int bitno, cc, digested; - int fd, len, skip; + int fd, len, skip, own_ct_fp = 0; unsigned long bits; unsigned char value, *b, *b1, *b2, *b3; unsigned char *cp, *ep; @@ -1785,8 +1776,8 @@ openBase64 (CT ct, char **file) } if (cp != NULL && *cp != '\0') { if (ce->ce_unlink) { - // Temporary file already exists, so we rename to - // version with extension. + /* Temporary file already exists, so we rename to + version with extension. */ char *file_org = strdup(ce->ce_file); ce->ce_file = add (cp, ce->ce_file); if (rename(file_org, ce->ce_file)) { @@ -1807,9 +1798,12 @@ openBase64 (CT ct, char **file) if ((len = ct->c_end - ct->c_begin) < 0) adios (NULL, "internal error(1)"); - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - content_error (ct->c_file, ct, "unable to open for reading"); - return NOTOK; + if (! ct->c_fp) { + if ((ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + content_error (ct->c_file, ct, "unable to open for reading"); + return NOTOK; + } + own_ct_fp = 1; } if ((digested = ct->c_digested)) @@ -1921,9 +1915,17 @@ self_delimiting: ready_to_go: *file = ce->ce_file; + if (own_ct_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } return fileno (ce->ce_fp); clean_up: + if (own_ct_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } free_encoding (ct, 0); return NOTOK; } @@ -1963,7 +1965,7 @@ InitQuoted (CT ct) static int openQuoted (CT ct, char **file) { - int cc, digested, len, quoted; + int cc, digested, len, quoted, own_ct_fp = 0; unsigned char *cp, *ep; char buffer[BUFSIZ]; unsigned char mask; @@ -2006,8 +2008,8 @@ openQuoted (CT ct, char **file) } if (cp != NULL && *cp != '\0') { if (ce->ce_unlink) { - // Temporary file already exists, so we rename to - // version with extension. + /* Temporary file already exists, so we rename to + version with extension. */ char *file_org = strdup(ce->ce_file); ce->ce_file = add (cp, ce->ce_file); if (rename(file_org, ce->ce_file)) { @@ -2025,17 +2027,15 @@ openQuoted (CT ct, char **file) return NOTOK; } - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } - if ((len = ct->c_end - ct->c_begin) < 0) adios (NULL, "internal error(2)"); - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - content_error (ct->c_file, ct, "unable to open for reading"); - return NOTOK; + if (! ct->c_fp) { + if ((ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + content_error (ct->c_file, ct, "unable to open for reading"); + return NOTOK; + } + own_ct_fp = 1; } if ((digested = ct->c_digested)) @@ -2157,10 +2157,18 @@ openQuoted (CT ct, char **file) ready_to_go: *file = ce->ce_file; + if (own_ct_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } return fileno (ce->ce_fp); clean_up: free_encoding (ct, 0); + if (own_ct_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } return NOTOK; } @@ -2183,7 +2191,7 @@ Init7Bit (CT ct) int open7Bit (CT ct, char **file) { - int cc, fd, len; + int cc, fd, len, own_ct_fp = 0; char buffer[BUFSIZ]; /* sbeck -- handle suffixes */ char *cp; @@ -2224,8 +2232,8 @@ open7Bit (CT ct, char **file) } if (cp != NULL && *cp != '\0') { if (ce->ce_unlink) { - // Temporary file already exists, so we rename to - // version with extension. + /* Temporary file already exists, so we rename to + version with extension. */ char *file_org = strdup(ce->ce_file); ce->ce_file = add (cp, ce->ce_file); if (rename(file_org, ce->ce_file)) { @@ -2293,9 +2301,12 @@ open7Bit (CT ct, char **file) if ((len = ct->c_end - ct->c_begin) < 0) adios (NULL, "internal error(3)"); - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - content_error (ct->c_file, ct, "unable to open for reading"); - return NOTOK; + if (! ct->c_fp) { + if ((ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + content_error (ct->c_file, ct, "unable to open for reading"); + return NOTOK; + } + own_ct_fp = 1; } lseek (fd = fileno (ct->c_fp), (off_t) ct->c_begin, SEEK_SET); @@ -2332,10 +2343,18 @@ open7Bit (CT ct, char **file) ready_to_go: *file = ce->ce_file; + if (own_ct_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } return fileno (ce->ce_fp); clean_up: free_encoding (ct, 0); + if (own_ct_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } return NOTOK; } @@ -2491,10 +2510,8 @@ openFTP (CT ct, char **file) if ((ftp = context_find (nmhaccessftp)) && !*ftp) ftp = NULL; -#ifndef BUILTIN_FTP if (!ftp) return NOTOK; -#endif switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { case NOTOK: @@ -2561,7 +2578,8 @@ openFTP (CT ct, char **file) if (e->eb_flags) { user = "anonymous"; - snprintf (buffer, sizeof(buffer), "%s@%s", getusername (), LocalName ()); + snprintf (buffer, sizeof(buffer), "%s@%s", getusername (), + LocalName (1)); pass = buffer; } else { ruserpass (e->eb_site, &username, &password); @@ -2593,9 +2611,6 @@ openFTP (CT ct, char **file) return NOTOK; } -#ifdef BUILTIN_FTP - if (ftp) -#endif { int child_id, i, vecp; char *vec[9]; @@ -2614,7 +2629,7 @@ openFTP (CT ct, char **file) fflush (stdout); - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: @@ -2631,9 +2646,6 @@ openFTP (CT ct, char **file) default: if (pidXwait (child_id, NULL)) { -#ifdef BUILTIN_FTP -losing_ftp: -#endif username = password = NULL; ce->ce_unlink = 1; return NOTOK; @@ -2641,14 +2653,6 @@ losing_ftp: break; } } -#ifdef BUILTIN_FTP - else - if (ftp_get (e->eb_site, user, pass, e->eb_dir, e->eb_name, - ce->ce_file, - e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii"), 0) - == NOTOK) - goto losing_ftp; -#endif if (cachefile[0]) { if (caching) @@ -2767,7 +2771,7 @@ openMail (CT ct, char **file) vec[vecp++] = e->eb_body; vec[vecp] = NULL; - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: