#include <h/signals.h>
#include <h/md5.h>
#include <errno.h>
-#include <setjmp.h>
#include <signal.h>
#include <h/mts.h>
#include <h/tws.h>
};
-/* 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 */
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;
}
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)) {
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))
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;
}
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;
}
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)) {
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))
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;
}
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;
}
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)) {
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);
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;
}
static int
openFTP (CT ct, char **file)
{
- int cachetype, fd;
- volatile int caching;
+ int cachetype, caching, fd;
int len, buflen;
char *bp, *ftp, *user, *pass;
char buffer[BUFSIZ], cachefile[BUFSIZ];
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);
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:
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: