Hi everybody,

Sorry, it took a bit longer than I expected, but some other things just came in 
between.

But finally, here it is: my patch which will add libproxy support to wget.
Of course it's all configurable using configure and the wget parameters 
--no-proxy and proxyrc have precedence.

I kindly ask you to review the patch and let me know if you have any comments / 
changes to apply. I'm sure we'll be able to work them out in no time
together.

Thank you very much,
Dominique

PS: please CC me in your replies, as I'm not subscribed to the list.
diff -r 078ccbf5d52a ChangeLog
--- a/ChangeLog Sat Aug 29 23:24:49 2009 +0200
+++ b/ChangeLog Sun Aug 30 18:01:36 2009 +0000
@@ -1,3 +1,8 @@
+2009-08-30  Dominique Leuenberger <[email protected]>
+
+    * configure.ac: Add detection of libproxy, including option to
+    disable it using --disable-libproxy.
+
 2009-08-27  Micah Cowan  <[email protected]>
 
        * NEWS: Mention the changes to exit codes.
diff -r 078ccbf5d52a configure.ac
--- a/configure.ac      Sat Aug 29 23:24:49 2009 +0200
+++ b/configure.ac      Sun Aug 30 18:01:36 2009 +0000
@@ -427,6 +427,52 @@
   AC_MSG_ERROR([IPv6 support requested but not found; aborting])
 fi
 
+dnl **********************************************************************
+dnl Checks for libproxy in case it should be enabled
+dnl **********************************************************************
+
+dnl We assume that if libproxy is availabel during build time and nothing
+dnl has been specified on how to configure it, it should be used.
+AC_ARG_ENABLE(libproxy,
+  AC_HELP_STRING([--disable-libproxy],[disable libproxy support]),
+  [case "${enable_libproxy}" in
+    no)
+      AC_MSG_NOTICE([disabling libproxy at user request])
+      dnl Disable libproxy checking
+      libproxy=no
+      ;;
+    yes)
+      dnl libproxy explicitly enabled: force its use (abort if unavailable).
+      libproxy=yes
+      force_libproxy=yes
+      ;;
+    auto)
+      dnl Auto-detect libproxy, i.e. check for libproxy, but don't force it.
+      libproxy=yes
+      ;;
+    *)
+      AC_MSG_ERROR([Invalid --enable-libproxy argument \`$enable_libproxy'])
+      ;;
+    esac
+  ], [
+    dnl If nothing is specified, assume auto-detection.
+    libproxy=yes
+  ]
+)
+
+if test "X$libproxy" = "Xyes"; then
+  AC_CHECK_LIB(proxy, px_proxy_factory_new, [], [
+    AC_MSG_NOTICE([Disabling libproxy support: your system is missing 
libproxy-devel package])
+    libproxy=no
+  ])
+fi
+
+if test "X$libproxy" = "Xyes"; then
+  AC_DEFINE([ENABLE_LIBPROXY], 1, [Define if libproxy support is enabled.])
+  AC_MSG_NOTICE([Enabling support for libproxy.])
+elif test "x$force_libproxy" = "xyes"; then
+  AC_MSG_ERROR([Libproxy support requested but not found; aborting])
+fi
 
 dnl
 dnl Set of available languages.
diff -r 078ccbf5d52a src/ChangeLog
--- a/src/ChangeLog     Sat Aug 29 23:24:49 2009 +0200
+++ b/src/ChangeLog     Sun Aug 30 18:01:36 2009 +0000
@@ -1,3 +1,8 @@
+2009-08-30  Dominique Leuenberger <[email protected]>
+
+    * retr.c: Add libproxy support in order to use the system proxy,
+    as configured in the kde/gnome session.
+
 2009-08-29  Steven Schubiger  <[email protected]>
 
        * convert.c (local_quote_string): Percent-encode semicolons
diff -r 078ccbf5d52a src/retr.c
--- a/src/retr.c        Sat Aug 29 23:24:49 2009 +0200
+++ b/src/retr.c        Sun Aug 30 18:01:36 2009 +0000
@@ -54,6 +54,9 @@
 #include "ptimer.h"
 #include "html-url.h"
 #include "iri.h"
+#ifdef HAVE_LIBPROXY
+#include "proxy.h"
+#endif
 
 /* Total size of downloaded files.  Used to enforce quota.  */
 SUM_SIZE_INT total_downloaded_bytes;
@@ -1109,11 +1112,14 @@
 getproxy (struct url *u)
 {
   char *proxy = NULL;
+
+  if (!opt.use_proxy)
+    return NULL;
+
+#ifndef HAVE_LIBPROXY
   char *rewritten_url;
   static char rewritten_storage[1024];
 
-  if (!opt.use_proxy)
-    return NULL;
   if (no_proxy_match (u->host, (const char **)opt.no_proxy))
     return NULL;
 
@@ -1147,6 +1153,42 @@
     }
 
   return proxy;
+#else
+  char **proxies = NULL;
+
+/* In case the user has wget configured to use specific proxies in .wgetrc,
+   then we don't pass the request on to libproxy. It would be a waste. 
+*/
+  switch (u->scheme)
+    {
+    case SCHEME_HTTP:
+      proxy = opt.http_proxy;
+      break;
+#ifdef HAVE_SSL
+    case SCHEME_HTTPS:
+      proxy = opt.https_proxy;
+      break;
+#endif
+    case SCHEME_FTP:
+      proxy = opt.ftp_proxy;
+      break;
+    case SCHEME_INVALID:
+      break;
+    }
+  if (proxy)
+    return proxy;
+
+  /* Initialize the libproxy engine */
+  pxProxyFactory *pf = px_proxy_factory_new ();
+  if ( !pf )
+    return NULL;
+  proxies = px_proxy_factory_get_proxies (pf, u->url);
+  px_proxy_factory_free (pf);
+  if (strcmp (proxies[0], "direct://") == 0) /* No proxy to be used */
+    return NULL;
+  else
+    return proxies[0];
+#endif
 }
 
 /* Returns true if URL would be downloaded through a proxy. */

Reply via email to