=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.9 retrieving revision 1.10 diff -c -r1.9 -r1.10 *** src/usr.bin/ftp/fetch.c 1997/04/18 18:56:49 1.9 --- src/usr.bin/ftp/fetch.c 1997/04/23 20:33:06 1.10 *************** *** 1,4 **** ! /* $OpenBSD: fetch.c,v 1.9 1997/04/18 18:56:49 millert Exp $ */ /* $NetBSD: fetch.c,v 1.6 1997/04/14 09:09:19 lukem Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: fetch.c,v 1.10 1997/04/23 20:33:06 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.6 1997/04/14 09:09:19 lukem Exp $ */ /*- *************** *** 38,44 **** */ #ifndef lint ! static char rcsid[] = "$OpenBSD: fetch.c,v 1.9 1997/04/18 18:56:49 millert Exp $"; #endif /* not lint */ /* --- 38,44 ---- */ #ifndef lint ! static char rcsid[] = "$OpenBSD: fetch.c,v 1.10 1997/04/23 20:33:06 deraadt Exp $"; #endif /* not lint */ /* *************** *** 82,90 **** * Returns -1 on failure, 0 on success */ int ! url_get(line, proxyenv) char *line; char *proxyenv; { struct sockaddr_in sin; int i, out, port, s; --- 82,91 ---- * Returns -1 on failure, 0 on success */ int ! url_get(line, proxyenv, fd) char *line; char *proxyenv; + int fd; { struct sockaddr_in sin; int i, out, port, s; *************** *** 145,151 **** *portnum++ = '\0'; if (debug) ! printf("host %s, port %s, path %s, save as %s.\n", host, portnum, path, savefile); memset(&sin, 0, sizeof(sin)); --- 146,152 ---- *portnum++ = '\0'; if (debug) ! fprintf(ttyout, "host %s, port %s, path %s, save as %s.\n", host, portnum, path, savefile); memset(&sin, 0, sizeof(sin)); *************** *** 198,206 **** * status of "200". Proxy requests don't want leading /. */ if (!proxy) ! printf("Requesting %s:%d/%s\n", line, ntohs(port), path); else ! printf("Requesting %s (via %s)\n", line, proxyenv); snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n", proxy ? "" : "/", path); buflen = strlen(buf); --- 199,208 ---- * status of "200". Proxy requests don't want leading /. */ if (!proxy) ! fprintf(ttyout, "Requesting %s:%d/%s\n", line, ntohs(port), ! path); else ! fprintf(ttyout, "Requesting %s (via %s)\n", line, proxyenv); snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n", proxy ? "" : "/", path); buflen = strlen(buf); *************** *** 264,274 **** goto improper; /* Open the output file. */ ! out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); ! if (out < 0) { ! warn("Can't open %s", savefile); ! goto cleanup_url_get; ! } /* Trap signals */ oldintr = NULL; --- 266,279 ---- goto improper; /* Open the output file. */ ! if (fd == -1) { ! out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); ! if (out < 0) { ! warn("Can't open %s", savefile); ! goto cleanup_url_get; ! } ! } else ! out = fd; /* Trap signals */ oldintr = NULL; *************** *** 297,313 **** } if (hash && !progress) { while (bytes >= hashbytes) { ! (void)putchar('#'); hashbytes += mark; } ! (void)fflush(stdout); } } if (hash && !progress && bytes > 0) { if (bytes < mark) ! (void)putchar('#'); ! (void)putchar('\n'); ! (void)fflush(stdout); } if (len != 0) { warn("Reading from socket"); --- 302,318 ---- } if (hash && !progress) { while (bytes >= hashbytes) { ! (void)putc('#', ttyout); hashbytes += mark; } ! (void)fflush(ttyout); } } if (hash && !progress && bytes > 0) { if (bytes < mark) ! (void)putc('#', ttyout); ! (void)putc('\n', ttyout); ! (void)fflush(ttyout); } if (len != 0) { warn("Reading from socket"); *************** *** 315,325 **** } progressmeter(1); if (verbose) ! puts("Successfully retrieved file."); (void)signal(SIGINT, oldintr); close(s); ! close(out); if (proxy) free(proxy); return (0); --- 320,331 ---- } progressmeter(1); if (verbose) ! fputs("Successfully retrieved file.\n", ttyout); (void)signal(SIGINT, oldintr); close(s); ! if (fd != -1) ! close(out); if (proxy) free(proxy); return (0); *************** *** 343,350 **** { alarmtimer(0); ! puts("\nhttp fetch aborted."); ! (void)fflush(stdout); longjmp(httpabort, 1); } --- 349,356 ---- { alarmtimer(0); ! fputs("\nhttp fetch aborted.\n", ttyout); ! (void)fflush(ttyout); longjmp(httpabort, 1); } *************** *** 363,371 **** * Otherwise, 0 is returned if all files retrieved successfully. */ int ! auto_fetch(argc, argv) int argc; char *argv[]; { static char lasthost[MAXHOSTNAMELEN]; char *xargv[5]; --- 369,378 ---- * Otherwise, 0 is returned if all files retrieved successfully. */ int ! auto_fetch(argc, argv, fd) int argc; char *argv[]; + int fd; { static char lasthost[MAXHOSTNAMELEN]; char *xargv[5]; *************** *** 374,380 **** char *ftpproxy, *httpproxy; int rval, xargc, argpos; int dirhasglob, filehasglob; ! char rempath[MAXPATHLEN]; argpos = 0; --- 381,387 ---- char *ftpproxy, *httpproxy; int rval, xargc, argpos; int dirhasglob, filehasglob; ! char rempath[MAXPATHLEN], fakedev[MAXPATHLEN]; argpos = 0; *************** *** 408,414 **** * Try HTTP URL-style arguments first. */ if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { ! if (url_get(line, httpproxy) == -1) rval = argpos + 1; continue; } --- 415,421 ---- * Try HTTP URL-style arguments first. */ if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { ! if (url_get(line, httpproxy, fd) == -1) rval = argpos + 1; continue; } *************** *** 421,427 **** host = line; if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { if (ftpproxy) { ! if (url_get(line, ftpproxy) == -1) rval = argpos + 1; continue; } --- 428,434 ---- host = line; if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { if (ftpproxy) { ! if (url_get(line, ftpproxy, fd) == -1) rval = argpos + 1; continue; } *************** *** 487,493 **** } } if (debug) ! printf("user %s:%s host %s port %s dir %s file %s\n", user, pass, host, portnum, dir, file); /* --- 494,500 ---- } } if (debug) ! fprintf(ttyout, "user %s:%s host %s port %s dir %s file %s\n", user, pass, host, portnum, dir, file); /* *************** *** 562,568 **** } if (!verbose) ! printf("Retrieving %s/%s\n", dir ? dir : "", file); if (dirhasglob) { snprintf(rempath, sizeof(rempath), "%s/%s", dir, file); --- 569,575 ---- } if (!verbose) ! fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "", file); if (dirhasglob) { snprintf(rempath, sizeof(rempath), "%s/%s", dir, file); *************** *** 570,575 **** --- 577,583 ---- } /* Fetch the file(s). */ + xargc = 2; xargv[0] = "get"; xargv[1] = file; xargv[2] = NULL; *************** *** 579,588 **** ointeractive = interactive; interactive = 0; xargv[0] = "mget"; ! mget(2, xargv); interactive = ointeractive; ! } else ! get(2, xargv); if ((code / 100) != COMPLETE) rval = argpos + 1; --- 587,602 ---- ointeractive = interactive; interactive = 0; xargv[0] = "mget"; ! mget(xargc, xargv); interactive = ointeractive; ! } else { ! if (fd != -1) { ! xargv[2] = "-"; ! xargc++; ! } ! xargv[3] = NULL; ! get(xargc, xargv); ! } if ((code / 100) != COMPLETE) rval = argpos + 1;