be saner about the method to determine which $proxy to use
This commit is contained in:
parent
bc72f5a29c
commit
ee32f5a96b
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: fetch.c,v 1.40 1998/11/22 06:52:32 explorer Exp $ */
|
/* $NetBSD: fetch.c,v 1.41 1998/12/27 05:49:53 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__RCSID("$NetBSD: fetch.c,v 1.40 1998/11/22 06:52:32 explorer Exp $");
|
__RCSID("$NetBSD: fetch.c,v 1.41 1998/12/27 05:49:53 lukem Exp $");
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -79,7 +79,7 @@ typedef enum {
|
||||||
|
|
||||||
static int parse_url __P((const char *, const char *, url_t *, char **,
|
static int parse_url __P((const char *, const char *, url_t *, char **,
|
||||||
char **, char **, in_port_t *, char **));
|
char **, char **, in_port_t *, char **));
|
||||||
static int url_get __P((const char *, const char *, const char *));
|
static int url_get __P((const char *, const char *));
|
||||||
void aborthttp __P((int));
|
void aborthttp __P((int));
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,10 +87,6 @@ void aborthttp __P((int));
|
||||||
#define FILE_URL "file://" /* file URL prefix */
|
#define FILE_URL "file://" /* file URL prefix */
|
||||||
#define FTP_URL "ftp://" /* ftp URL prefix */
|
#define FTP_URL "ftp://" /* ftp URL prefix */
|
||||||
#define HTTP_URL "http://" /* http 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 */
|
|
||||||
#define NO_PROXY "no_proxy" /* env var with list of non-proxied
|
|
||||||
* hosts, comma or space separated */
|
|
||||||
|
|
||||||
|
|
||||||
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
|
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
|
||||||
|
@ -102,7 +98,7 @@ void aborthttp __P((int));
|
||||||
* Returns -1 if a parse error occurred, otherwise 0.
|
* Returns -1 if a parse error occurred, otherwise 0.
|
||||||
* Sets type to url_t, each of the given char ** pointers to a
|
* Sets type to url_t, each of the given char ** pointers to a
|
||||||
* malloc(3)ed strings of the relevant section, and port to
|
* malloc(3)ed strings of the relevant section, and port to
|
||||||
* 0 if not given, or the number given.
|
* the number given, or ftpport if ftp://, or httpport if http://.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
parse_url(url, desc, type, user, pass, host, port, path)
|
parse_url(url, desc, type, user, pass, host, port, path)
|
||||||
|
@ -128,9 +124,11 @@ parse_url(url, desc, type, user, pass, host, port, path)
|
||||||
if (strncasecmp(url, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
|
if (strncasecmp(url, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
|
||||||
url += sizeof(HTTP_URL) - 1;
|
url += sizeof(HTTP_URL) - 1;
|
||||||
*type = HTTP_URL_T;
|
*type = HTTP_URL_T;
|
||||||
|
*port = httpport;
|
||||||
} else if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
|
} else if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
|
||||||
url += sizeof(FTP_URL) - 1;
|
url += sizeof(FTP_URL) - 1;
|
||||||
*type = FTP_URL_T;
|
*type = FTP_URL_T;
|
||||||
|
*port = ftpport;
|
||||||
} else if (strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
|
} else if (strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
|
||||||
url += sizeof(FILE_URL) - 1;
|
url += sizeof(FILE_URL) - 1;
|
||||||
*type = FILE_URL_T;
|
*type = FILE_URL_T;
|
||||||
|
@ -199,14 +197,14 @@ cleanup_parse_url:
|
||||||
jmp_buf httpabort;
|
jmp_buf httpabort;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve URL, via the proxy in $proxyvar if necessary.
|
* Retrieve URL or classic ftp argument, via the proxy in $proxyvar if
|
||||||
* Modifies the string argument given.
|
* necessary.
|
||||||
* Returns -1 on failure, 0 on success
|
* Returns -1 on failure, 0 on completed xfer, 1 if ftp connection
|
||||||
|
* is still open (e.g, ftp xfer with trailing /)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
url_get(url, proxyenv, outfile)
|
url_get(url, outfile)
|
||||||
const char *url;
|
const char *url;
|
||||||
const char *proxyenv;
|
|
||||||
const char *outfile;
|
const char *outfile;
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
@ -226,6 +224,7 @@ url_get(url, proxyenv, outfile)
|
||||||
char *user, *pass, *host;
|
char *user, *pass, *host;
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
char *path;
|
char *path;
|
||||||
|
const char *proxyenv;
|
||||||
|
|
||||||
closefunc = NULL;
|
closefunc = NULL;
|
||||||
fin = fout = NULL;
|
fin = fout = NULL;
|
||||||
|
@ -233,6 +232,7 @@ url_get(url, proxyenv, outfile)
|
||||||
buf = savefile = NULL;
|
buf = savefile = NULL;
|
||||||
isredirected = isproxy = 0;
|
isredirected = isproxy = 0;
|
||||||
retval = -1;
|
retval = -1;
|
||||||
|
proxyenv = NULL;
|
||||||
|
|
||||||
#ifdef __GNUC__ /* shut up gcc warnings */
|
#ifdef __GNUC__ /* shut up gcc warnings */
|
||||||
(void)&closefunc;
|
(void)&closefunc;
|
||||||
|
@ -247,8 +247,6 @@ url_get(url, proxyenv, outfile)
|
||||||
if (parse_url(url, "URL", &urltype, &user, &pass, &host, &port, &path)
|
if (parse_url(url, "URL", &urltype, &user, &pass, &host, &port, &path)
|
||||||
== -1)
|
== -1)
|
||||||
goto cleanup_url_get;
|
goto cleanup_url_get;
|
||||||
if (port == 0)
|
|
||||||
port = httpport;
|
|
||||||
|
|
||||||
if (urltype == FILE_URL_T && ! EMPTYSTRING(host)
|
if (urltype == FILE_URL_T && ! EMPTYSTRING(host)
|
||||||
&& strcasecmp(host, "localhost") != 0) {
|
&& strcasecmp(host, "localhost") != 0) {
|
||||||
|
@ -298,18 +296,19 @@ url_get(url, proxyenv, outfile)
|
||||||
}
|
}
|
||||||
fprintf(ttyout, "Copying %s\n", path);
|
fprintf(ttyout, "Copying %s\n", path);
|
||||||
} else { /* ftp:// or http:// URLs */
|
} else { /* ftp:// or http:// URLs */
|
||||||
|
if (urltype == HTTP_URL_T)
|
||||||
|
proxyenv = httpproxy;
|
||||||
|
else if (urltype == FTP_URL_T)
|
||||||
|
proxyenv = ftpproxy;
|
||||||
direction = "retrieved";
|
direction = "retrieved";
|
||||||
if (proxyenv != NULL) { /* use proxy */
|
if (proxyenv != NULL) { /* use proxy */
|
||||||
url_t purltype;
|
url_t purltype;
|
||||||
char *puser, *ppass, *phost;
|
char *puser, *ppass, *phost;
|
||||||
in_port_t pport;
|
|
||||||
char *ppath;
|
char *ppath;
|
||||||
char *no_proxy;
|
|
||||||
|
|
||||||
isproxy = 1;
|
isproxy = 1;
|
||||||
|
|
||||||
/* check URL against list of no_proxied sites */
|
/* check URL against list of no_proxied sites */
|
||||||
no_proxy = getenv(NO_PROXY);
|
|
||||||
if (no_proxy != NULL) {
|
if (no_proxy != NULL) {
|
||||||
char *np, *np_copy;
|
char *np, *np_copy;
|
||||||
long np_port;
|
long np_port;
|
||||||
|
@ -342,7 +341,7 @@ url_get(url, proxyenv, outfile)
|
||||||
|
|
||||||
if (isproxy) {
|
if (isproxy) {
|
||||||
if (parse_url(proxyenv, "proxy URL", &purltype,
|
if (parse_url(proxyenv, "proxy URL", &purltype,
|
||||||
&puser, &ppass, &phost, &pport, &ppath)
|
&puser, &ppass, &phost, &port, &ppath)
|
||||||
== -1)
|
== -1)
|
||||||
goto cleanup_url_get;
|
goto cleanup_url_get;
|
||||||
|
|
||||||
|
@ -366,10 +365,6 @@ url_get(url, proxyenv, outfile)
|
||||||
pass = ppass;
|
pass = ppass;
|
||||||
FREEPTR(host);
|
FREEPTR(host);
|
||||||
host = phost;
|
host = phost;
|
||||||
if (pport == 0)
|
|
||||||
port = httpport;
|
|
||||||
else
|
|
||||||
port = pport;
|
|
||||||
FREEPTR(path);
|
FREEPTR(path);
|
||||||
FREEPTR(ppath);
|
FREEPTR(ppath);
|
||||||
path = xstrdup(url);
|
path = xstrdup(url);
|
||||||
|
@ -397,8 +392,10 @@ url_get(url, proxyenv, outfile)
|
||||||
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
|
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port == 0)
|
if (port == 0) {
|
||||||
port = httpport;
|
warnx("Unknown port for URL `%s'", url);
|
||||||
|
goto cleanup_url_get;
|
||||||
|
}
|
||||||
sin.sin_port = port;
|
sin.sin_port = port;
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
@ -551,7 +548,7 @@ url_get(url, proxyenv, outfile)
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(ttyout,
|
fprintf(ttyout,
|
||||||
"Redirected to %s\n", cp);
|
"Redirected to %s\n", cp);
|
||||||
retval = url_get(cp, proxyenv, outfile);
|
retval = url_get(cp, outfile);
|
||||||
goto cleanup_url_get;
|
goto cleanup_url_get;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -691,10 +688,9 @@ aborthttp(notused)
|
||||||
* ftp protocol, URLs of the form "http://host/path" using the
|
* ftp protocol, URLs of the form "http://host/path" using the
|
||||||
* http protocol, and URLs of the form "file:///" by simple
|
* http protocol, and URLs of the form "file:///" by simple
|
||||||
* copying.
|
* copying.
|
||||||
* If path has a trailing "/", then return (-1);
|
* If path has a trailing "/", the path will be cd-ed into and
|
||||||
* the path will be cd-ed into and the connection remains open,
|
* the connection remains open, and the function will return -1
|
||||||
* and the function will return -1 (to indicate the connection
|
* (to indicate the connection is alive).
|
||||||
* is alive).
|
|
||||||
* If an error occurs the return value will be the offset+1 in
|
* 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]
|
* argv[] of the file that caused a problem (i.e, argv[x]
|
||||||
* returns x+1)
|
* returns x+1)
|
||||||
|
@ -713,7 +709,6 @@ auto_fetch(argc, argv, outfile)
|
||||||
char *cp, *host, *path, *dir, *file;
|
char *cp, *host, *path, *dir, *file;
|
||||||
char *user, *pass;
|
char *user, *pass;
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
char *ftpproxy, *httpproxy;
|
|
||||||
int rval, xargc;
|
int rval, xargc;
|
||||||
volatile int argpos;
|
volatile int argpos;
|
||||||
int dirhasglob, filehasglob;
|
int dirhasglob, filehasglob;
|
||||||
|
@ -733,9 +728,6 @@ auto_fetch(argc, argv, outfile)
|
||||||
(void)signal(SIGINT, (sig_t)intr);
|
(void)signal(SIGINT, (sig_t)intr);
|
||||||
(void)signal(SIGPIPE, (sig_t)lostpeer);
|
(void)signal(SIGPIPE, (sig_t)lostpeer);
|
||||||
|
|
||||||
ftpproxy = getenv(FTP_PROXY);
|
|
||||||
httpproxy = getenv(HTTP_PROXY);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loop through as long as there's files to fetch.
|
* Loop through as long as there's files to fetch.
|
||||||
*/
|
*/
|
||||||
|
@ -773,7 +765,7 @@ auto_fetch(argc, argv, outfile)
|
||||||
*/
|
*/
|
||||||
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 ||
|
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 ||
|
||||||
strncasecmp(line, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
|
strncasecmp(line, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
|
||||||
if (url_get(line, httpproxy, outfile) == -1)
|
if (url_get(line, outfile) == -1)
|
||||||
rval = argpos + 1;
|
rval = argpos + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -787,7 +779,7 @@ auto_fetch(argc, argv, outfile)
|
||||||
url_t urltype;
|
url_t urltype;
|
||||||
|
|
||||||
if (ftpproxy) {
|
if (ftpproxy) {
|
||||||
if (url_get(line, ftpproxy, outfile) == -1)
|
if (url_get(line, outfile) == -1)
|
||||||
rval = argpos + 1;
|
rval = argpos + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: ftp_var.h,v 1.27 1998/11/25 16:55:10 christos Exp $ */
|
/* $NetBSD: ftp_var.h,v 1.28 1998/12/27 05:49:53 lukem Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1985, 1989, 1993, 1994
|
* Copyright (c) 1985, 1989, 1993, 1994
|
||||||
|
@ -147,6 +147,10 @@ in_port_t ftpport; /* port number to use for ftp connections */
|
||||||
in_port_t httpport; /* port number to use for http connections */
|
in_port_t httpport; /* port number to use for http connections */
|
||||||
in_port_t gateport; /* port number to use for gateftp connections */
|
in_port_t gateport; /* port number to use for gateftp connections */
|
||||||
|
|
||||||
|
const char *ftpproxy; /* ftp:// proxy server */
|
||||||
|
const char *httpproxy; /* http:// proxy server */
|
||||||
|
const char *no_proxy; /* list of domains not to proxy */
|
||||||
|
|
||||||
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
|
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
|
||||||
|
|
||||||
char line[FTPBUFLEN]; /* input line buffer */
|
char line[FTPBUFLEN]; /* input line buffer */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: main.c,v 1.34 1998/09/28 09:03:22 lukem Exp $ */
|
/* $NetBSD: main.c,v 1.35 1998/12/27 05:49:53 lukem Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1985, 1989, 1993, 1994
|
* Copyright (c) 1985, 1989, 1993, 1994
|
||||||
|
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: main.c,v 1.34 1998/09/28 09:03:22 lukem Exp $");
|
__RCSID("$NetBSD: main.c,v 1.35 1998/12/27 05:49:53 lukem Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -65,6 +65,11 @@ __RCSID("$NetBSD: main.c,v 1.34 1998/09/28 09:03:22 lukem Exp $");
|
||||||
#include "ftp_var.h"
|
#include "ftp_var.h"
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
|
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */
|
||||||
|
#define HTTP_PROXY "http_proxy" /* env var with http proxy location */
|
||||||
|
#define NO_PROXY "no_proxy" /* env var with list of non-proxied
|
||||||
|
* hosts, comma or space separated */
|
||||||
|
|
||||||
int main __P((int, char **));
|
int main __P((int, char **));
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -90,6 +95,9 @@ main(argc, argv)
|
||||||
httpport = htons(HTTP_PORT); /* good fallback */
|
httpport = htons(HTTP_PORT); /* good fallback */
|
||||||
else
|
else
|
||||||
httpport = sp->s_port;
|
httpport = sp->s_port;
|
||||||
|
ftpproxy = getenv(FTP_PROXY);
|
||||||
|
httpproxy = getenv(HTTP_PROXY);
|
||||||
|
no_proxy = getenv(NO_PROXY);
|
||||||
gateport = 0;
|
gateport = 0;
|
||||||
cp = getenv("FTPSERVERPORT");
|
cp = getenv("FTPSERVERPORT");
|
||||||
if (cp != NULL) {
|
if (cp != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue