File wget-libproxy.patch of Package wget

diff -Nru wget-1.13/configure.ac wget-1.13new/configure.ac
--- wget-1.13/configure.ac	2011-08-05 22:02:50.000000000 +0400
+++ wget-1.13new/configure.ac	2011-08-13 13:39:03.167361286 +0400
@@ -320,6 +320,22 @@
   fi
 fi
 
+dnl
+dnl libproxy support
+dnl
+AC_ARG_ENABLE(libproxy,
+  [  --enable-libproxy       libproxy support for system wide proxy configuration])
+if test "${enable_libproxy}" != "no"
+then
+  PKG_CHECK_MODULES([libproxy], [libproxy-1.0], [enable_libproxy=yes], [enable_libproxy=no])
+fi
+if test "${enable_libproxy}" = "yes"
+then
+  AC_SUBST(libproxy_CFLAGS)
+  AC_SUBST(libproxy_LIBS)
+  AC_DEFINE([HAVE_LIBPROXY], 1, [Define when using libproxy])
+fi
+
 dnl **********************************************************************
 dnl Checks for IPv6
 dnl **********************************************************************
diff -Nru wget-1.13/src/Makefile.am wget-1.13new/src/Makefile.am
--- wget-1.13/src/Makefile.am	2011-05-15 18:31:59.000000000 +0400
+++ wget-1.13new/src/Makefile.am	2011-08-13 13:39:03.167361286 +0400
@@ -37,7 +37,7 @@
 
 # The following line is losing on some versions of make!
 DEFS     = @DEFS@ -DSYSTEM_WGETRC=\"$(sysconfdir)/wgetrc\" -DLOCALEDIR=\"$(localedir)\"
-LIBS     = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME)
+LIBS     = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME) @libproxy_LIBS@
 
 bin_PROGRAMS = wget
 wget_SOURCES = cmpt.c connect.c convert.c cookies.c ftp.c    		  \
diff -Nru wget-1.13/src/retr.c wget-1.13new/src/retr.c
--- wget-1.13/src/retr.c	2011-07-26 13:43:17.000000000 +0400
+++ wget-1.13new/src/retr.c	2011-08-13 13:39:03.168361259 +0400
@@ -54,6 +54,10 @@
 #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;
 
@@ -1181,7 +1185,40 @@
       break;
     }
   if (!proxy || !*proxy)
+#ifdef HAVE_LIBPROXY
+  {
+	pxProxyFactory *pf = px_proxy_factory_new();
+        if (!pf)
+        {
+		logprintf (LOG_VERBOSE, _("Allocating memory for libproxy failed"));
+               return NULL;
+        }
+	int i; 
+	char direct[] = "direct://";
+
+	logprintf (LOG_VERBOSE, _("asking libproxy about url '%s'\n"), u->url);
+	char **proxies = px_proxy_factory_get_proxies(pf, u->url);
+	if (proxies[0])
+	{
+          char *check = NULL;
+          asprintf(&check , "%s", proxies[0]);
+	    logprintf (LOG_VERBOSE, _("libproxy suggest to use '%s'\n"), check);
+  	    if(strcmp(check ,direct) != 0)
+	    {
+		asprintf(&proxy , "%s", proxies[0]);
+  	        logprintf (LOG_VERBOSE, _("case 2: libproxy setting to use '%s'\n"), proxy);
+	    }
+	}
+	for(i=0;proxies[i];i++) free(proxies[i]);
+	free(proxies);
+	free(pf);
+        
+        if (!proxy || !*proxy)
+	    return NULL;
+  }
+#else
     return NULL;
+#endif
 
   /* Handle shorthands.  `rewritten_storage' is a kludge to allow
      getproxy() to return static storage. */