* support $ftp_proxy for ftp:// transfers [bin/3245]

* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
  only setup setup terminal if going into interactive mode. inspired
  by Todd Miller <todd.miller@courtesan.com>
This commit is contained in:
lukem 1997-04-05 03:27:32 +00:00
parent 0d321a7e29
commit d473547d56
7 changed files with 123 additions and 69 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.21 1997/03/16 14:24:14 lukem Exp $ */
/* $NetBSD: cmds.c,v 1.22 1997/04/05 03:27:32 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
static char rcsid[] = "$NetBSD: cmds.c,v 1.21 1997/03/16 14:24:14 lukem Exp $";
static char rcsid[] = "$NetBSD: cmds.c,v 1.22 1997/04/05 03:27:32 lukem Exp $";
#endif
#endif /* not lint */
@ -730,6 +730,7 @@ setedit(argc, argv)
{
code = togglevar(argc, argv, &editing, "Editing mode");
controlediting();
}
#endif /* !SMALL */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmdtab.c,v 1.14 1997/03/14 01:39:34 christos Exp $ */
/* $NetBSD: cmdtab.c,v 1.15 1997/04/05 03:27:33 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
static char rcsid[] = "$NetBSD: cmdtab.c,v 1.14 1997/03/14 01:39:34 christos Exp $";
static char rcsid[] = "$NetBSD: cmdtab.c,v 1.15 1997/04/05 03:27:33 lukem Exp $";
#endif
#endif /* not lint */
@ -165,6 +165,7 @@ struct cmd cmdtab[] = {
{ "idle", idlehelp, 0, 1, 1, CMPL0 idle },
{ "image", binaryhelp, 0, 1, 1, CMPL0 setbinary },
{ "lcd", lcdhelp, 0, 0, 0, CMPL(l) lcd },
{ "less", pagehelp, 1, 1, 1, CMPL(r) page },
{ "lpwd", lpwdhelp, 0, 0, 0, CMPL0 lpwd },
{ "ls", lshelp, 1, 1, 1, CMPL(rl) ls },
{ "macdef", macdefhelp, 0, 0, 0, CMPL0 macdef },
@ -175,6 +176,7 @@ struct cmd cmdtab[] = {
{ "mls", mlshelp, 1, 1, 1, CMPL(R) mls },
{ "mode", modehelp, 0, 1, 1, CMPL0 setftmode },
{ "modtime", modtimehelp, 0, 1, 1, CMPL(r) modtime },
{ "more", pagehelp, 1, 1, 1, CMPL(r) page },
{ "mput", mputhelp, 1, 1, 1, CMPL(L) mput },
{ "msend", mputhelp, 1, 1, 1, CMPL(L) mput },
{ "newer", newerhelp, 1, 1, 1, CMPL(r) newer },

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.13 1997/03/14 01:39:37 christos Exp $ */
/* $NetBSD: extern.h,v 1.14 1997/04/05 03:27:34 lukem Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@ -55,6 +55,7 @@ void cmdscanner __P((int));
int command __P((const char *, ...));
#ifndef SMALL
unsigned char complete __P((EditLine *, int));
void controlediting __P((void));
#endif /* !SMALL */
int confirm __P((const char *, const char *));
FILE *dataconn __P((const char *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.4 1997/03/16 14:24:18 lukem Exp $ */
/* $NetBSD: fetch.c,v 1.5 1997/04/05 03:27:36 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: fetch.c,v 1.4 1997/03/16 14:24:18 lukem Exp $";
static char rcsid[] = "$NetBSD: fetch.c,v 1.5 1997/04/05 03:27:36 lukem Exp $";
#endif /* not lint */
/*
@ -67,6 +67,7 @@ static char rcsid[] = "$NetBSD: fetch.c,v 1.4 1997/03/16 14:24:18 lukem Exp $";
#define FTP_URL "ftp://" /* ftp URL prefix */
#define HTTP_URL "http://" /* http URL prefix */
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */
#define HTTP_PROXY "http_proxy" /* env var with http proxy location */
@ -75,32 +76,39 @@ static char rcsid[] = "$NetBSD: fetch.c,v 1.4 1997/03/16 14:24:18 lukem Exp $";
jmp_buf httpabort;
/*
* Retrieve an http:// URL, via a proxy if necessary.
* Retrieve URL, via the proxy in $proxyvar if necessary.
* Modifies the string argument given.
* Returns -1 on failure, 0 on success
*/
int
http_get(line)
url_get(line, proxyenv)
char *line;
char *proxyenv;
{
struct sockaddr_in sin;
int i, out, port, s;
size_t buflen, len;
char c, *cp, *cp2, *savefile, *portnum, *path, buf[4096];
char *proxyenv, *proxy, *host;
char *proxy, *host;
sig_t oldintr;
off_t hashbytes;
s = -1;
proxy = NULL;
host = line + sizeof(HTTP_URL) - 1;
if (strncmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0)
host = line + sizeof(HTTP_URL) - 1;
else if (strncmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0)
host = line + sizeof(FTP_URL) - 1;
else
errx(1, "url_get: invalid url '%s'", line);
path = strchr(host, '/'); /* find path */
if (EMPTYSTRING(path))
goto cleanup_http_get;
goto cleanup_url_get;
*path++ = '\0';
if (EMPTYSTRING(path))
goto cleanup_http_get;
goto cleanup_url_get;
savefile = strrchr(path, '/'); /* find savefile */
if (savefile != NULL)
@ -108,20 +116,22 @@ http_get(line)
else
savefile = path;
if (EMPTYSTRING(savefile))
goto cleanup_http_get;
goto cleanup_url_get;
proxyenv = getenv(HTTP_PROXY);
if (proxyenv != NULL) { /* use proxy */
if (strncmp(proxyenv, HTTP_URL, sizeof(HTTP_URL) - 1) != 0) {
warnx("Malformed proxy url: %s", proxyenv);
goto cleanup_http_get;
}
proxy = strdup(proxyenv);
if (proxy == NULL)
errx(1, "Can't allocate memory for proxy url.");
host = proxy + sizeof(HTTP_URL) - 1;
if (strncmp(proxy, HTTP_URL, sizeof(HTTP_URL) - 1) == 0)
host = proxy + sizeof(HTTP_URL) - 1;
else if (strncmp(proxy, FTP_URL, sizeof(FTP_URL) - 1) == 0)
host = proxy + sizeof(FTP_URL) - 1;
else {
warnx("Malformed proxy url: %s", proxy);
goto cleanup_url_get;
}
if (EMPTYSTRING(host))
goto cleanup_http_get;
goto cleanup_url_get;
*--path = '/'; /* add / back to real path */
path = strchr(host, '/'); /* remove trailing / on host */
if (! EMPTYSTRING(path))
@ -143,7 +153,7 @@ http_get(line)
if (isdigit(host[0])) {
if (inet_aton(host, &sin.sin_addr) == 0) {
warnx("invalid IP address: %s", host);
goto cleanup_http_get;
goto cleanup_url_get;
}
} else {
struct hostent *hp;
@ -151,11 +161,11 @@ http_get(line)
hp = gethostbyname(host);
if (hp == NULL) {
warnx("%s: %s", host, hstrerror(h_errno));
goto cleanup_http_get;
goto cleanup_url_get;
}
if (hp->h_addrtype != AF_INET) {
warnx("%s: not an Internet address?", host);
goto cleanup_http_get;
goto cleanup_url_get;
}
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
}
@ -164,7 +174,7 @@ http_get(line)
port = atoi(portnum);
if (port < 1 || (port & 0xffff) != port) {
warnx("invalid port: %s", portnum);
goto cleanup_http_get;
goto cleanup_url_get;
}
port = htons(port);
} else
@ -174,12 +184,12 @@ http_get(line)
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) {
warnx("Can't create socket");
goto cleanup_http_get;
goto cleanup_url_get;
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
warn("Can't connect to %s", host);
goto cleanup_http_get;
goto cleanup_url_get;
}
/*
@ -195,7 +205,7 @@ http_get(line)
buflen = strlen(buf);
if (write(s, buf, buflen) < buflen) {
warn("write");
goto cleanup_http_get;
goto cleanup_url_get;
}
memset(buf, 0, sizeof(buf));
for (i = 0, buflen = sizeof(buf), cp = buf; i < buflen; cp++, i++) {
@ -214,7 +224,7 @@ http_get(line)
cp++;
if (strncmp(cp, "200", 3)) {
warnx("Error retrieving file: %s", cp);
goto cleanup_http_get;
goto cleanup_url_get;
}
/*
@ -258,7 +268,7 @@ http_get(line)
out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (out < 0) {
warn("Can't open %s", savefile);
goto cleanup_http_get;
goto cleanup_url_get;
}
/* Trap signals */
@ -266,7 +276,7 @@ http_get(line)
if (setjmp(httpabort)) {
if (oldintr)
(void)signal(SIGINT, oldintr);
goto cleanup_http_get;
goto cleanup_url_get;
}
oldintr = signal(SIGINT, aborthttp);
@ -281,7 +291,7 @@ http_get(line)
for (cp = buf; len > 0; len -= i, cp += i) {
if ((i = write(out, cp, len)) == -1) {
warn("Writing %s", savefile);
goto cleanup_http_get;
goto cleanup_url_get;
}
else if (i == 0)
break;
@ -302,7 +312,7 @@ http_get(line)
}
if (len != 0) {
warn("Reading from socket");
goto cleanup_http_get;
goto cleanup_url_get;
}
progressmeter(1);
if (verbose)
@ -317,7 +327,7 @@ http_get(line)
improper:
warnx("improper response from %s", host);
cleanup_http_get:
cleanup_url_get:
if (s != -1)
close(s);
if (proxy)
@ -361,6 +371,7 @@ auto_fetch(argc, argv)
static char lasthost[MAXHOSTNAMELEN];
char *xargv[5];
char *cp, *line, *host, *dir, *file, *portnum;
char *ftpproxy, *httpproxy;
int rval, xargc, argpos;
int dirhasglob, filehasglob;
char rempath[MAXPATHLEN];
@ -375,6 +386,9 @@ auto_fetch(argc, argv)
(void)signal(SIGINT, (sig_t)intr);
(void)signal(SIGPIPE, (sig_t)lostpeer);
ftpproxy = getenv(FTP_PROXY);
httpproxy = getenv(HTTP_PROXY);
/*
* Loop through as long as there's files to fetch.
*/
@ -394,16 +408,23 @@ auto_fetch(argc, argv)
* Try HTTP URL-style arguments first.
*/
if (strncmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
if (http_get(line) == -1)
if (url_get(line, httpproxy) == -1)
rval = argpos + 1;
continue;
}
/*
* Try FTP URL-style arguments next, then host:file.
* Try FTP URL-style arguments next. If ftpproxy is
* set, use url_get() instead of standard ftp.
* Finally, try host:file.
*/
host = line;
if (strncmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
if (ftpproxy) {
if (url_get(line, ftpproxy) == -1)
rval = argpos + 1;
continue;
}
host += sizeof(FTP_URL) - 1;
cp = strchr(host, '/');

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ftp.1,v 1.18 1997/03/13 06:23:16 lukem Exp $
.\" $NetBSD: ftp.1,v 1.19 1997/04/05 03:27:37 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -387,6 +387,9 @@ If
no
.Ar directory
is specified, the user's home directory is used.
.It Ic less Ar file
A synonym for
.Ic page .
.It Ic lpwd
Print the working directory on the local machine.
.It Ic \&ls Op Ar remote-directory Op Ar local-file
@ -486,6 +489,9 @@ to
The default mode is \*(Lqstream\*(Rq mode.
.It Ic modtime Ar file-name
Show the last modification time of the file on the remote machine.
.It Ic more Ar file
A synonym for
.Ic page .
.It Ic mput Ar local-files
Expand wild cards in the list of local files given as arguments
and do a
@ -1006,7 +1012,11 @@ The following formats are valid syntax for an auto-fetch element:
.Dq Classic
ftp format
.It ftp://host[:port]/file
FTP URL, using the ftp protocol.
FTP URL, using the ftp protocol if
.Ev ftp_proxy
isn't defined.
Otherwise, transfer using http via the proxy defined in
.Ev ftp_proxy .
.It http://host[:port]/file
HTTP URL, using the http protocol.
If
@ -1306,8 +1316,11 @@ Used by
to display files.
.It Ev SHELL
For default shell.
.It Ev ftp_proxy
URL of FTP proxy to use when making FTP URL requests
(if not defined, use the standard ftp protocol).
.It Ev http_proxy
URL of HTTP proxy to use when making HTTP requests.
URL of HTTP proxy to use when making HTTP URL requests.
.El
.Sh SEE ALSO
.Xr editrc 5 ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.20 1997/03/16 14:24:21 lukem Exp $ */
/* $NetBSD: main.c,v 1.21 1997/04/05 03:27:39 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
static char rcsid[] = "$NetBSD: main.c,v 1.20 1997/03/16 14:24:21 lukem Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.21 1997/04/05 03:27:39 lukem Exp $";
#endif
#endif /* not lint */
@ -91,6 +91,8 @@ main(argc, argv)
progress = 0;
#ifndef SMALL
editing = 0;
el = NULL;
hist = NULL;
#endif
mark = HASHBYTES;
marg_sl = sl_init();
@ -188,33 +190,8 @@ main(argc, argv)
(void)strcpy(home, pw->pw_dir);
}
#ifndef SMALL
if (editing) {
el = el_init(__progname, stdin, stdout); /* init editline */
hist = history_init(); /* init the builtin history */
history(hist, H_EVENT, 100); /* remember 100 events */
el_set(el, EL_HIST, history, hist); /* use history */
el_set(el, EL_EDITOR, "emacs"); /* default editor is emacs */
el_set(el, EL_PROMPT, prompt); /* set the prompt function */
/* add local file completion, bind to TAB */
el_set(el, EL_ADDFN, "ftp-complete",
"Context sensitive argument completion",
complete);
el_set(el, EL_BIND, "^I", "ftp-complete", NULL);
el_source(el, NULL); /* read ~/.editrc */
}
#endif /* !SMALL */
setttywidth(0);
(void)signal(SIGWINCH, setttywidth);
#ifndef SMALL
if (editing)
el_set(el, EL_SIGNAL, 1);
#endif /* !SMALL */
if (argc > 0) {
if (strchr(argv[0], ':') != NULL) {
@ -237,6 +214,9 @@ main(argc, argv)
setpeer(argc+1, xargv);
}
}
#ifndef SMALL
controlediting();
#endif /* !SMALL */
top = setjmp(toplevel) == 0;
if (top) {
(void)signal(SIGINT, (sig_t)intr);

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.5 1997/03/13 06:23:21 lukem Exp $ */
/* $NetBSD: util.c,v 1.6 1997/04/05 03:27:39 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -34,7 +34,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: util.c,v 1.5 1997/03/13 06:23:21 lukem Exp $";
static char rcsid[] = "$NetBSD: util.c,v 1.6 1997/04/05 03:27:39 lukem Exp $";
#endif /* not lint */
/*
@ -611,7 +611,6 @@ setttywidth(a)
/*
* Set the SIGALRM interval timer for wait seconds, 0 to disable.
*/
void
alarmtimer(wait)
int wait;
@ -623,3 +622,40 @@ alarmtimer(wait)
itv.it_interval = itv.it_value;
setitimer(ITIMER_REAL, &itv, NULL);
}
/*
* Setup or cleanup EditLine structures
*/
#ifndef SMALL
void
controlediting()
{
if (editing && el == NULL && hist == NULL) {
el = el_init(__progname, stdin, stdout); /* init editline */
hist = history_init(); /* init the builtin history */
history(hist, H_EVENT, 100); /* remember 100 events */
el_set(el, EL_HIST, history, hist); /* use history */
el_set(el, EL_EDITOR, "emacs"); /* default editor is emacs */
el_set(el, EL_PROMPT, prompt); /* set the prompt function */
/* add local file completion, bind to TAB */
el_set(el, EL_ADDFN, "ftp-complete",
"Context sensitive argument completion",
complete);
el_set(el, EL_BIND, "^I", "ftp-complete", NULL);
el_source(el, NULL); /* read ~/.editrc */
el_set(el, EL_SIGNAL, 1);
} else if (!editing) {
if (hist) {
history_end(hist);
hist = NULL;
}
if (el) {
el_end(el);
el = NULL;
}
}
}
#endif /* !SMALL */