Add libproxy support

Add support for libproxy, which is capable to extract desktop
environment proxy configurations from dozens of systems and platforms.
This also enables wget to handle pac/wpad proxy server.

* configure.ac: Add check for libbproxy.
* src/retr.c (getproxy): Retrieve proxy via libproxy.

Copyright-paperwork-exempt: Yes
This commit is contained in:
Jan-Michael Brummer 2023-06-27 20:47:35 +02:00 committed by Tim Rühsen
parent 73d24b2779
commit 8e8900613c
3 changed files with 53 additions and 0 deletions

View File

@ -363,3 +363,4 @@ Contributors:
[ ] Nik Soggia *wget [at] niksoggia.it*
[ ] Aarni Koskela *akx [at] iki.fi*
[ ] jinfuchiang *jinfuchiang [at] outlook.com*
[ ] Jan-Michael Brummer *jan-michael.brummer1 [at] volkswagen.de*

View File

@ -951,6 +951,21 @@ AS_IF([test x"$with_metalink" != xno], [
])
])
dnl
dnl libproxy support
dnl
with_libproxy=no
AC_ARG_ENABLE(libproxy,
[ --enable-libproxy libproxy support for system wide proxy configuration])
AS_IF([test "${enable_libproxy}" = "yes"], [
with_libproxy=yes
PKG_CHECK_MODULES([LIBPROXY], [libproxy-1.0], [
LIBS="$LIBPROXY_LIBS $LIBS"
CFLAGS="$LIBPROXY_CFLAGS $CFLAGS"
AC_DEFINE([HAVE_LIBPROXY], [1], [Define if using libproxy.])
])
])
dnl
dnl Extended Attribute support
dnl
@ -1022,4 +1037,5 @@ AC_MSG_NOTICE([Summary of build options:
GPGME: $have_gpg
IRI: $iri
Fuzzing build: $enable_fuzzing, $LIB_FUZZING_ENGINE
libproxy: $with_libproxy
])

View File

@ -44,6 +44,10 @@ as that of the covered work. */
# include <zlib.h>
#endif
#ifdef HAVE_LIBPROXY
# include "proxy.h"
#endif
#include "exits.h"
#include "utils.h"
#include "retr.h"
@ -1489,7 +1493,39 @@ getproxy (struct url *u)
break;
}
if (!proxy || !*proxy)
#ifdef HAVE_LIBPROXY
{
pxProxyFactory *pf = px_proxy_factory_new ();
if (!pf)
{
debug_logprintf ("Allocating memory for libproxy failed");
return NULL;
}
debug_logprintf ("asking libproxy about url '%s'\n", u->url);
char **proxies = px_proxy_factory_get_proxies (pf, u->url);
if (proxies)
{
if (proxies[0])
{
debug_logprintf ("libproxy suggest to use '%s'\n", proxies[0]);
if (strcmp (proxies[0], "direct://") != 0)
{
proxy = xstrdup (proxies[0]);
debug_logprintf ("libproxy setting to use '%s'\n", proxy);
}
}
px_proxy_factory_free_proxies (proxies);
}
px_proxy_factory_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. */