version 1.9, 1997/04/18 18:56:49 |
version 1.10, 1997/04/23 20:33:06 |
|
|
* Returns -1 on failure, 0 on success |
* Returns -1 on failure, 0 on success |
*/ |
*/ |
int |
int |
url_get(line, proxyenv) |
url_get(line, proxyenv, fd) |
char *line; |
char *line; |
char *proxyenv; |
char *proxyenv; |
|
int fd; |
{ |
{ |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
int i, out, port, s; |
int i, out, port, s; |
|
|
*portnum++ = '\0'; |
*portnum++ = '\0'; |
|
|
if (debug) |
if (debug) |
printf("host %s, port %s, path %s, save as %s.\n", |
fprintf(ttyout, "host %s, port %s, path %s, save as %s.\n", |
host, portnum, path, savefile); |
host, portnum, path, savefile); |
|
|
memset(&sin, 0, sizeof(sin)); |
memset(&sin, 0, sizeof(sin)); |
|
|
* status of "200". Proxy requests don't want leading /. |
* status of "200". Proxy requests don't want leading /. |
*/ |
*/ |
if (!proxy) |
if (!proxy) |
printf("Requesting %s:%d/%s\n", line, ntohs(port), path); |
fprintf(ttyout, "Requesting %s:%d/%s\n", line, ntohs(port), |
|
path); |
else |
else |
printf("Requesting %s (via %s)\n", line, proxyenv); |
fprintf(ttyout, "Requesting %s (via %s)\n", line, proxyenv); |
snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n", |
snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n", |
proxy ? "" : "/", path); |
proxy ? "" : "/", path); |
buflen = strlen(buf); |
buflen = strlen(buf); |
|
|
goto improper; |
goto improper; |
|
|
/* Open the output file. */ |
/* Open the output file. */ |
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
if (fd == -1) { |
if (out < 0) { |
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
warn("Can't open %s", savefile); |
if (out < 0) { |
goto cleanup_url_get; |
warn("Can't open %s", savefile); |
} |
goto cleanup_url_get; |
|
} |
|
} else |
|
out = fd; |
|
|
/* Trap signals */ |
/* Trap signals */ |
oldintr = NULL; |
oldintr = NULL; |
|
|
} |
} |
if (hash && !progress) { |
if (hash && !progress) { |
while (bytes >= hashbytes) { |
while (bytes >= hashbytes) { |
(void)putchar('#'); |
(void)putc('#', ttyout); |
hashbytes += mark; |
hashbytes += mark; |
} |
} |
(void)fflush(stdout); |
(void)fflush(ttyout); |
} |
} |
} |
} |
if (hash && !progress && bytes > 0) { |
if (hash && !progress && bytes > 0) { |
if (bytes < mark) |
if (bytes < mark) |
(void)putchar('#'); |
(void)putc('#', ttyout); |
(void)putchar('\n'); |
(void)putc('\n', ttyout); |
(void)fflush(stdout); |
(void)fflush(ttyout); |
} |
} |
if (len != 0) { |
if (len != 0) { |
warn("Reading from socket"); |
warn("Reading from socket"); |
|
|
} |
} |
progressmeter(1); |
progressmeter(1); |
if (verbose) |
if (verbose) |
puts("Successfully retrieved file."); |
fputs("Successfully retrieved file.\n", ttyout); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
|
|
close(s); |
close(s); |
close(out); |
if (fd != -1) |
|
close(out); |
if (proxy) |
if (proxy) |
free(proxy); |
free(proxy); |
return (0); |
return (0); |
|
|
{ |
{ |
|
|
alarmtimer(0); |
alarmtimer(0); |
puts("\nhttp fetch aborted."); |
fputs("\nhttp fetch aborted.\n", ttyout); |
(void)fflush(stdout); |
(void)fflush(ttyout); |
longjmp(httpabort, 1); |
longjmp(httpabort, 1); |
} |
} |
|
|
|
|
* Otherwise, 0 is returned if all files retrieved successfully. |
* Otherwise, 0 is returned if all files retrieved successfully. |
*/ |
*/ |
int |
int |
auto_fetch(argc, argv) |
auto_fetch(argc, argv, fd) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
|
int fd; |
{ |
{ |
static char lasthost[MAXHOSTNAMELEN]; |
static char lasthost[MAXHOSTNAMELEN]; |
char *xargv[5]; |
char *xargv[5]; |
|
|
char *ftpproxy, *httpproxy; |
char *ftpproxy, *httpproxy; |
int rval, xargc, argpos; |
int rval, xargc, argpos; |
int dirhasglob, filehasglob; |
int dirhasglob, filehasglob; |
char rempath[MAXPATHLEN]; |
char rempath[MAXPATHLEN], fakedev[MAXPATHLEN]; |
|
|
argpos = 0; |
argpos = 0; |
|
|
|
|
* 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) == -1) |
if (url_get(line, httpproxy, fd) == -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) == -1) |
if (url_get(line, ftpproxy, fd) == -1) |
rval = argpos + 1; |
rval = argpos + 1; |
continue; |
continue; |
} |
} |
|
|
} |
} |
} |
} |
if (debug) |
if (debug) |
printf("user %s:%s host %s port %s dir %s file %s\n", |
fprintf(ttyout, "user %s:%s host %s port %s dir %s file %s\n", |
user, pass, host, portnum, dir, file); |
user, pass, host, portnum, dir, file); |
|
|
/* |
/* |
|
|
} |
} |
|
|
if (!verbose) |
if (!verbose) |
printf("Retrieving %s/%s\n", dir ? dir : "", file); |
fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "", file); |
|
|
if (dirhasglob) { |
if (dirhasglob) { |
snprintf(rempath, sizeof(rempath), "%s/%s", dir, file); |
snprintf(rempath, sizeof(rempath), "%s/%s", dir, file); |
|
|
} |
} |
|
|
/* Fetch the file(s). */ |
/* Fetch the file(s). */ |
|
xargc = 2; |
xargv[0] = "get"; |
xargv[0] = "get"; |
xargv[1] = file; |
xargv[1] = file; |
xargv[2] = NULL; |
xargv[2] = NULL; |
|
|
ointeractive = interactive; |
ointeractive = interactive; |
interactive = 0; |
interactive = 0; |
xargv[0] = "mget"; |
xargv[0] = "mget"; |
mget(2, xargv); |
mget(xargc, xargv); |
interactive = ointeractive; |
interactive = ointeractive; |
} else |
} else { |
get(2, xargv); |
if (fd != -1) { |
|
xargv[2] = "-"; |
|
xargc++; |
|
} |
|
xargv[3] = NULL; |
|
get(xargc, xargv); |
|
} |
|
|
if ((code / 100) != COMPLETE) |
if ((code / 100) != COMPLETE) |
rval = argpos + 1; |
rval = argpos + 1; |