1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Support FWTK-style proxies.

Pbublished in <sxslmbsxptu.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2002-04-12 20:04:47 -07:00
parent 278b63093f
commit 5390ada318
8 changed files with 64 additions and 44 deletions

4
NEWS
View File

@ -15,6 +15,10 @@ Previously it only affected reading and writing data.
** Download speed shown by the progress bar is based on the data ** Download speed shown by the progress bar is based on the data
recently read, rather than the average speed of the entire download. recently read, rather than the average speed of the entire download.
The ETA is still based on the average speed, though. The ETA is still based on the average speed, though.
** It is now possible to connect to FTP servers through FWTK
firewalls. Set ftp_proxy to an FTP URL, and Wget will automatically
log on to the proxy as "username@host".
* Wget 1.8.1 is a bugfix release with no user-visible changes. * Wget 1.8.1 is a bugfix release with no user-visible changes.

5
TODO
View File

@ -25,11 +25,6 @@ represent user-visible changes.
* Be careful not to lose username/password information given for the * Be careful not to lose username/password information given for the
URL on the command line. URL on the command line.
* Support FWTK firewalls. It should work like this: if ftp_proxy is
set to an ftp URL, Wget should assume the use of an FWTK firewall.
It should connect to the proxy URL, log in as username@target-site,
and continue as usual.
* Add a --range parameter allowing you to explicitly specify a range of bytes to * Add a --range parameter allowing you to explicitly specify a range of bytes to
get from a file over HTTP (FTP only supports ranges ending at the end of the get from a file over HTTP (FTP only supports ranges ending at the end of the
file, though forcibly disconnecting from the server at the desired endpoint file, though forcibly disconnecting from the server at the desired endpoint

View File

@ -1,3 +1,12 @@
2002-04-13 Hrvoje Niksic <hniksic@arsdigita.com>
* url.c (getproxy): Accept a struct url argument. This obviates
the need for USE_PROXY_P.
* retr.c (retrieve_url): Allow proxy to be a non-FTP URL.
* ftp.c (getftp): Recognize FWTK-style proxy.
2002-04-12 Hrvoje Niksic <hniksic@arsdigita.com> 2002-04-12 Hrvoje Niksic <hniksic@arsdigita.com>
* config.h.in: Only define _VA_LIST when compiled with gcc. * config.h.in: Only define _VA_LIST when compiled with gcc.

View File

@ -63,6 +63,7 @@ typedef struct
enum stype rs; /* remote system reported by ftp server */ enum stype rs; /* remote system reported by ftp server */
char *id; /* initial directory */ char *id; /* initial directory */
char *target; /* target file name */ char *target; /* target file name */
struct url *proxy; /* FTWK-style proxy */
} ccon; } ccon;
@ -150,15 +151,26 @@ getftp (struct url *u, long *len, long restval, ccon *con)
char type_char; char type_char;
struct address_list *al; struct address_list *al;
char *host = con->proxy ? con->proxy->host : u->host;
int port = con->proxy ? con->proxy->port : u->port;
char *logname = user;
if (con->proxy)
{
/* If proxy is in use, log in as username@target-site. */
logname = xmalloc (strlen (user) + 1 + strlen (u->host) + 1);
sprintf (logname, "%s@%s", user, u->host);
}
/* Login to the server: */ /* Login to the server: */
/* First: Establish the control connection. */ /* First: Establish the control connection. */
al = lookup_host (u->host, 0); al = lookup_host (host, 0);
if (!al) if (!al)
return HOSTERR; return HOSTERR;
set_connection_host_name (u->host); set_connection_host_name (host);
csock = connect_to_many (al, u->port, 0); csock = connect_to_many (al, port, 0);
set_connection_host_name (NULL); set_connection_host_name (NULL);
address_list_release (al); address_list_release (al);
@ -178,7 +190,11 @@ getftp (struct url *u, long *len, long restval, ccon *con)
logprintf (LOG_VERBOSE, _("Logging in as %s ... "), user); logprintf (LOG_VERBOSE, _("Logging in as %s ... "), user);
if (opt.server_response) if (opt.server_response)
logputs (LOG_ALWAYS, "\n"); logputs (LOG_ALWAYS, "\n");
err = ftp_login (&con->rbuf, user, passwd); err = ftp_login (&con->rbuf, logname, passwd);
if (con->proxy)
xfree (logname);
/* FTPRERR, FTPSRVERR, WRITEFAILED, FTPLOGREFUSED, FTPLOGINC */ /* FTPRERR, FTPSRVERR, WRITEFAILED, FTPLOGREFUSED, FTPLOGINC */
switch (err) switch (err)
{ {
@ -1629,7 +1645,7 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action)
of URL. Inherently, its capabilities are limited on what can be of URL. Inherently, its capabilities are limited on what can be
encoded into a URL. */ encoded into a URL. */
uerr_t uerr_t
ftp_loop (struct url *u, int *dt) ftp_loop (struct url *u, int *dt, struct url *proxy)
{ {
ccon con; /* FTP connection */ ccon con; /* FTP connection */
uerr_t res; uerr_t res;
@ -1642,6 +1658,7 @@ ftp_loop (struct url *u, int *dt)
con.st = ON_YOUR_OWN; con.st = ON_YOUR_OWN;
con.rs = ST_UNIX; con.rs = ST_UNIX;
con.id = NULL; con.id = NULL;
con.proxy = proxy;
res = RETROK; /* in case it's not used */ res = RETROK; /* in case it's not used */
/* If the file name is empty, the user probably wants a directory /* If the file name is empty, the user probably wants a directory

View File

@ -105,7 +105,7 @@ enum wget_ftp_fstatus
}; };
struct fileinfo *ftp_parse_ls PARAMS ((const char *, const enum stype)); struct fileinfo *ftp_parse_ls PARAMS ((const char *, const enum stype));
uerr_t ftp_loop PARAMS ((struct url *, int *)); uerr_t ftp_loop PARAMS ((struct url *, int *, struct url *));
uerr_t ftp_index PARAMS ((const char *, struct url *, struct fileinfo *)); uerr_t ftp_index PARAMS ((const char *, struct url *, struct fileinfo *));

View File

@ -274,10 +274,6 @@ calc_rate (long bytes, long msecs, int *units)
return dlrate; return dlrate;
} }
#define USE_PROXY_P(u) (opt.use_proxy && getproxy((u)->scheme) \
&& no_proxy_match((u)->host, \
(const char **)opt.no_proxy))
/* Maximum number of allowed redirections. 20 was chosen as a /* Maximum number of allowed redirections. 20 was chosen as a
"reasonable" value, which is low enough to not cause havoc, yet "reasonable" value, which is low enough to not cause havoc, yet
high enough to guarantee that normal retrievals will not be hurt by high enough to guarantee that normal retrievals will not be hurt by
@ -295,9 +291,8 @@ retrieve_url (const char *origurl, char **file, char **newloc,
uerr_t result; uerr_t result;
char *url; char *url;
int location_changed, dummy; int location_changed, dummy;
int use_proxy;
char *mynewloc, *proxy; char *mynewloc, *proxy;
struct url *u; struct url *u, *proxy_url;
int up_error_code; /* url parse error code */ int up_error_code; /* url parse error code */
char *local_file; char *local_file;
int redirection_count = 0; int redirection_count = 0;
@ -327,22 +322,11 @@ retrieve_url (const char *origurl, char **file, char **newloc,
result = NOCONERROR; result = NOCONERROR;
mynewloc = NULL; mynewloc = NULL;
local_file = NULL; local_file = NULL;
proxy_url = NULL;
use_proxy = USE_PROXY_P (u); proxy = getproxy (u);
if (use_proxy) if (proxy)
{ {
struct url *proxy_url;
/* Get the proxy server for the current scheme. */
proxy = getproxy (u->scheme);
if (!proxy)
{
logputs (LOG_NOTQUIET, _("Could not find proxy host.\n"));
url_free (u);
xfree (url);
return PROXERR;
}
/* Parse the proxy URL. */ /* Parse the proxy URL. */
proxy_url = url_parse (proxy, &up_error_code); proxy_url = url_parse (proxy, &up_error_code);
if (!proxy_url) if (!proxy_url)
@ -352,24 +336,22 @@ retrieve_url (const char *origurl, char **file, char **newloc,
xfree (url); xfree (url);
return PROXERR; return PROXERR;
} }
if (proxy_url->scheme != SCHEME_HTTP) if (proxy_url->scheme != SCHEME_HTTP && proxy_url->scheme != u->scheme)
{ {
logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy); logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy);
url_free (proxy_url); url_free (proxy_url);
xfree (url); xfree (url);
return PROXERR; return PROXERR;
} }
result = http_loop (u, &mynewloc, &local_file, refurl, dt, proxy_url);
url_free (proxy_url);
} }
else if (u->scheme == SCHEME_HTTP
if (u->scheme == SCHEME_HTTP
#ifdef HAVE_SSL #ifdef HAVE_SSL
|| u->scheme == SCHEME_HTTPS || u->scheme == SCHEME_HTTPS
#endif #endif
) || (proxy_url && proxy_url->scheme == SCHEME_HTTP))
{ {
result = http_loop (u, &mynewloc, &local_file, refurl, dt, NULL); result = http_loop (u, &mynewloc, &local_file, refurl, dt, proxy_url);
} }
else if (u->scheme == SCHEME_FTP) else if (u->scheme == SCHEME_FTP)
{ {
@ -379,7 +361,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
int oldrec = opt.recursive; int oldrec = opt.recursive;
if (redirection_count) if (redirection_count)
opt.recursive = 0; opt.recursive = 0;
result = ftp_loop (u, dt); result = ftp_loop (u, dt, proxy_url);
opt.recursive = oldrec; opt.recursive = oldrec;
/* There is a possibility of having HTTP being redirected to /* There is a possibility of having HTTP being redirected to
@ -392,6 +374,13 @@ retrieve_url (const char *origurl, char **file, char **newloc,
*dt |= TEXTHTML; *dt |= TEXTHTML;
} }
} }
if (proxy_url)
{
url_free (proxy_url);
proxy_url = NULL;
}
location_changed = (result == NEWLOCATION); location_changed = (result == NEWLOCATION);
if (location_changed) if (location_changed)
{ {

View File

@ -1883,15 +1883,20 @@ url_string (const struct url *url, int hide_password)
return result; return result;
} }
/* Returns proxy host address, in accordance with SCHEME. */ /* Return the URL of the proxy appropriate for url U. */
char * char *
getproxy (enum url_scheme scheme) getproxy (struct url *u)
{ {
char *proxy = NULL; char *proxy = NULL;
char *rewritten_url; char *rewritten_url;
static char rewritten_storage[1024]; static char rewritten_storage[1024];
switch (scheme) if (!opt.use_proxy)
return NULL;
if (!no_proxy_match (u->host, (const char **)opt.no_proxy))
return NULL;
switch (u->scheme)
{ {
case SCHEME_HTTP: case SCHEME_HTTP:
proxy = opt.http_proxy ? opt.http_proxy : getenv ("http_proxy"); proxy = opt.http_proxy ? opt.http_proxy : getenv ("http_proxy");
@ -1910,7 +1915,8 @@ getproxy (enum url_scheme scheme)
if (!proxy || !*proxy) if (!proxy || !*proxy)
return NULL; return NULL;
/* Handle shorthands. */ /* Handle shorthands. `rewritten_storage' is a kludge to allow
getproxy() to return static storage. */
rewritten_url = rewrite_shorthand_url (proxy); rewritten_url = rewrite_shorthand_url (proxy);
if (rewritten_url) if (rewritten_url)
{ {

View File

@ -149,7 +149,7 @@ void rotate_backups PARAMS ((const char *));
int mkalldirs PARAMS ((const char *)); int mkalldirs PARAMS ((const char *));
char *url_filename PARAMS ((const struct url *)); char *url_filename PARAMS ((const struct url *));
char *getproxy PARAMS ((enum url_scheme)); char *getproxy PARAMS ((struct url *));
int no_proxy_match PARAMS ((const char *, const char **)); int no_proxy_match PARAMS ((const char *, const char **));
void convert_links PARAMS ((const char *, struct urlpos *)); void convert_links PARAMS ((const char *, struct urlpos *));