1998-07-10 08:39:03 +04:00
|
|
|
/* $NetBSD: fetch.c,v 1.23 1998/07/10 04:39:04 thorpej Exp $ */
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason Thorpe and Luke Mewburn.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
1997-08-18 14:20:13 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1997-01-19 17:19:02 +03:00
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-20 13:45:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#ifndef lint
|
1998-07-10 08:39:03 +04:00
|
|
|
__RCSID("$NetBSD: fetch.c,v 1.23 1998/07/10 04:39:04 thorpej Exp $");
|
1997-01-19 17:19:02 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FTP User Program -- Command line file retrieval
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
#include <arpa/ftp.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
1998-06-04 12:28:35 +04:00
|
|
|
#include <errno.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <fcntl.h>
|
1997-03-13 09:23:11 +03:00
|
|
|
#include <signal.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "ftp_var.h"
|
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
static int url_get __P((const char *, const char *, const char *));
|
1997-07-20 13:45:35 +04:00
|
|
|
void aborthttp __P((int));
|
|
|
|
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
#define FTP_URL "ftp://" /* ftp URL prefix */
|
|
|
|
#define HTTP_URL "http://" /* http URL prefix */
|
1997-04-05 07:27:32 +04:00
|
|
|
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */
|
1997-01-19 17:19:02 +03:00
|
|
|
#define HTTP_PROXY "http_proxy" /* env var with http proxy location */
|
|
|
|
|
|
|
|
|
|
|
|
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
jmp_buf httpabort;
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
1997-04-05 07:27:32 +04:00
|
|
|
* Retrieve URL, via the proxy in $proxyvar if necessary.
|
1997-01-19 17:19:02 +03:00
|
|
|
* Modifies the string argument given.
|
|
|
|
* Returns -1 on failure, 0 on success
|
|
|
|
*/
|
1997-07-20 13:45:35 +04:00
|
|
|
static int
|
1998-06-04 12:28:35 +04:00
|
|
|
url_get(origline, proxyenv, outfile)
|
1997-05-23 22:42:36 +04:00
|
|
|
const char *origline;
|
|
|
|
const char *proxyenv;
|
1998-06-04 12:28:35 +04:00
|
|
|
const char *outfile;
|
1997-01-19 17:19:02 +03:00
|
|
|
{
|
|
|
|
struct sockaddr_in sin;
|
1997-07-20 13:45:35 +04:00
|
|
|
int i, out, isftpurl;
|
1998-01-18 17:23:33 +03:00
|
|
|
in_port_t port;
|
1997-07-20 13:45:35 +04:00
|
|
|
volatile int s;
|
1997-07-20 16:49:26 +04:00
|
|
|
size_t len;
|
1997-07-20 13:45:35 +04:00
|
|
|
char c, *cp, *ep, *portnum, *path, buf[4096];
|
|
|
|
const char *savefile;
|
1997-05-23 22:42:36 +04:00
|
|
|
char *line, *proxy, *host;
|
1998-06-04 12:28:35 +04:00
|
|
|
volatile sig_t oldintr, oldintp;
|
1997-01-19 17:19:02 +03:00
|
|
|
off_t hashbytes;
|
1998-06-04 12:28:35 +04:00
|
|
|
struct hostent *hp = NULL;
|
|
|
|
int (*closefunc) __P((FILE *));
|
|
|
|
FILE *fout;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
closefunc = NULL;
|
|
|
|
fout = NULL;
|
1997-01-19 17:19:02 +03:00
|
|
|
s = -1;
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
proxy = NULL;
|
1997-06-29 10:34:50 +04:00
|
|
|
isftpurl = 0;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
#ifdef __GNUC__ /* to shut up gcc warnings */
|
|
|
|
(void)&closefunc;
|
|
|
|
(void)&fout;
|
1997-07-20 13:45:35 +04:00
|
|
|
(void)&proxy;
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)&savefile;
|
1997-07-20 13:45:35 +04:00
|
|
|
#endif
|
|
|
|
|
1997-05-23 22:42:36 +04:00
|
|
|
line = strdup(origline);
|
|
|
|
if (line == NULL)
|
|
|
|
errx(1, "Can't allocate memory to parse URL");
|
1997-04-14 13:09:15 +04:00
|
|
|
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0)
|
1997-04-05 07:27:32 +04:00
|
|
|
host = line + sizeof(HTTP_URL) - 1;
|
1997-06-29 10:34:50 +04:00
|
|
|
else if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
|
1997-04-05 07:27:32 +04:00
|
|
|
host = line + sizeof(FTP_URL) - 1;
|
1997-06-29 10:34:50 +04:00
|
|
|
isftpurl = 1;
|
|
|
|
} else
|
1997-05-23 22:42:36 +04:00
|
|
|
errx(1, "url_get: Invalid URL '%s'", line);
|
1997-04-05 07:27:32 +04:00
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
path = strchr(host, '/'); /* find path */
|
1997-05-23 22:42:36 +04:00
|
|
|
if (EMPTYSTRING(path)) {
|
1997-06-29 10:34:50 +04:00
|
|
|
if (isftpurl)
|
|
|
|
goto noftpautologin;
|
|
|
|
warnx("Invalid URL (no `/' after host): %s", origline);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-05-23 22:42:36 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
*path++ = '\0';
|
1997-05-23 22:42:36 +04:00
|
|
|
if (EMPTYSTRING(path)) {
|
1997-06-29 10:34:50 +04:00
|
|
|
if (isftpurl)
|
|
|
|
goto noftpautologin;
|
|
|
|
warnx("Invalid URL (no file after host): %s", origline);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-05-23 22:42:36 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
if (outfile)
|
|
|
|
savefile = outfile;
|
|
|
|
else {
|
|
|
|
savefile = strrchr(path, '/'); /* find savefile */
|
|
|
|
if (savefile != NULL)
|
|
|
|
savefile++;
|
|
|
|
else
|
|
|
|
savefile = path;
|
|
|
|
}
|
1997-05-23 22:42:36 +04:00
|
|
|
if (EMPTYSTRING(savefile)) {
|
1997-06-29 10:34:50 +04:00
|
|
|
if (isftpurl)
|
|
|
|
goto noftpautologin;
|
|
|
|
warnx("Invalid URL (no file after directory): %s", origline);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-05-23 22:42:36 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (proxyenv != NULL) { /* use proxy */
|
|
|
|
proxy = strdup(proxyenv);
|
1997-01-19 17:19:02 +03:00
|
|
|
if (proxy == NULL)
|
1997-05-23 22:42:36 +04:00
|
|
|
errx(1, "Can't allocate memory for proxy URL.");
|
1997-04-14 13:09:15 +04:00
|
|
|
if (strncasecmp(proxy, HTTP_URL, sizeof(HTTP_URL) - 1) == 0)
|
1997-04-05 07:27:32 +04:00
|
|
|
host = proxy + sizeof(HTTP_URL) - 1;
|
1997-04-14 13:09:15 +04:00
|
|
|
else if (strncasecmp(proxy, FTP_URL, sizeof(FTP_URL) - 1) == 0)
|
1997-04-05 07:27:32 +04:00
|
|
|
host = proxy + sizeof(FTP_URL) - 1;
|
|
|
|
else {
|
1997-05-23 22:42:36 +04:00
|
|
|
warnx("Malformed proxy URL: %s", proxyenv);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
1997-05-23 22:42:36 +04:00
|
|
|
if (EMPTYSTRING(host)) {
|
|
|
|
warnx("Malformed proxy URL: %s", proxyenv);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-05-23 22:42:36 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
*--path = '/'; /* add / back to real path */
|
|
|
|
path = strchr(host, '/'); /* remove trailing / on host */
|
|
|
|
if (! EMPTYSTRING(path))
|
|
|
|
*path++ = '\0';
|
|
|
|
path = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
portnum = strchr(host, ':'); /* find portnum */
|
|
|
|
if (portnum != NULL)
|
|
|
|
*portnum++ = '\0';
|
|
|
|
|
|
|
|
if (debug)
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout, "host %s, port %s, path %s, save as %s.\n",
|
1997-01-19 17:19:02 +03:00
|
|
|
host, portnum, path, savefile);
|
|
|
|
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
|
1998-05-20 04:54:26 +04:00
|
|
|
if (isdigit((unsigned char)host[0])) {
|
1997-01-19 17:19:02 +03:00
|
|
|
if (inet_aton(host, &sin.sin_addr) == 0) {
|
1997-04-14 13:09:15 +04:00
|
|
|
warnx("Invalid IP address: %s", host);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hp = gethostbyname(host);
|
|
|
|
if (hp == NULL) {
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
warnx("%s: %s", host, hstrerror(h_errno));
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
if (hp->h_addrtype != AF_INET) {
|
|
|
|
warnx("%s: not an Internet address?", host);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! EMPTYSTRING(portnum)) {
|
1997-07-20 13:45:35 +04:00
|
|
|
char *ep;
|
|
|
|
long nport;
|
|
|
|
|
|
|
|
nport = strtol(portnum, &ep, 10);
|
1998-01-19 01:09:39 +03:00
|
|
|
if (nport < 1 || nport > MAX_IN_PORT_T || *ep != '\0') {
|
1997-04-14 13:09:15 +04:00
|
|
|
warnx("Invalid port: %s", portnum);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
1998-01-18 17:23:33 +03:00
|
|
|
port = htons((in_port_t)nport);
|
1997-01-19 17:19:02 +03:00
|
|
|
} else
|
|
|
|
port = httpport;
|
|
|
|
sin.sin_port = port;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (s == -1) {
|
1997-05-23 22:42:36 +04:00
|
|
|
warn("Can't create socket");
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-07-10 08:39:03 +04:00
|
|
|
while (xconnect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
|
1998-06-04 12:28:35 +04:00
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
if (hp && hp->h_addr_list[1]) {
|
|
|
|
int oerrno = errno;
|
|
|
|
char *ia;
|
|
|
|
|
|
|
|
ia = inet_ntoa(sin.sin_addr);
|
|
|
|
errno = oerrno;
|
|
|
|
warn("connect to address %s", ia);
|
|
|
|
hp->h_addr_list++;
|
|
|
|
memcpy(&sin.sin_addr, hp->h_addr_list[0],
|
|
|
|
(size_t)hp->h_length);
|
|
|
|
fprintf(ttyout, "Trying %s...\n",
|
|
|
|
inet_ntoa(sin.sin_addr));
|
|
|
|
(void)close(s);
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
warn("socket");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
warn("Can't connect to %s", host);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct and send the request. We're expecting a return
|
|
|
|
* status of "200". Proxy requests don't want leading /.
|
|
|
|
*/
|
1998-06-03 19:50:34 +04:00
|
|
|
if (!proxy) {
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout, "Requesting %s\n", origline);
|
1998-06-03 19:50:34 +04:00
|
|
|
len = snprintf(buf, sizeof(buf),
|
|
|
|
"GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", path, host);
|
|
|
|
} else {
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout, "Requesting %s (via %s)\n", origline, proxyenv);
|
1998-06-03 19:50:34 +04:00
|
|
|
len = snprintf(buf, sizeof(buf), "GET %s HTTP/1.0\r\n\r\n",
|
|
|
|
path);
|
|
|
|
}
|
1997-07-20 16:49:26 +04:00
|
|
|
if (write(s, buf, len) < len) {
|
1997-05-23 22:42:36 +04:00
|
|
|
warn("Writing HTTP request");
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
memset(buf, 0, sizeof(buf));
|
1997-07-20 16:49:26 +04:00
|
|
|
for (cp = buf; cp < buf + sizeof(buf); ) {
|
1997-01-19 17:19:02 +03:00
|
|
|
if (read(s, cp, 1) != 1)
|
|
|
|
goto improper;
|
1997-03-13 09:23:11 +03:00
|
|
|
if (*cp == '\r')
|
|
|
|
continue;
|
1997-01-19 17:19:02 +03:00
|
|
|
if (*cp == '\n')
|
|
|
|
break;
|
1997-07-20 16:49:26 +04:00
|
|
|
cp++;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
1997-07-20 16:49:26 +04:00
|
|
|
buf[sizeof(buf) - 1] = '\0'; /* sanity */
|
1997-01-19 17:19:02 +03:00
|
|
|
cp = strchr(buf, ' ');
|
|
|
|
if (cp == NULL)
|
|
|
|
goto improper;
|
|
|
|
else
|
|
|
|
cp++;
|
|
|
|
if (strncmp(cp, "200", 3)) {
|
|
|
|
warnx("Error retrieving file: %s", cp);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
/* Read the rest of the header. */
|
1997-01-19 17:19:02 +03:00
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
c = '\0';
|
1997-07-20 16:49:26 +04:00
|
|
|
for (cp = buf; cp < buf + sizeof(buf); ) {
|
1997-01-19 17:19:02 +03:00
|
|
|
if (read(s, cp, 1) != 1)
|
|
|
|
goto improper;
|
1997-03-13 09:23:11 +03:00
|
|
|
if (*cp == '\r')
|
|
|
|
continue;
|
1997-01-19 17:19:02 +03:00
|
|
|
if (*cp == '\n' && c == '\n')
|
|
|
|
break;
|
|
|
|
c = *cp;
|
1997-07-20 16:49:26 +04:00
|
|
|
cp++;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
1997-07-20 16:49:26 +04:00
|
|
|
buf[sizeof(buf) - 1] = '\0'; /* sanity */
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
/* Look for the "Content-length: " header. */
|
1997-01-19 17:19:02 +03:00
|
|
|
#define CONTENTLEN "Content-Length: "
|
|
|
|
for (cp = buf; *cp != '\0'; cp++) {
|
|
|
|
if (tolower(*cp) == 'c' &&
|
|
|
|
strncasecmp(cp, CONTENTLEN, sizeof(CONTENTLEN) - 1) == 0)
|
|
|
|
break;
|
|
|
|
}
|
1997-07-20 16:49:26 +04:00
|
|
|
if (*cp != '\0') {
|
|
|
|
cp += sizeof(CONTENTLEN) - 1;
|
|
|
|
ep = strchr(cp, '\n');
|
|
|
|
if (ep == NULL)
|
|
|
|
goto improper;
|
|
|
|
else
|
|
|
|
*ep = '\0';
|
|
|
|
filesize = strtol(cp, &ep, 10);
|
|
|
|
if (filesize < 1 || *ep != '\0')
|
|
|
|
goto improper;
|
|
|
|
} else
|
|
|
|
filesize = -1;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
oldintr = oldintp = NULL;
|
|
|
|
|
|
|
|
/* Open the output file. */
|
|
|
|
if (strcmp(savefile, "-") == 0) {
|
|
|
|
fout = stdout;
|
|
|
|
} else if (*savefile == '|') {
|
|
|
|
oldintp = signal(SIGPIPE, SIG_IGN);
|
|
|
|
fout = popen(savefile + 1, "w");
|
|
|
|
if (fout == NULL) {
|
|
|
|
warn("Can't run %s", savefile + 1);
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
closefunc = pclose;
|
|
|
|
} else {
|
|
|
|
fout = fopen(savefile, "w");
|
|
|
|
if (fout == NULL) {
|
|
|
|
warn("Can't open %s", savefile);
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
closefunc = fclose;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
/* Trap signals */
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (setjmp(httpabort)) {
|
|
|
|
if (oldintr)
|
1997-03-13 09:23:11 +03:00
|
|
|
(void)signal(SIGINT, oldintr);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (oldintp)
|
|
|
|
(void)signal(SIGPIPE, oldintp);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
}
|
|
|
|
oldintr = signal(SIGINT, aborthttp);
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
bytes = 0;
|
|
|
|
hashbytes = mark;
|
|
|
|
progressmeter(-1);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
|
|
|
|
/* Finally, suck down the file. */
|
1997-01-19 17:19:02 +03:00
|
|
|
i = 0;
|
1998-06-04 12:28:35 +04:00
|
|
|
out = fileno(fout);
|
1997-01-19 17:19:02 +03:00
|
|
|
while ((len = read(s, buf, sizeof(buf))) > 0) {
|
|
|
|
bytes += len;
|
|
|
|
for (cp = buf; len > 0; len -= i, cp += i) {
|
|
|
|
if ((i = write(out, cp, len)) == -1) {
|
|
|
|
warn("Writing %s", savefile);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
else if (i == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (hash && !progress) {
|
|
|
|
while (bytes >= hashbytes) {
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)putc('#', ttyout);
|
1997-01-19 17:19:02 +03:00
|
|
|
hashbytes += mark;
|
|
|
|
}
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)fflush(ttyout);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hash && !progress && bytes > 0) {
|
|
|
|
if (bytes < mark)
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)putc('#', ttyout);
|
|
|
|
(void)putc('\n', ttyout);
|
|
|
|
(void)fflush(ttyout);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
if (len != 0) {
|
|
|
|
warn("Reading from socket");
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
progressmeter(1);
|
|
|
|
if (verbose)
|
1998-06-04 12:28:35 +04:00
|
|
|
fputs("Successfully retrieved file.\n", ttyout);
|
1997-03-13 09:23:11 +03:00
|
|
|
(void)signal(SIGINT, oldintr);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (oldintp)
|
|
|
|
(void)signal(SIGPIPE, oldintp);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-10 08:39:03 +04:00
|
|
|
resetsockbufsize();
|
1997-01-19 17:19:02 +03:00
|
|
|
close(s);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (closefunc != NULL)
|
|
|
|
(*closefunc)(fout);
|
1997-01-19 17:19:02 +03:00
|
|
|
if (proxy)
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
free(proxy);
|
1997-05-23 22:54:18 +04:00
|
|
|
free(line);
|
1997-03-13 09:23:11 +03:00
|
|
|
return (0);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1997-06-29 10:34:50 +04:00
|
|
|
noftpautologin:
|
|
|
|
warnx(
|
|
|
|
"Auto-login using ftp URLs isn't supported when using $ftp_proxy");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
improper:
|
1997-04-14 13:09:15 +04:00
|
|
|
warnx("Improper response from %s", host);
|
1997-06-29 10:34:50 +04:00
|
|
|
|
1997-04-05 07:27:32 +04:00
|
|
|
cleanup_url_get:
|
1998-07-10 08:39:03 +04:00
|
|
|
resetsockbufsize();
|
1997-01-19 17:19:02 +03:00
|
|
|
if (s != -1)
|
|
|
|
close(s);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (closefunc != NULL && fout != NULL)
|
|
|
|
(*closefunc)(fout);
|
1997-01-19 17:19:02 +03:00
|
|
|
if (proxy)
|
|
|
|
free(proxy);
|
1997-05-23 22:54:18 +04:00
|
|
|
free(line);
|
1997-03-13 09:23:11 +03:00
|
|
|
return (-1);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
/*
|
|
|
|
* Abort a http retrieval
|
|
|
|
*/
|
|
|
|
void
|
1997-03-13 09:23:11 +03:00
|
|
|
aborthttp(notused)
|
|
|
|
int notused;
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
alarmtimer(0);
|
1998-06-04 12:28:35 +04:00
|
|
|
fputs("\nhttp fetch aborted.\n", ttyout);
|
|
|
|
(void)fflush(ttyout);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
longjmp(httpabort, 1);
|
|
|
|
}
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
|
|
|
* Retrieve multiple files from the command line, transferring
|
|
|
|
* files of the form "host:path", "ftp://host/path" using the
|
|
|
|
* ftp protocol, and files of the form "http://host/path" using
|
|
|
|
* the http protocol.
|
1997-03-13 09:23:11 +03:00
|
|
|
* If path has a trailing "/", then return (-1);
|
1997-01-19 17:19:02 +03:00
|
|
|
* the path will be cd-ed into and the connection remains open,
|
|
|
|
* and the function will return -1 (to indicate the connection
|
|
|
|
* is alive).
|
|
|
|
* If an error occurs the return value will be the offset+1 in
|
|
|
|
* argv[] of the file that caused a problem (i.e, argv[x]
|
|
|
|
* returns x+1)
|
|
|
|
* Otherwise, 0 is returned if all files retrieved successfully.
|
|
|
|
*/
|
|
|
|
int
|
1998-06-04 12:28:35 +04:00
|
|
|
auto_fetch(argc, argv, outfile)
|
1997-01-19 17:19:02 +03:00
|
|
|
int argc;
|
|
|
|
char *argv[];
|
1998-06-04 12:28:35 +04:00
|
|
|
char *outfile;
|
1997-01-19 17:19:02 +03:00
|
|
|
{
|
|
|
|
static char lasthost[MAXHOSTNAMELEN];
|
|
|
|
char *xargv[5];
|
|
|
|
char *cp, *line, *host, *dir, *file, *portnum;
|
1997-04-14 13:09:15 +04:00
|
|
|
char *user, *pass;
|
1997-04-05 07:27:32 +04:00
|
|
|
char *ftpproxy, *httpproxy;
|
1997-07-20 13:45:35 +04:00
|
|
|
int rval, xargc;
|
|
|
|
volatile int argpos;
|
1997-03-13 09:23:11 +03:00
|
|
|
int dirhasglob, filehasglob;
|
|
|
|
char rempath[MAXPATHLEN];
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
#ifdef __GNUC__ /* to shut up gcc warnings */
|
|
|
|
(void)&outfile;
|
|
|
|
#endif
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
argpos = 0;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (setjmp(toplevel)) {
|
|
|
|
if (connected)
|
|
|
|
disconnect(0, NULL);
|
1997-03-13 09:23:11 +03:00
|
|
|
return (argpos + 1);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
}
|
1997-03-13 09:23:11 +03:00
|
|
|
(void)signal(SIGINT, (sig_t)intr);
|
|
|
|
(void)signal(SIGPIPE, (sig_t)lostpeer);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1997-04-05 07:27:32 +04:00
|
|
|
ftpproxy = getenv(FTP_PROXY);
|
|
|
|
httpproxy = getenv(HTTP_PROXY);
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
|
|
|
* Loop through as long as there's files to fetch.
|
|
|
|
*/
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
for (rval = 0; (rval == 0) && (argpos < argc); free(line), argpos++) {
|
1997-01-19 17:19:02 +03:00
|
|
|
if (strchr(argv[argpos], ':') == NULL)
|
|
|
|
break;
|
1997-04-14 13:09:15 +04:00
|
|
|
host = dir = file = portnum = user = pass = NULL;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We muck with the string, so we make a copy.
|
|
|
|
*/
|
|
|
|
line = strdup(argv[argpos]);
|
|
|
|
if (line == NULL)
|
|
|
|
errx(1, "Can't allocate memory for auto-fetch.");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try HTTP URL-style arguments first.
|
|
|
|
*/
|
1997-04-14 13:09:15 +04:00
|
|
|
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
|
1998-06-04 12:28:35 +04:00
|
|
|
if (url_get(line, httpproxy, outfile) == -1)
|
1997-01-19 17:19:02 +03:00
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-04-05 07:27:32 +04:00
|
|
|
* Try FTP URL-style arguments next. If ftpproxy is
|
|
|
|
* set, use url_get() instead of standard ftp.
|
|
|
|
* Finally, try host:file.
|
1997-01-19 17:19:02 +03:00
|
|
|
*/
|
|
|
|
host = line;
|
1997-04-14 13:09:15 +04:00
|
|
|
if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
|
1997-04-05 07:27:32 +04:00
|
|
|
if (ftpproxy) {
|
1998-06-04 12:28:35 +04:00
|
|
|
if (url_get(line, ftpproxy, outfile) == -1)
|
1997-04-05 07:27:32 +04:00
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
host += sizeof(FTP_URL) - 1;
|
1997-04-14 13:09:15 +04:00
|
|
|
dir = strchr(host, '/');
|
|
|
|
|
|
|
|
/* look for [user:pass@]host[:port] */
|
1997-04-21 22:41:03 +04:00
|
|
|
pass = strpbrk(host, ":@/");
|
|
|
|
if (pass == NULL || *pass == '/') {
|
|
|
|
pass = NULL;
|
1997-04-14 13:09:15 +04:00
|
|
|
goto parsed_url;
|
1997-04-21 22:41:03 +04:00
|
|
|
}
|
|
|
|
if (pass == host || *pass == '@') {
|
1997-04-21 22:45:47 +04:00
|
|
|
bad_ftp_url:
|
1997-05-23 22:42:36 +04:00
|
|
|
warnx("Invalid URL: %s", argv[argpos]);
|
1997-04-14 13:09:15 +04:00
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*pass++ = '\0';
|
|
|
|
cp = strpbrk(pass, ":@/");
|
|
|
|
if (cp == NULL || *cp == '/') {
|
|
|
|
portnum = pass;
|
1997-04-21 22:41:03 +04:00
|
|
|
pass = NULL;
|
1997-04-14 13:09:15 +04:00
|
|
|
goto parsed_url;
|
|
|
|
}
|
1997-04-21 22:41:03 +04:00
|
|
|
if (EMPTYSTRING(cp) || *cp == ':')
|
1997-04-21 22:45:47 +04:00
|
|
|
goto bad_ftp_url;
|
1997-04-14 13:09:15 +04:00
|
|
|
*cp++ = '\0';
|
1997-04-21 22:41:03 +04:00
|
|
|
user = host;
|
|
|
|
if (EMPTYSTRING(user))
|
1997-04-21 22:45:47 +04:00
|
|
|
goto bad_ftp_url;
|
1997-04-14 13:09:15 +04:00
|
|
|
host = cp;
|
1997-01-19 17:19:02 +03:00
|
|
|
portnum = strchr(host, ':');
|
|
|
|
if (portnum != NULL)
|
|
|
|
*portnum++ = '\0';
|
1997-04-14 13:09:15 +04:00
|
|
|
} else { /* classic style `host:file' */
|
|
|
|
dir = strchr(host, ':');
|
|
|
|
}
|
1997-09-21 05:06:30 +04:00
|
|
|
parsed_url:
|
1997-01-19 17:19:02 +03:00
|
|
|
if (EMPTYSTRING(host)) {
|
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-13 13:05:52 +04:00
|
|
|
* If dir is NULL, the file wasn't specified
|
1997-01-19 17:19:02 +03:00
|
|
|
* (URL looked something like ftp://host)
|
|
|
|
*/
|
1997-04-14 13:09:15 +04:00
|
|
|
if (dir != NULL)
|
|
|
|
*dir++ = '\0';
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the file and (if present) directory name.
|
|
|
|
*/
|
|
|
|
if (! EMPTYSTRING(dir)) {
|
1997-04-14 13:09:15 +04:00
|
|
|
cp = strrchr(dir, '/');
|
1997-01-19 17:19:02 +03:00
|
|
|
if (cp != NULL) {
|
|
|
|
*cp++ = '\0';
|
|
|
|
file = cp;
|
|
|
|
} else {
|
|
|
|
file = dir;
|
|
|
|
dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (debug)
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout,
|
|
|
|
"user %s:%s host %s port %s dir %s file %s\n",
|
1997-04-14 13:09:15 +04:00
|
|
|
user, pass, host, portnum, dir, file);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the connection if we don't have one.
|
|
|
|
*/
|
|
|
|
if (strcmp(host, lasthost) != 0) {
|
1997-04-14 13:09:15 +04:00
|
|
|
int oautologin;
|
|
|
|
|
1997-03-16 17:24:14 +03:00
|
|
|
(void)strcpy(lasthost, host);
|
1997-01-19 17:19:02 +03:00
|
|
|
if (connected)
|
|
|
|
disconnect(0, NULL);
|
|
|
|
xargv[0] = __progname;
|
|
|
|
xargv[1] = host;
|
|
|
|
xargv[2] = NULL;
|
|
|
|
xargc = 2;
|
1997-04-14 13:09:15 +04:00
|
|
|
if (! EMPTYSTRING(portnum)) {
|
1997-01-19 17:19:02 +03:00
|
|
|
xargv[2] = portnum;
|
|
|
|
xargv[3] = NULL;
|
|
|
|
xargc = 3;
|
|
|
|
}
|
1997-04-14 13:09:15 +04:00
|
|
|
oautologin = autologin;
|
|
|
|
if (user != NULL)
|
|
|
|
autologin = 0;
|
1997-01-19 17:19:02 +03:00
|
|
|
setpeer(xargc, xargv);
|
1997-04-14 13:09:15 +04:00
|
|
|
autologin = oautologin;
|
|
|
|
if ((connected == 0)
|
|
|
|
|| ((connected == 1) && !login(host, user, pass)) ) {
|
|
|
|
warnx("Can't connect or login to host `%s'",
|
|
|
|
host);
|
1997-01-19 17:19:02 +03:00
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always use binary transfers. */
|
|
|
|
setbinary(0, NULL);
|
|
|
|
}
|
1997-04-14 13:09:15 +04:00
|
|
|
/* cd back to '/' */
|
|
|
|
xargv[0] = "cd";
|
|
|
|
xargv[1] = "/";
|
|
|
|
xargv[2] = NULL;
|
|
|
|
cd(2, xargv);
|
|
|
|
if (! dirchange) {
|
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1997-03-13 09:23:11 +03:00
|
|
|
dirhasglob = filehasglob = 0;
|
|
|
|
if (doglob) {
|
|
|
|
if (! EMPTYSTRING(dir) &&
|
|
|
|
strpbrk(dir, "*?[]{}") != NULL)
|
|
|
|
dirhasglob = 1;
|
|
|
|
if (! EMPTYSTRING(file) &&
|
|
|
|
strpbrk(file, "*?[]{}") != NULL)
|
|
|
|
filehasglob = 1;
|
|
|
|
}
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/* Change directories, if necessary. */
|
1997-03-13 09:23:11 +03:00
|
|
|
if (! EMPTYSTRING(dir) && !dirhasglob) {
|
1997-01-19 17:19:02 +03:00
|
|
|
xargv[0] = "cd";
|
|
|
|
xargv[1] = dir;
|
|
|
|
xargv[2] = NULL;
|
|
|
|
cd(2, xargv);
|
|
|
|
if (! dirchange) {
|
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EMPTYSTRING(file)) {
|
|
|
|
rval = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (!verbose)
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "",
|
|
|
|
file);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
|
1997-03-13 09:23:11 +03:00
|
|
|
if (dirhasglob) {
|
|
|
|
snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);
|
|
|
|
file = rempath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch the file(s). */
|
1998-06-04 12:28:35 +04:00
|
|
|
xargc = 2;
|
1997-01-19 17:19:02 +03:00
|
|
|
xargv[0] = "get";
|
|
|
|
xargv[1] = file;
|
|
|
|
xargv[2] = NULL;
|
1997-03-13 09:23:11 +03:00
|
|
|
if (dirhasglob || filehasglob) {
|
|
|
|
int ointeractive;
|
|
|
|
|
|
|
|
ointeractive = interactive;
|
|
|
|
interactive = 0;
|
|
|
|
xargv[0] = "mget";
|
1998-06-04 12:28:35 +04:00
|
|
|
mget(xargc, xargv);
|
1997-03-16 17:24:14 +03:00
|
|
|
interactive = ointeractive;
|
1998-06-04 12:28:35 +04:00
|
|
|
} else {
|
|
|
|
if (outfile != NULL) {
|
|
|
|
xargv[2] = outfile;
|
|
|
|
xargv[3] = NULL;
|
|
|
|
xargc++;
|
|
|
|
}
|
|
|
|
get(xargc, xargv);
|
|
|
|
if (outfile != NULL && strcmp(outfile, "-") != 0
|
|
|
|
&& outfile[0] != '|')
|
|
|
|
outfile = NULL;
|
|
|
|
}
|
1997-03-13 09:23:11 +03:00
|
|
|
|
|
|
|
if ((code / 100) != COMPLETE)
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
rval = argpos + 1;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
if (connected && rval != -1)
|
|
|
|
disconnect(0, NULL);
|
|
|
|
return (rval);
|
|
|
|
}
|