]> sjero.net Git - wget/commitdiff
[svn] Support FWTK-style proxies.
authorhniksic <devnull@localhost>
Sat, 13 Apr 2002 03:04:47 +0000 (20:04 -0700)
committerhniksic <devnull@localhost>
Sat, 13 Apr 2002 03:04:47 +0000 (20:04 -0700)
Pbublished in <sxslmbsxptu.fsf@florida.arsdigita.de>.

NEWS
TODO
src/ChangeLog
src/ftp.c
src/ftp.h
src/retr.c
src/url.c
src/url.h

diff --git a/NEWS b/NEWS
index 9624327f260c19fcd04eaadc43fc3c2b8b1d01c2..206636ed3082fb8a9d6cf3c433835806c81d29cb 100644 (file)
--- 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".
 \f
 * Wget 1.8.1 is a bugfix release with no user-visible changes.
 \f
diff --git a/TODO b/TODO
index bfd54a42a282859ebaa514deaf84569030fba4f5..f0f06317f2c7d49e6b38de87ea39f97b80153134 100644 (file)
--- 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
index d6a89c1a78fc806159c57908d44d3e86a5b97142..12912cf68b8cca243cb90f90021b726b15478a9d 100644 (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>
 
        * config.h.in: Only define _VA_LIST when compiled with gcc.
index c0ded718b718497dac8ca1c3143143bbf08db3cc..6d406222a1caf901ecc4abd026b58b79c4e9eb2b 100644 (file)
--- 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
index b13a319252f47afdf242f808eaa25796f3cb85bc..2b7628c4016558dcd7f0defca1d8ef7572a99c58 100644 (file)
--- 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 *));
 
index c35dde110483a482fae8bf8b673d3e2ab725cb66..772d922ce4b48858e5f4a1f63ceb27893ddf9f82 100644 (file)
@@ -274,10 +274,6 @@ calc_rate (long bytes, long msecs, int *units)
   return dlrate;
 }
 \f
-#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)
     {
index 6fb2418288f16f4bb4aef28732111a631b76d934..6bcaa39a7b9f402b94c976515d72dabb5fb34e23 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -1883,15 +1883,20 @@ url_string (const struct url *url, int hide_password)
   return result;
 }
 \f
-/* 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)
     {
index 6d4fdeabf984821bec3964bc16b508ee7e536596..79f23814ab5b1a1bd4fbe09c2722cc94bd153eed 100644 (file)
--- 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 *));