=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.77 retrieving revision 1.78 diff -c -r1.77 -r1.78 *** src/usr.bin/ftp/fetch.c 2008/06/15 04:43:20 1.77 --- src/usr.bin/ftp/fetch.c 2008/06/25 21:15:19 1.78 *************** *** 1,4 **** ! /* $OpenBSD: fetch.c,v 1.77 2008/06/15 04:43:20 martynas Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- --- 1,4 ---- ! /* $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,44 **** */ #if !defined(lint) && !defined(SMALL) ! static const char rcsid[] = "$OpenBSD: fetch.c,v 1.77 2008/06/15 04:43:20 martynas Exp $"; #endif /* not lint and not SMALL */ /* --- 38,44 ---- */ #if !defined(lint) && !defined(SMALL) ! 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,82 **** #ifndef SMALL #include #include ! #else #define SSL void ! #endif #include "ftp_var.h" --- 74,82 ---- #ifndef SMALL #include #include ! #else /* !SMALL */ #define SSL void ! #endif /* !SMALL */ #include "ftp_var.h" *************** *** 92,98 **** int proxy_connect(int, char *); int SSL_vprintf(SSL *, const char *, va_list); char *SSL_readline(SSL *, size_t *); ! #endif #define FTP_URL "ftp://" /* ftp URL prefix */ #define HTTP_URL "http://" /* http URL prefix */ --- 92,98 ---- int proxy_connect(int, char *); int SSL_vprintf(SSL *, const char *, va_list); char *SSL_readline(SSL *, size_t *); ! #endif /* !SMALL */ #define FTP_URL "ftp://" /* ftp URL prefix */ #define HTTP_URL "http://" /* http URL prefix */ *************** *** 137,143 **** char *sslpath = NULL, *sslhost = NULL; int ishttpsurl = 0; SSL_CTX *ssl_ctx = NULL; ! #endif SSL *ssl = NULL; int status; --- 137,143 ---- char *sslpath = NULL, *sslhost = NULL; int ishttpsurl = 0; SSL_CTX *ssl_ctx = NULL; ! #endif /* !SMALL */ SSL *ssl = NULL; int status; *************** *** 156,162 **** } else if (strncasecmp(newline, HTTPS_URL, sizeof(HTTPS_URL) - 1) == 0) { host = newline + sizeof(HTTPS_URL) - 1; ishttpsurl = 1; ! #endif } else errx(1, "url_get: Invalid URL '%s'", newline); --- 156,162 ---- } else if (strncasecmp(newline, HTTPS_URL, sizeof(HTTPS_URL) - 1) == 0) { host = newline + sizeof(HTTPS_URL) - 1; ishttpsurl = 1; ! #endif /* !SMALL */ } else errx(1, "url_get: Invalid URL '%s'", newline); *************** *** 189,195 **** warnx("can't append to stdout"); goto cleanup_url_get; } ! #endif if (EMPTYSTRING(savefile)) { if (isftpurl) --- 189,195 ---- warnx("can't append to stdout"); goto cleanup_url_get; } ! #endif /* !SMALL */ if (EMPTYSTRING(savefile)) { if (isftpurl) *************** *** 206,212 **** if (! sslpath || ! sslhost) errx(1, "Can't allocate memory for https path/host."); } ! #endif proxyurl = strdup(proxyenv); if (proxyurl == NULL) errx(1, "Can't allocate memory for proxy URL."); --- 206,212 ---- if (! sslpath || ! sslhost) errx(1, "Can't allocate memory for https path/host."); } ! #endif /* !SMALL */ proxyurl = strdup(proxyenv); if (proxyurl == NULL) errx(1, "Can't allocate memory for proxy URL."); *************** *** 270,276 **** if (resume) out = open(savefile, O_APPEND | O_WRONLY); else ! #endif out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { --- 270,276 ---- if (resume) out = open(savefile, O_APPEND | O_WRONLY); else ! #endif /* !SMALL */ out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { *************** *** 292,298 **** } restart_point = st.st_size; } ! #endif /* Trap signals */ oldintr = NULL; --- 292,298 ---- } restart_point = st.st_size; } ! #endif /* !SMALL */ /* Trap signals */ oldintr = NULL; *************** *** 369,377 **** hints.ai_socktype = SOCK_STREAM; #ifndef SMALL port = portnum ? portnum : (ishttpsurl ? httpsport : httpport); ! #else port = portnum ? portnum : httpport; ! #endif error = getaddrinfo(host, port, &hints, &res0); /* * If the services file is corrupt/missing, fall back --- 369,377 ---- hints.ai_socktype = SOCK_STREAM; #ifndef SMALL port = portnum ? portnum : (ishttpsurl ? httpsport : httpport); ! #else /* !SMALL */ port = portnum ? portnum : httpport; ! #endif /* !SMALL */ error = getaddrinfo(host, port, &hints, &res0); /* * If the services file is corrupt/missing, fall back *************** *** 384,390 **** } else if (error == EAI_SERVICE && port == httpsport) { snprintf(pbuf, sizeof(pbuf), "%d", HTTPS_PORT); error = getaddrinfo(host, pbuf, &hints, &res0); ! #endif } if (error) { warnx("%s: %s", gai_strerror(error), host); --- 384,390 ---- } else if (error == EAI_SERVICE && port == httpsport) { snprintf(pbuf, sizeof(pbuf), "%d", HTTPS_PORT); error = getaddrinfo(host, pbuf, &hints, &res0); ! #endif /* !SMALL */ } if (error) { warnx("%s: %s", gai_strerror(error), host); *************** *** 429,435 **** #ifndef SMALL if (proxyenv && sslhost) proxy_connect(s, sslhost); ! #endif break; } freeaddrinfo(res0); --- 429,435 ---- #ifndef SMALL if (proxyenv && sslhost) proxy_connect(s, sslhost); ! #endif /* !SMALL */ break; } freeaddrinfo(res0); *************** *** 465,473 **** } else { fin = fdopen(s, "r+"); } ! #else fin = fdopen(s, "r+"); ! #endif if (verbose) fprintf(ttyout, "Requesting %s", origline); --- 465,473 ---- } else { fin = fdopen(s, "r+"); } ! #else /* !SMALL */ fin = fdopen(s, "r+"); ! #endif /* !SMALL */ if (verbose) fprintf(ttyout, "Requesting %s", origline); *************** *** 476,482 **** */ #ifndef SMALL cookie_get(host, path, ishttpsurl, &buf); ! #endif if (proxyurl) { if (verbose) fprintf(ttyout, " (via %s)\n", proxyenv); --- 476,482 ---- */ #ifndef SMALL cookie_get(host, path, ishttpsurl, &buf); ! #endif /* !SMALL */ if (proxyurl) { if (verbose) fprintf(ttyout, " (via %s)\n", proxyenv); *************** *** 496,502 **** ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", path, #ifndef SMALL resume ? "HTTP/1.1" : ! #endif "HTTP/1.0"); if (strchr(host, ':')) { char *h, *p; --- 496,502 ---- ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", path, #ifndef SMALL resume ? "HTTP/1.1" : ! #endif /* !SMALL */ "HTTP/1.0"); if (strchr(host, ':')) { char *h, *p; *************** *** 538,547 **** ftp_printf(fin, ssl, "\r\nRange: bytes=%lld-", (long long)restart_point); } ! #else if (port && strcmp(port, "80") != 0) ftp_printf(fin, ssl, ":%s", port); ! #endif ftp_printf(fin, ssl, "\r\n%s%s\r\n\r\n", buf ? buf : "", HTTP_USER_AGENT); if (verbose) --- 538,547 ---- ftp_printf(fin, ssl, "\r\nRange: bytes=%lld-", (long long)restart_point); } ! #else /* !SMALL */ if (port && strcmp(port, "80") != 0) ftp_printf(fin, ssl, ":%s", port); ! #endif /* !SMALL */ ftp_printf(fin, ssl, "\r\n%s%s\r\n\r\n", buf ? buf : "", HTTP_USER_AGENT); if (verbose) *************** *** 551,557 **** #ifndef SMALL free(buf); ! #endif buf = NULL; if (fin != NULL && fflush(fin) == EOF) { --- 551,557 ---- #ifndef SMALL free(buf); ! #endif /* !SMALL */ buf = NULL; if (fin != NULL && fflush(fin) == EOF) { *************** *** 586,592 **** #ifndef SMALL case 206: /* Partial Content */ break; ! #endif case 301: /* Moved Permanently */ case 302: /* Found */ case 303: /* See Other */ --- 586,592 ---- #ifndef SMALL case 206: /* Partial Content */ break; ! #endif /* !SMALL */ case 301: /* Moved Permanently */ case 302: /* Found */ case 303: /* See Other */ *************** *** 601,607 **** case 416: /* Requested Range Not Satisfiable */ warnx("File is already fully retrieved."); goto cleanup_url_get; ! #endif default: warnx("Error retrieving file: %s", cp); goto cleanup_url_get; --- 601,607 ---- case 416: /* Requested Range Not Satisfiable */ warnx("File is already fully retrieved."); goto cleanup_url_get; ! #endif /* !SMALL */ default: warnx("Error retrieving file: %s", cp); goto cleanup_url_get; *************** *** 637,643 **** #ifndef SMALL if (resume) filesize += restart_point; ! #endif #define LOCATION "Location: " } else if (isredirect && strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) { --- 637,643 ---- #ifndef SMALL if (resume) filesize += restart_point; ! #endif /* !SMALL */ #define LOCATION "Location: " } else if (isredirect && strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) { *************** *** 662,668 **** if (resume) out = open(savefile, O_APPEND | O_WRONLY); else ! #endif out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { --- 662,668 ---- if (resume) out = open(savefile, O_APPEND | O_WRONLY); else ! #endif /* !SMALL */ out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { *************** *** 725,731 **** if ( #ifndef SMALL !resume && ! #endif filesize != -1 && len == 0 && bytes != filesize) { if (verbose) fputs("Read short file.\n", ttyout); --- 725,731 ---- if ( #ifndef SMALL !resume && ! #endif /* !SMALL */ filesize != -1 && len == 0 && bytes != filesize) { if (verbose) fputs("Read short file.\n", ttyout); *************** *** 753,759 **** SSL_shutdown(ssl); SSL_free(ssl); } ! #endif if (fin != NULL) fclose(fin); else if (s != -1) --- 753,759 ---- SSL_shutdown(ssl); SSL_free(ssl); } ! #endif /* !SMALL */ if (fin != NULL) fclose(fin); else if (s != -1) *************** *** 855,861 **** #ifndef SMALL /* even if we compiled without SSL, url_get will check */ strncasecmp(url, HTTPS_URL, sizeof(HTTPS_URL) -1) == 0 || ! #endif strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { redirect_loop = 0; if (url_get(url, httpproxy, outfile) == -1) --- 855,861 ---- #ifndef SMALL /* even if we compiled without SSL, url_get will check */ strncasecmp(url, HTTPS_URL, sizeof(HTTPS_URL) -1) == 0 || ! #endif /* !SMALL */ strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { redirect_loop = 0; if (url_get(url, httpproxy, outfile) == -1) *************** *** 1062,1067 **** --- 1062,1075 ---- 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,1080 **** if (resume) reget(xargc, xargv); else ! #endif get(xargc, xargv); } --- 1082,1088 ---- if (resume) reget(xargc, xargv); else ! #endif /* !SMALL */ get(xargc, xargv); } *************** *** 1148,1154 **** strncasecmp(p, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 || #ifndef SMALL strncasecmp(p, HTTPS_URL, sizeof(HTTPS_URL) - 1) == 0 || ! #endif strncasecmp(p, FILE_URL, sizeof(FILE_URL) - 1) == 0 || strstr(p, ":/")) return (1); --- 1156,1162 ---- strncasecmp(p, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 || #ifndef SMALL strncasecmp(p, HTTPS_URL, sizeof(HTTPS_URL) - 1) == 0 || ! #endif /* !SMALL */ strncasecmp(p, FILE_URL, sizeof(FILE_URL) - 1) == 0 || strstr(p, ":/")) return (1); *************** *** 1163,1169 **** #ifndef SMALL else if (ssl != NULL) return SSL_readline(ssl, lenp); ! #endif else return NULL; } --- 1171,1177 ---- #ifndef SMALL else if (ssl != NULL) return SSL_readline(ssl, lenp); ! #endif /* !SMALL */ else return NULL; } *************** *** 1185,1191 **** else ret = nr; } ! #endif else ret = 0; return (ret); --- 1193,1199 ---- else ret = nr; } ! #endif /* !SMALL */ else ret = 0; return (ret); *************** *** 1204,1210 **** #ifndef SMALL else if (ssl != NULL) ret = SSL_vprintf((SSL*)ssl, fmt, ap); ! #endif else ret = NULL; --- 1212,1218 ---- #ifndef SMALL else if (ssl != NULL) ret = SSL_vprintf((SSL*)ssl, fmt, ap); ! #endif /* !SMALL */ else ret = NULL; *************** *** 1283,1286 **** free(connstr); return(200); } ! #endif --- 1291,1294 ---- free(connstr); return(200); } ! #endif /* !SMALL */