From: hniksic Date: Sat, 13 Apr 2002 03:04:47 +0000 (-0700) Subject: [svn] Support FWTK-style proxies. X-Git-Tag: v1.13~1802 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=5390ada318a462655c79ef8cfc02d675bab78f7e [svn] Support FWTK-style proxies. Pbublished in . --- diff --git a/NEWS b/NEWS index 9624327f..206636ed 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,10 @@ Previously it only affected reading and writing data. ** Download speed shown by the progress bar is based on the data recently read, rather than the average speed of the entire download. 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. diff --git a/TODO b/TODO index bfd54a42..f0f06317 100644 --- a/TODO +++ b/TODO @@ -25,11 +25,6 @@ represent user-visible changes. * Be careful not to lose username/password information given for the 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 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 diff --git a/src/ChangeLog b/src/ChangeLog index d6a89c1a..12912cf6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2002-04-13 Hrvoje Niksic + + * 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 * config.h.in: Only define _VA_LIST when compiled with gcc. diff --git a/src/ftp.c b/src/ftp.c index c0ded718..6d406222 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -63,6 +63,7 @@ typedef struct enum stype rs; /* remote system reported by ftp server */ char *id; /* initial directory */ char *target; /* target file name */ + struct url *proxy; /* FTWK-style proxy */ } ccon; @@ -150,15 +151,26 @@ getftp (struct url *u, long *len, long restval, ccon *con) char type_char; 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: */ /* First: Establish the control connection. */ - al = lookup_host (u->host, 0); + al = lookup_host (host, 0); if (!al) return HOSTERR; - set_connection_host_name (u->host); - csock = connect_to_many (al, u->port, 0); + set_connection_host_name (host); + csock = connect_to_many (al, port, 0); set_connection_host_name (NULL); 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); if (opt.server_response) 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 */ 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 encoded into a URL. */ uerr_t -ftp_loop (struct url *u, int *dt) +ftp_loop (struct url *u, int *dt, struct url *proxy) { ccon con; /* FTP connection */ uerr_t res; @@ -1642,6 +1658,7 @@ ftp_loop (struct url *u, int *dt) con.st = ON_YOUR_OWN; con.rs = ST_UNIX; con.id = NULL; + con.proxy = proxy; res = RETROK; /* in case it's not used */ /* If the file name is empty, the user probably wants a directory diff --git a/src/ftp.h b/src/ftp.h index b13a3192..2b7628c4 100644 --- a/src/ftp.h +++ b/src/ftp.h @@ -105,7 +105,7 @@ enum wget_ftp_fstatus }; 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 *)); diff --git a/src/retr.c b/src/retr.c index c35dde11..772d922c 100644 --- a/src/retr.c +++ b/src/retr.c @@ -274,10 +274,6 @@ calc_rate (long bytes, long msecs, int *units) 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 "reasonable" value, which is low enough to not cause havoc, yet 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; char *url; int location_changed, dummy; - int use_proxy; char *mynewloc, *proxy; - struct url *u; + struct url *u, *proxy_url; int up_error_code; /* url parse error code */ char *local_file; int redirection_count = 0; @@ -327,22 +322,11 @@ retrieve_url (const char *origurl, char **file, char **newloc, result = NOCONERROR; mynewloc = NULL; local_file = NULL; + proxy_url = NULL; - use_proxy = USE_PROXY_P (u); - if (use_proxy) + proxy = getproxy (u); + 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. */ proxy_url = url_parse (proxy, &up_error_code); if (!proxy_url) @@ -352,24 +336,22 @@ retrieve_url (const char *origurl, char **file, char **newloc, xfree (url); 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); url_free (proxy_url); xfree (url); 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 || u->scheme == SCHEME_HTTPS #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) { @@ -379,7 +361,7 @@ retrieve_url (const char *origurl, char **file, char **newloc, int oldrec = opt.recursive; if (redirection_count) opt.recursive = 0; - result = ftp_loop (u, dt); + result = ftp_loop (u, dt, proxy_url); opt.recursive = oldrec; /* 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; } } + + if (proxy_url) + { + url_free (proxy_url); + proxy_url = NULL; + } + location_changed = (result == NEWLOCATION); if (location_changed) { diff --git a/src/url.c b/src/url.c index 6fb24182..6bcaa39a 100644 --- a/src/url.c +++ b/src/url.c @@ -1883,15 +1883,20 @@ url_string (const struct url *url, int hide_password) return result; } -/* Returns proxy host address, in accordance with SCHEME. */ +/* Return the URL of the proxy appropriate for url U. */ char * -getproxy (enum url_scheme scheme) +getproxy (struct url *u) { char *proxy = NULL; char *rewritten_url; 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: proxy = opt.http_proxy ? opt.http_proxy : getenv ("http_proxy"); @@ -1910,7 +1915,8 @@ getproxy (enum url_scheme scheme) if (!proxy || !*proxy) return NULL; - /* Handle shorthands. */ + /* Handle shorthands. `rewritten_storage' is a kludge to allow + getproxy() to return static storage. */ rewritten_url = rewrite_shorthand_url (proxy); if (rewritten_url) { diff --git a/src/url.h b/src/url.h index 6d4fdeab..79f23814 100644 --- a/src/url.h +++ b/src/url.h @@ -149,7 +149,7 @@ void rotate_backups PARAMS ((const char *)); int mkalldirs PARAMS ((const char *)); 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 **)); void convert_links PARAMS ((const char *, struct urlpos *));