version 1.74, 2007/06/13 13:52:26 |
version 1.75, 2007/11/26 12:39:00 |
|
|
else |
else |
savefile = basename(path); |
savefile = basename(path); |
|
|
|
#ifndef SMALL |
|
if (resume && (strcmp(savefile, "-") == 0)) { |
|
warnx("can't append to stdout"); |
|
goto cleanup_url_get; |
|
} |
|
#endif |
|
|
if (EMPTYSTRING(savefile)) { |
if (EMPTYSTRING(savefile)) { |
if (isftpurl) |
if (isftpurl) |
goto noftpautologin; |
goto noftpautologin; |
|
|
|
|
/* Open the output file. */ |
/* Open the output file. */ |
if (strcmp(savefile, "-") != 0) { |
if (strcmp(savefile, "-") != 0) { |
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, |
#ifndef SMALL |
0666); |
if (resume) |
|
out = open(savefile, O_APPEND | O_WRONLY); |
|
else |
|
#endif |
|
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 = fileno(stdout); |
out = fileno(stdout); |
|
|
|
#ifndef SMALL |
|
if (resume) { |
|
if (fstat(out, &st) == -1) { |
|
warn("Can't fstat %s", savefile); |
|
goto cleanup_url_get; |
|
} |
|
if (lseek(s, st.st_size, SEEK_SET) == -1) { |
|
warn("Can't lseek %s", path); |
|
goto cleanup_url_get; |
|
} |
|
restart_point = st.st_size; |
|
} |
|
#endif |
|
|
/* Trap signals */ |
/* Trap signals */ |
oldintr = NULL; |
oldintr = NULL; |
if (setjmp(httpabort)) { |
if (setjmp(httpabort)) { |
|
|
path, buf ? buf : "", HTTP_USER_AGENT); |
path, buf ? buf : "", HTTP_USER_AGENT); |
|
|
} else { |
} else { |
ftp_printf(fin, ssl, "GET /%s HTTP/1.0\r\nHost: ", path); |
ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", path, |
|
#ifndef SMALL |
|
resume ? "HTTP/1.1" : |
|
#endif |
|
"HTTP/1.0"); |
if (strchr(host, ':')) { |
if (strchr(host, ':')) { |
char *h, *p; |
char *h, *p; |
|
|
|
|
#ifndef SMALL |
#ifndef SMALL |
if (port && strcmp(port, (ishttpsurl ? "443" : "80")) != 0) |
if (port && strcmp(port, (ishttpsurl ? "443" : "80")) != 0) |
ftp_printf(fin, ssl, ":%s", port); |
ftp_printf(fin, ssl, ":%s", port); |
|
if (resume) { |
|
int ret; |
|
struct stat stbuf; |
|
|
|
ret = stat(savefile, &stbuf); |
|
if (ret < 0) { |
|
if (verbose) |
|
fprintf(ttyout, "\n"); |
|
warn("Can't open %s", savefile); |
|
goto cleanup_url_get; |
|
} |
|
restart_point = stbuf.st_size; |
|
ftp_printf(fin, ssl, "\r\nRange: bytes=%lld-", |
|
(long long)restart_point); |
|
} |
#else |
#else |
if (port && strcmp(port, "80") != 0) |
if (port && strcmp(port, "80") != 0) |
ftp_printf(fin, ssl, ":%s", port); |
ftp_printf(fin, ssl, ":%s", port); |
|
|
cp++; |
cp++; |
|
|
strlcpy(ststr, cp, sizeof(ststr)); |
strlcpy(ststr, cp, sizeof(ststr)); |
status = strtonum(ststr, 200, 307, &errstr); |
status = strtonum(ststr, 200, 416, &errstr); |
if (errstr) { |
if (errstr) { |
warnx("Error retrieving file: %s", cp); |
warnx("Error retrieving file: %s", cp); |
goto cleanup_url_get; |
goto cleanup_url_get; |
|
|
|
|
switch (status) { |
switch (status) { |
case 200: /* OK */ |
case 200: /* OK */ |
|
#ifndef SMALL |
|
case 206: /* Partial Content */ |
break; |
break; |
|
#endif |
case 301: /* Moved Permanently */ |
case 301: /* Moved Permanently */ |
case 302: /* Found */ |
case 302: /* Found */ |
case 303: /* See Other */ |
case 303: /* See Other */ |
|
|
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
break; |
break; |
|
#ifndef SMALL |
|
case 416: /* Requested Range Not Satisfiable */ |
|
warnx("File is already fully retrieved."); |
|
goto cleanup_url_get; |
|
#endif |
default: |
default: |
warnx("Error retrieving file: %s", cp); |
warnx("Error retrieving file: %s", cp); |
goto cleanup_url_get; |
goto cleanup_url_get; |
|
|
filesize = strtonum(cp, 0, LLONG_MAX, &errstr); |
filesize = strtonum(cp, 0, LLONG_MAX, &errstr); |
if (errstr != NULL) |
if (errstr != NULL) |
goto improper; |
goto improper; |
|
#ifndef SMALL |
|
if (resume) |
|
filesize += restart_point; |
|
#endif |
#define LOCATION "Location: " |
#define LOCATION "Location: " |
} else if (isredirect && |
} else if (isredirect && |
strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) { |
strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) { |
|
|
|
|
/* Open the output file. */ |
/* Open the output file. */ |
if (strcmp(savefile, "-") != 0) { |
if (strcmp(savefile, "-") != 0) { |
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
#ifndef SMALL |
|
if (resume) |
|
out = open(savefile, O_APPEND | O_WRONLY); |
|
else |
|
#endif |
|
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; |
|
|
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
progressmeter(1); |
progressmeter(1); |
if (filesize != -1 && len == 0 && bytes != filesize) { |
if ( |
|
#ifndef SMALL |
|
!resume && |
|
#endif |
|
filesize != -1 && len == 0 && bytes != filesize) { |
if (verbose) |
if (verbose) |
fputs("Read short file.\n", ttyout); |
fputs("Read short file.\n", ttyout); |
goto cleanup_url_get; |
goto cleanup_url_get; |
|
|
xargv[3] = NULL; |
xargv[3] = NULL; |
xargc++; |
xargc++; |
} |
} |
get(xargc, xargv); |
#ifndef SMALL |
|
if (resume) |
|
reget(xargc, xargv); |
|
else |
|
#endif |
|
get(xargc, xargv); |
} |
} |
|
|
if ((code / 100) != COMPLETE) |
if ((code / 100) != COMPLETE) |