[PATCH] Add support for libproxy to the access module http. Libproxy reads proxy settings from kde, gnome, networkmanager, environment

Dominique Leuenberger dominique at leuenberger.net
Sun Jun 8 15:56:35 CEST 2008


---
 configure.ac          |    4 ++++
 modules/access/http.c |   34 +++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index cd6d28f..c09bf78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -536,6 +536,10 @@ AC_CHECK_HEADERS(zlib.h, [
   VLC_ADD_LIBS([access_http],[-lz])
 ])
 
+AC_CHECK_HEADERS(proxy.h, [
+  VLC_ADD_LIBS([access_http],[-lproxy])
+])
+
 dnl Check for socklen_t
 AH_TEMPLATE(socklen_t, [Define to `int' if <sys/socket.h> does not define.])
 AC_CACHE_CHECK([for socklen_t in sys/socket.h],
diff --git a/modules/access/http.c b/modules/access/http.c
index 8a04e14..7a59619 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -52,6 +52,9 @@
 
 #include <assert.h>
 
+#ifdef HAVE_PROXY_H
+#    include "proxy.h"
+#endif
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -306,7 +309,36 @@ static int OpenWithCookies( vlc_object_t *p_this, vlc_array_t *cookies )
         p_sys->b_proxy = true;
         vlc_UrlParse( &p_sys->proxy, psz, 0 );
     }
-#ifdef HAVE_GETENV
+#ifdef PROXY_H_
+    else
+    {
+	pxProxyFactory *pf = px_proxy_factory_new();
+        if (!pf)
+        {
+		msg_Err(p_access, "Allocating memory for libproxy failed");
+                return 1;
+        }
+	char *buf;
+	int i;
+	i=asprintf(&buf, "%s://%s", p_access->psz_access, p_access->psz_path);
+	msg_Dbg(p_access, "asking libproxy about url '%s'", buf);
+	char **proxies = px_proxy_factory_get_proxies(pf, buf);
+	if (proxies[0])
+	{
+	    msg_Dbg(p_access, "libproxy suggest to use '%s'", proxies[0]);
+	    if(proxies[0] != "direct://") 
+	    {
+	        p_sys->b_proxy = true;
+	        vlc_UrlParse( &p_sys->proxy, proxies[0], 0);
+	    }
+	}
+	for(i=0;proxies[i];i++) free(proxies[i]);
+	free(proxies);
+	free(buf);
+	free(pf);
+	
+    }
+#elif HAVE_GETENV
     else
     {
         char *psz_proxy = getenv( "http_proxy" );
-- 
1.5.4.5


--=-Li58nJ1o5QoYhDWItmPc--



More information about the vlc-devel mailing list