Blame SOURCES/hexchat-Avoid-direct-use-of-libproxy.patch

ebda66
From 54321bae1feaf0845d75f67245c95795651277f5 Mon Sep 17 00:00:00 2001
ebda66
From: Michael Catanzaro <mcatanzaro@redhat.com>
ebda66
Date: Mon, 12 Jul 2021 08:38:02 -0500
ebda66
Subject: [PATCH] Avoid direct use of libproxy
ebda66
ebda66
Since hexchat already depends on GLib, it's better to use GProxyResolver
ebda66
instead. This might use libproxy, or not, as appropriate.
ebda66
ebda66
P.S. This removes a memory safety issue because proxy_list is allocated
ebda66
using malloc(), not g_malloc(), and therefore using g_strfreev() is
ebda66
incorrect. The proper way to free the proxy list returned by libproxy
ebda66
is to use px_proxy_factory_free_proxies() (but nobody does that because
ebda66
it was added in libproxy 0.4.16, which is somewhat recent).
ebda66
---
ebda66
 meson.build            |  1 -
ebda66
 meson_options.txt      |  3 ---
ebda66
 src/common/hexchat.c   | 16 ----------------
ebda66
 src/common/meson.build |  4 ----
ebda66
 src/common/server.c    | 26 ++++++++++++++++----------
ebda66
 src/fe-gtk/setup.c     |  2 --
ebda66
 6 files changed, 16 insertions(+), 36 deletions(-)
ebda66
ebda66
diff --git a/meson.build b/meson.build
ebda66
index 18baf26e126e..381e3fd87ac6 100644
ebda66
--- a/meson.build
ebda66
+++ b/meson.build
ebda66
@@ -33,7 +33,6 @@ config_h.set10('ENABLE_NLS', true)
ebda66
 
ebda66
 # Optional features
ebda66
 config_h.set('USE_OPENSSL', get_option('with-ssl'))
ebda66
-config_h.set('USE_LIBPROXY', get_option('with-libproxy'))
ebda66
 config_h.set('USE_LIBCANBERRA', get_option('with-libcanberra'))
ebda66
 config_h.set('USE_DBUS', get_option('with-dbus'))
ebda66
 config_h.set('USE_PLUGIN', get_option('with-plugin'))
