diff options
Diffstat (limited to 'usr.bin/ftp/fetch.c')
-rw-r--r-- | usr.bin/ftp/fetch.c | 78 |
1 files changed, 43 insertions, 35 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 0c6cdf795d4..6a4592575a5 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.77 2008/06/15 04:43:20 martynas Exp $ */ +/* $OpenBSD: fetch.c,v 1.78 2008/06/25 21:15:19 martynas Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -38,7 +38,7 @@ */ #if !defined(lint) && !defined(SMALL) -static const char rcsid[] = "$OpenBSD: fetch.c,v 1.77 2008/06/15 04:43:20 martynas Exp $"; +static const char rcsid[] = "$OpenBSD: fetch.c,v 1.78 2008/06/25 21:15:19 martynas Exp $"; #endif /* not lint and not SMALL */ /* @@ -74,9 +74,9 @@ static const char rcsid[] = "$OpenBSD: fetch.c,v 1.77 2008/06/15 04:43:20 martyn #ifndef SMALL #include <openssl/ssl.h> #include <openssl/err.h> -#else +#else /* !SMALL */ #define SSL void -#endif +#endif /* !SMALL */ #include "ftp_var.h" @@ -92,7 +92,7 @@ size_t ftp_read(FILE *, SSL *, char *, size_t); int proxy_connect(int, char *); int SSL_vprintf(SSL *, const char *, va_list); char *SSL_readline(SSL *, size_t *); -#endif +#endif /* !SMALL */ #define FTP_URL "ftp://" /* ftp URL prefix */ #define HTTP_URL "http://" /* http URL prefix */ @@ -137,7 +137,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) char *sslpath = NULL, *sslhost = NULL; int ishttpsurl = 0; SSL_CTX *ssl_ctx = NULL; -#endif +#endif /* !SMALL */ SSL *ssl = NULL; int status; @@ -156,7 +156,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) } else if (strncasecmp(newline, HTTPS_URL, sizeof(HTTPS_URL) - 1) == 0) { host = newline + sizeof(HTTPS_URL) - 1; ishttpsurl = 1; -#endif +#endif /* !SMALL */ } else errx(1, "url_get: Invalid URL '%s'", newline); @@ -189,7 +189,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) warnx("can't append to stdout"); goto cleanup_url_get; } -#endif +#endif /* !SMALL */ if (EMPTYSTRING(savefile)) { if (isftpurl) @@ -206,7 +206,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) if (! sslpath || ! sslhost) errx(1, "Can't allocate memory for https path/host."); } -#endif +#endif /* !SMALL */ proxyurl = strdup(proxyenv); if (proxyurl == NULL) errx(1, "Can't allocate memory for proxy URL."); @@ -270,7 +270,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) if (resume) out = open(savefile, O_APPEND | O_WRONLY); else -#endif +#endif /* !SMALL */ out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { @@ -292,7 +292,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) } restart_point = st.st_size; } -#endif +#endif /* !SMALL */ /* Trap signals */ oldintr = NULL; @@ -369,9 +369,9 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) hints.ai_socktype = SOCK_STREAM; #ifndef SMALL port = portnum ? portnum : (ishttpsurl ? httpsport : httpport); -#else +#else /* !SMALL */ port = portnum ? portnum : httpport; -#endif +#endif /* !SMALL */ error = getaddrinfo(host, port, &hints, &res0); /* * If the services file is corrupt/missing, fall back @@ -384,7 +384,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) } else if (error == EAI_SERVICE && port == httpsport) { snprintf(pbuf, sizeof(pbuf), "%d", HTTPS_PORT); error = getaddrinfo(host, pbuf, &hints, &res0); -#endif +#endif /* !SMALL */ } if (error) { warnx("%s: %s", gai_strerror(error), host); @@ -429,7 +429,7 @@ again: #ifndef SMALL if (proxyenv && sslhost) proxy_connect(s, sslhost); -#endif +#endif /* !SMALL */ break; } freeaddrinfo(res0); @@ -465,9 +465,9 @@ again: } else { fin = fdopen(s, "r+"); } -#else +#else /* !SMALL */ fin = fdopen(s, "r+"); -#endif +#endif /* !SMALL */ if (verbose) fprintf(ttyout, "Requesting %s", origline); @@ -476,7 +476,7 @@ again: */ #ifndef SMALL cookie_get(host, path, ishttpsurl, &buf); -#endif +#endif /* !SMALL */ if (proxyurl) { if (verbose) fprintf(ttyout, " (via %s)\n", proxyenv); @@ -496,7 +496,7 @@ again: ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", path, #ifndef SMALL resume ? "HTTP/1.1" : -#endif +#endif /* !SMALL */ "HTTP/1.0"); if (strchr(host, ':')) { char *h, *p; @@ -538,10 +538,10 @@ again: ftp_printf(fin, ssl, "\r\nRange: bytes=%lld-", (long long)restart_point); } -#else +#else /* !SMALL */ if (port && strcmp(port, "80") != 0) ftp_printf(fin, ssl, ":%s", port); -#endif +#endif /* !SMALL */ ftp_printf(fin, ssl, "\r\n%s%s\r\n\r\n", buf ? buf : "", HTTP_USER_AGENT); if (verbose) @@ -551,7 +551,7 @@ again: #ifndef SMALL free(buf); -#endif +#endif /* !SMALL */ buf = NULL; if (fin != NULL && fflush(fin) == EOF) { @@ -586,7 +586,7 @@ again: #ifndef SMALL case 206: /* Partial Content */ break; -#endif +#endif /* !SMALL */ case 301: /* Moved Permanently */ case 302: /* Found */ case 303: /* See Other */ @@ -601,7 +601,7 @@ again: case 416: /* Requested Range Not Satisfiable */ warnx("File is already fully retrieved."); goto cleanup_url_get; -#endif +#endif /* !SMALL */ default: warnx("Error retrieving file: %s", cp); goto cleanup_url_get; @@ -637,7 +637,7 @@ again: #ifndef SMALL if (resume) filesize += restart_point; -#endif +#endif /* !SMALL */ #define LOCATION "Location: " } else if (isredirect && strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) { @@ -662,7 +662,7 @@ again: if (resume) out = open(savefile, O_APPEND | O_WRONLY); else -#endif +#endif /* !SMALL */ out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { @@ -725,7 +725,7 @@ again: if ( #ifndef SMALL !resume && -#endif +#endif /* !SMALL */ filesize != -1 && len == 0 && bytes != filesize) { if (verbose) fputs("Read short file.\n", ttyout); @@ -753,7 +753,7 @@ cleanup_url_get: SSL_shutdown(ssl); SSL_free(ssl); } -#endif +#endif /* !SMALL */ if (fin != NULL) fclose(fin); else if (s != -1) @@ -855,7 +855,7 @@ auto_fetch(int argc, char *argv[], char *outfile) #ifndef SMALL /* even if we compiled without SSL, url_get will check */ strncasecmp(url, HTTPS_URL, sizeof(HTTPS_URL) -1) == 0 || -#endif +#endif /* !SMALL */ strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { redirect_loop = 0; if (url_get(url, httpproxy, outfile) == -1) @@ -1062,6 +1062,14 @@ bad_ftp_url: ointeractive = interactive; interactive = 0; xargv[0] = "mget"; +#ifndef SMALL + if (resume) { + xargc = 3; + xargv[1] = "-c"; + xargv[2] = file; + xargv[3] = NULL; + } +#endif /* !SMALL */ mget(xargc, xargv); interactive = ointeractive; } else { @@ -1074,7 +1082,7 @@ bad_ftp_url: if (resume) reget(xargc, xargv); else -#endif +#endif /* !SMALL */ get(xargc, xargv); } @@ -1148,7 +1156,7 @@ isurl(const char *p) strncasecmp(p, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 || #ifndef SMALL strncasecmp(p, HTTPS_URL, sizeof(HTTPS_URL) - 1) == 0 || -#endif +#endif /* !SMALL */ strncasecmp(p, FILE_URL, sizeof(FILE_URL) - 1) == 0 || strstr(p, ":/")) return (1); @@ -1163,7 +1171,7 @@ ftp_readline(FILE *fp, SSL *ssl, size_t *lenp) #ifndef SMALL else if (ssl != NULL) return SSL_readline(ssl, lenp); -#endif +#endif /* !SMALL */ else return NULL; } @@ -1185,7 +1193,7 @@ ftp_read(FILE *fp, SSL *ssl, char *buf, size_t len) else ret = nr; } -#endif +#endif /* !SMALL */ else ret = 0; return (ret); @@ -1204,7 +1212,7 @@ ftp_printf(FILE *fp, SSL *ssl, const char *fmt, ...) #ifndef SMALL else if (ssl != NULL) ret = SSL_vprintf((SSL*)ssl, fmt, ap); -#endif +#endif /* !SMALL */ else ret = NULL; @@ -1283,4 +1291,4 @@ proxy_connect(int socket, char *host) free(connstr); return(200); } -#endif +#endif /* !SMALL */ |