version 1.16, 1997/09/11 01:55:15 |
version 1.17, 1998/02/17 23:22:54 |
|
|
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
#include <err.h> |
|
#include <libgen.h> |
#include <netdb.h> |
#include <netdb.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <signal.h> |
#include <signal.h> |
|
|
|
|
#include "ftp_var.h" |
#include "ftp_var.h" |
|
|
static int url_get __P((const char *, const char *, int)); |
static int url_get __P((const char *, const char *, const char *)); |
void aborthttp __P((int)); |
void aborthttp __P((int)); |
|
|
|
|
|
|
* Returns -1 on failure, 0 on success |
* Returns -1 on failure, 0 on success |
*/ |
*/ |
static int |
static int |
url_get(origline, proxyenv, fd) |
url_get(origline, proxyenv, outfile) |
const char *origline; |
const char *origline; |
const char *proxyenv; |
const char *proxyenv; |
int fd; |
const char *outfile; |
{ |
{ |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
int i, out, isftpurl; |
int i, out, isftpurl; |
|
|
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
|
|
savefile = strrchr(path, '/'); /* find savefile */ |
if (outfile) |
if (savefile != NULL) |
savefile = outfile; |
savefile++; |
|
else |
else |
savefile = path; |
savefile = basename(path); |
|
|
if (EMPTYSTRING(savefile)) { |
if (EMPTYSTRING(savefile)) { |
if (isftpurl) |
if (isftpurl) |
goto noftpautologin; |
goto noftpautologin; |
|
|
} else |
} else |
filesize = -1; |
filesize = -1; |
|
|
/* Open the output file. */ |
/* Open the output file. */ |
if (fd == -1) { |
if (strcmp(savefile, "-") != 0) { |
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
if (out < 0) { |
if (out < 0) { |
warn("Can't open %s", savefile); |
warn("Can't open %s", savefile); |
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
} else |
} else |
out = fd; |
out = fileno(stdout); |
|
|
/* Trap signals */ |
/* Trap signals */ |
oldintr = NULL; |
oldintr = NULL; |
|
|
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
|
|
close(s); |
close(s); |
if (fd != -1) |
if (out != fileno(stdout)) |
close(out); |
close(out); |
if (proxy) |
if (proxy) |
free(proxy); |
free(proxy); |
|
|
* Otherwise, 0 is returned if all files retrieved successfully. |
* Otherwise, 0 is returned if all files retrieved successfully. |
*/ |
*/ |
int |
int |
auto_fetch(argc, argv, fd) |
auto_fetch(argc, argv, outfile) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
int fd; |
char *outfile; |
{ |
{ |
static char lasthost[MAXHOSTNAMELEN]; |
static char lasthost[MAXHOSTNAMELEN]; |
char *xargv[5]; |
char *xargv[5]; |
|
|
* Try HTTP URL-style arguments first. |
* Try HTTP URL-style arguments first. |
*/ |
*/ |
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { |
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { |
if (url_get(line, httpproxy, fd) == -1) |
if (url_get(line, httpproxy, outfile) == -1) |
rval = argpos + 1; |
rval = argpos + 1; |
continue; |
continue; |
} |
} |
|
|
host = line; |
host = line; |
if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { |
if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { |
if (ftpproxy) { |
if (ftpproxy) { |
if (url_get(line, ftpproxy, fd) == -1) |
if (url_get(line, ftpproxy, outfile) == -1) |
rval = argpos + 1; |
rval = argpos + 1; |
continue; |
continue; |
} |
} |
|
|
mget(xargc, xargv); |
mget(xargc, xargv); |
interactive = ointeractive; |
interactive = ointeractive; |
} else { |
} else { |
if (fd != -1) { |
if (outfile != NULL) { |
xargv[2] = "-"; |
xargv[2] = outfile; |
|
xargv[3] = NULL; |
xargc++; |
xargc++; |
} |
} |
xargv[3] = NULL; |
|
get(xargc, xargv); |
get(xargc, xargv); |
} |
} |
|
|