summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@redhat.com>2021-07-12 08:38:02 -0500
committerPatrick <tingping@tingping.se>2021-07-12 11:29:15 -0500
commit25440a07c3b421134b4376d7db3ee4b7ed57ad98 (patch)
tree73f110696622d7246bf3d64c4ab82f8f67bffe26
parent869a8d7ab335cf785e06450e4ab1ca02a9f5005f (diff)
Avoid direct use of libproxy
Since hexchat already depends on GLib, it's better to use GProxyResolver
instead. This might use libproxy, or not, as appropriate.

P.S. This removes a memory safety issue because proxy_list is allocated
using malloc(), not g_malloc(), and therefore using g_strfreev() is
incorrect. The proper way to free the proxy list returned by libproxy
is to use px_proxy_factory_free_proxies() (but nobody does that because
it was added in libproxy 0.4.16, which is somewhat recent).
-rw-r--r--meson.build1
-rw-r--r--meson_options.txt3
-rw-r--r--src/common/hexchat.c16
-rw-r--r--src/common/meson.build4
-rw-r--r--src/common/server.c26
-rw-r--r--src/fe-gtk/setup.c2
6 files changed, 16 insertions, 36 deletions
diff --git a/meson.build b/meson.build
index 9b33574b..0f5faca8 100644
--- a/meson.build
+++ b/meson.build
@@ -33,7 +33,6 @@ config_h.set10('ENABLE_NLS', true)
 
 # Optional features
 config_h.set('USE_OPENSSL', get_option('with-ssl'))
-config_h.set('USE_LIBPROXY', get_option('with-libproxy'))
 config_h.set('USE_LIBCANBERRA', get_option('with-libcanberra'))
 config_h.set('USE_DBUS', get_option('with-dbus'))
 config_h.set('USE_PLUGIN', get_option('with-plugin'))
diff --git a/meson_options.txt b/meson_options.txt
index 100a5ee7..ad03d6bc 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -13,9 +13,6 @@ option('with-plugin', type: 'boolean',
 option('with-dbus', type: 'boolean',
   description: 'Support used for single-instance and scripting interface, Unix only'
 )
-option('with-libproxy', type: 'boolean',
-  description: 'Support for getting proxy information, Unix only'
-)
 option('with-libnotify', type: 'boolean',
   description: 'Support for freedesktop notifications, Unix only'
 )
diff --git a/src/common/hexchat.c b/src/common/hexchat.c
index 8702c63d..3ba7ed6d 100644
--- a/src/common/hexchat.c
+++ b/src/common/hexchat.c
@@ -57,10 +57,6 @@
 #include <glib-object.h>			/* for g_type_init() */
 #endif
 
-#ifdef USE_LIBPROXY
-#include <proxy.h>
-#endif
-
 GSList *popup_list = 0;
 GSList *button_list = 0;
 GSList *dlgbutton_list = 0;
@@ -111,10 +107,6 @@ struct session *current_tab;
 struct session *current_sess = 0;
 struct hexchatprefs prefs;
 
-#ifdef USE_LIBPROXY
-pxProxyFactory *libproxy_factory;
-#endif
-
 /*
  * Update the priority queue of the "interesting sessions"
  * (sess_list_by_lastact).
@@ -1102,10 +1094,6 @@ main (int argc, char *argv[])
 	hexchat_remote ();
 #endif
 
-#ifdef USE_LIBPROXY
-	libproxy_factory = px_proxy_factory_new ();
-#endif
-
 #ifdef WIN32
 	coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
 	if (SUCCEEDED (coinit_result))
@@ -1148,10 +1136,6 @@ main (int argc, char *argv[])
 	}
 #endif
 
-#ifdef USE_LIBPROXY
-	px_proxy_factory_free (libproxy_factory);
-#endif
-
 #ifdef WIN32
 	WSACleanup ();
 #endif
diff --git a/src/common/meson.build b/src/common/meson.build
index 492227b2..09491e84 100644
--- a/src/common/meson.build
+++ b/src/common/meson.build
@@ -77,10 +77,6 @@ if get_option('with-ssl')
   common_deps += libssl_dep
 endif
 
-if get_option('with-libproxy')
-  common_deps += dependency('libproxy-1.0')
-endif
-
 if get_option('with-libcanberra')
   common_deps += dependency('libcanberra', version: '>= 0.22')
 endif
diff --git a/src/common/server.c b/src/common/server.c
index 5c645eb5..4f809fa8 100644
--- a/src/common/server.c
+++ b/src/common/server.c
@@ -61,10 +61,6 @@
 #include "ssl.h"
 #endif
 
-#ifdef USE_LIBPROXY
-#include <proxy.h>
-#endif
-
 #ifdef USE_OPENSSL
 /* local variables */
 static struct session *g_sess = NULL;
@@ -78,9 +74,15 @@ static void server_disconnect (session * sess, int sendquit, int err);
 static int server_cleanup (server * serv);
 static void server_connect (server *serv, char *hostname, int port, int no_login);
 
-#ifdef USE_LIBPROXY
-extern pxProxyFactory *libproxy_factory;
-#endif
+static void
+write_error (char *message, GError **error)
+{
+	if (error == NULL || *error == NULL) {
+		return;
+	}
+	g_printerr ("%s: %s\n", message, (*error)->message);
+	g_clear_error (error);
+}
 
 /* actually send to the socket. This might do a character translation or
    send via SSL. server/dcc both use this function. */
@@ -1392,14 +1394,16 @@ server_child (server * serv)
 
 	if (!serv->dont_use_proxy) /* blocked in serverlist? */
 	{
-#ifdef USE_LIBPROXY
 		if (prefs.hex_net_proxy_type == 5)
 		{
 			char **proxy_list;
 			char *url, *proxy;
+			GProxyResolver *resolver;
+			GError *error = NULL;
 
+			resolver = g_proxy_resolver_get_default ();
 			url = g_strdup_printf ("irc://%s:%d", hostname, port);
-			proxy_list = px_proxy_factory_get_proxies (libproxy_factory, url);
+			proxy_list = g_proxy_resolver_lookup (resolver, url, NULL, &error);
 
 			if (proxy_list) {
 				/* can use only one */
@@ -1412,6 +1416,8 @@ server_child (server * serv)
 					proxy_type = 3;
 				else if (!strncmp (proxy, "socks", 5))
 					proxy_type = 2;
+			} else {
+				write_error ("Failed to lookup proxy", &error);
 			}
 
 			if (proxy_type) {
@@ -1426,7 +1432,7 @@ server_child (server * serv)
 			g_strfreev (proxy_list);
 			g_free (url);
 		}
-#endif
+
 		if (prefs.hex_net_proxy_host[0] &&
 			   prefs.hex_net_proxy_type > 0 &&
 			   prefs.hex_net_proxy_use != 2) /* proxy is NOT dcc-only */
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
index 3d003eef..a7e3a15c 100644
--- a/src/fe-gtk/setup.c
+++ b/src/fe-gtk/setup.c
@@ -614,9 +614,7 @@ static const char *const proxytypes[] =
 	N_("SOCKS4"),
 	N_("SOCKS5"),
 	N_("HTTP"),
-#ifdef USE_LIBPROXY
 	N_("Auto"),
-#endif
 	NULL
 };