ebda66
diff --git a/meson_options.txt b/meson_options.txt
ebda66
index 100a5ee72ad7..ad03d6bc58ef 100644
ebda66
--- a/meson_options.txt
ebda66
+++ b/meson_options.txt
ebda66
@@ -13,9 +13,6 @@ option('with-plugin', type: 'boolean',
ebda66
 option('with-dbus', type: 'boolean',
ebda66
   description: 'Support used for single-instance and scripting interface, Unix only'
ebda66
 )
ebda66
-option('with-libproxy', type: 'boolean',
ebda66
-  description: 'Support for getting proxy information, Unix only'
ebda66
-)
ebda66
 option('with-libnotify', type: 'boolean',
ebda66
   description: 'Support for freedesktop notifications, Unix only'
ebda66
 )
ebda66
diff --git a/src/common/hexchat.c b/src/common/hexchat.c
ebda66
index e9a9a7fc9fcd..a98fcafba2f7 100644
ebda66
--- a/src/common/hexchat.c
ebda66
+++ b/src/common/hexchat.c
ebda66
@@ -57,10 +57,6 @@
ebda66
 #include <glib-object.h>			/* for g_type_init() */
ebda66
 #endif
ebda66
 
ebda66
-#ifdef USE_LIBPROXY
ebda66
-#include <proxy.h>
ebda66
-#endif
ebda66
-
ebda66
 GSList *popup_list = 0;
ebda66
 GSList *button_list = 0;
ebda66
 GSList *dlgbutton_list = 0;
ebda66
@@ -111,10 +107,6 @@ struct session *current_tab;
ebda66
 struct session *current_sess = 0;
ebda66
 struct hexchatprefs prefs;
ebda66
 
ebda66
-#ifdef USE_LIBPROXY
ebda66
-pxProxyFactory *libproxy_factory;
ebda66
-#endif
ebda66
-
ebda66
 /*
ebda66
  * Update the priority queue of the "interesting sessions"
ebda66
  * (sess_list_by_lastact).
ebda66
@@ -1101,10 +1093,6 @@ main (int argc, char *argv[])
ebda66
 	hexchat_remote ();
ebda66
 #endif
ebda66
 
ebda66
-#ifdef USE_LIBPROXY
ebda66
-	libproxy_factory = px_proxy_factory_new ();
ebda66
-#endif
ebda66
-
ebda66
 #ifdef WIN32
ebda66
 	coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
ebda66
 	if (SUCCEEDED (coinit_result))
ebda66
@@ -1147,10 +1135,6 @@ main (int argc, char *argv[])
ebda66
 	}
ebda66
 #endif
ebda66
 
ebda66
-#ifdef USE_LIBPROXY
ebda66
-	px_proxy_factory_free (libproxy_factory);
ebda66
-#endif
ebda66
-
ebda66
 #ifdef WIN32
ebda66
 	WSACleanup ();
ebda66
 #endif
ebda66
diff --git a/src/common/meson.build b/src/common/meson.build
ebda66
index bbb646459522..5885ec9e47c1 100644
ebda66
--- a/src/common/meson.build
ebda66
+++ b/src/common/meson.build
ebda66
@@ -77,10 +77,6 @@ if get_option('with-ssl')
ebda66
   common_deps += libssl_dep
ebda66
 endif
ebda66
 
ebda66
-if get_option('with-libproxy')
ebda66
-  common_deps += dependency('libproxy-1.0')
ebda66
-endif
ebda66
-
ebda66
 if get_option('with-libcanberra')
ebda66
   common_deps += dependency('libcanberra', version: '>= 0.22')
ebda66
 endif
ebda66
diff --git a/src/common/server.c b/src/common/server.c
ebda66
index 3db0a9635fc5..a96e81f43d15 100644
ebda66
--- a/src/common/server.c
ebda66
+++ b/src/common/server.c
ebda66
@@ -61,10 +61,6 @@
ebda66
 #include "ssl.h"
ebda66
 #endif
ebda66
 
ebda66
-#ifdef USE_LIBPROXY
ebda66
-#include <proxy.h>
ebda66
-#endif
ebda66
-
ebda66
 #ifdef USE_OPENSSL
ebda66
 /* local variables */
ebda66
 static struct session *g_sess = NULL;
ebda66
@@ -78,9 +74,15 @@ static void server_disconnect (session * sess, int sendquit, int err);
ebda66
 static int server_cleanup (server * serv);
ebda66
 static void server_connect (server *serv, char *hostname, int port, int no_login);
ebda66
 
ebda66
-#ifdef USE_LIBPROXY
ebda66
-extern pxProxyFactory *libproxy_factory;
ebda66
-#endif
ebda66
+static void
ebda66
+write_error (char *message, GError **error)
ebda66
+{
ebda66
+	if (error == NULL || *error == NULL) {
ebda66
+		return;
ebda66
+	}
ebda66
+	g_printerr ("%s: %s\n", message, (*error)->message);
ebda66
+	g_clear_error (error);
ebda66
+}
ebda66
 
ebda66
 /* actually send to the socket. This might do a character translation or
ebda66
    send via SSL. server/dcc both use this function. */
ebda66
@@ -1365,14 +1367,16 @@ server_child (server * serv)
ebda66
 
ebda66
 	if (!serv->dont_use_proxy) /* blocked in serverlist? */
ebda66
 	{
ebda66
-#ifdef USE_LIBPROXY
ebda66
 		if (prefs.hex_net_proxy_type == 5)
ebda66
 		{
ebda66
 			char **proxy_list;
ebda66
 			char *url, *proxy;
ebda66
+			GProxyResolver *resolver;
ebda66
+			GError *error = NULL;
ebda66
 
ebda66
+			resolver = g_proxy_resolver_get_default ();
ebda66
 			url = g_strdup_printf ("irc://%s:%d", hostname, port);
ebda66
-			proxy_list = px_proxy_factory_get_proxies (libproxy_factory, url);
ebda66
+			proxy_list = g_proxy_resolver_lookup (resolver, url, NULL, &error);
ebda66
 
ebda66
 			if (proxy_list) {
ebda66
 				/* can use only one */
ebda66
@@ -1385,6 +1389,8 @@ server_child (server * serv)
ebda66
 					proxy_type = 3;
ebda66
 				else if (!strncmp (proxy, "socks", 5))
ebda66
 					proxy_type = 2;
ebda66
+			} else {
ebda66
+				write_error ("Failed to lookup proxy", &error);
ebda66
 			}
ebda66
 
ebda66
 			if (proxy_type) {
ebda66
@@ -1399,7 +1405,7 @@ server_child (server * serv)
ebda66
 			g_strfreev (proxy_list);
ebda66
 			g_free (url);
ebda66
 		}
ebda66
-#endif
ebda66
+
ebda66
 		if (prefs.hex_net_proxy_host[0] &&
ebda66
 			   prefs.hex_net_proxy_type > 0 &&
ebda66
 			   prefs.hex_net_proxy_use != 2) /* proxy is NOT dcc-only */
ebda66
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
ebda66
index 3d003eefc776..a7e3a15cac52 100644
ebda66
--- a/src/fe-gtk/setup.c
ebda66
+++ b/src/fe-gtk/setup.c
ebda66
@@ -614,9 +614,7 @@ static const char *const proxytypes[] =
ebda66
 	N_("SOCKS4"),
ebda66
 	N_("SOCKS5"),
ebda66
 	N_("HTTP"),
ebda66
-#ifdef USE_LIBPROXY
ebda66
 	N_("Auto"),
ebda66
-#endif
ebda66
 	NULL
ebda66
 };
ebda66
 
ebda66
-- 
ebda66
2.31.1
ebda66