changeset 31534:3e11fa72c5d8

merge of '8a2ad25fe0712bc0d47a1229671868560599a2cd' and '9da15614ca2aaddf25bfffea7e99eca752dd86b3'
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 03 May 2011 12:49:56 +0000
parents 5e574e30256b (current diff) 1b7c8904c066 (diff)
children 2f8448c4f43d 6ec53e134447 2ef7fb1f1154
files ChangeLog libpurple/proxy.c libpurple/proxy.h
diffstat 3 files changed, 61 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue May 03 05:42:13 2011 +0000
+++ b/ChangeLog	Tue May 03 12:49:56 2011 +0000
@@ -34,6 +34,9 @@
 	  (Kartik Mohta) (#1131)
 	* media: Allow libpurple and plugins to set SDES properties for RTP
 	  conferences. (Jakub Adam) (#12981)
+	* proxy: Add new "Tor/Privacy" proxy type that can be used to restrict
+	  operations that could leak potentially sensitive data (e.g. DNS queries).
+	  (#11110, #13928)
 
 	Gadu-Gadu:
 	* Allow showing your status only to buddies. (Mateusz Piękos) (#13358)
@@ -98,7 +101,7 @@
 	Windows-Specific Changes:
 	* Fix building libpurple with Visual C++ .NET 2005. This was accidentally
 	  broken in 2.7.11. (Florian Quèze)
-	* Build internal libgadu without -mms-bitfields, fixing several
+	* Build internal libgadu using packed structs, fixing several
 	  long-standing Gadu-Gadu issues. (#11958, #6297)
 
 version 2.7.11 (03/10/2011):
--- a/libpurple/proxy.c	Tue May 03 05:42:13 2011 +0000
+++ b/libpurple/proxy.c	Tue May 03 12:49:56 2011 +0000
@@ -2398,9 +2398,6 @@
 	return connect_data;
 }
 
-/*
- * Combine some of this code with purple_proxy_connect()
- */
 PurpleProxyConnectData *
 purple_proxy_connect_socks5(void *handle, PurpleProxyInfo *gpi,
 						  const char *host, int port,
@@ -2410,6 +2407,42 @@
 	return purple_proxy_connect_socks5_account(NULL, handle, gpi,
 						  host, port, connect_cb, data);
 }
+
+
+/* This is called when we connect to the SOCKS5 proxy server (through any
+ * relevant account proxy)
+ */
+static void socks5_connected_to_proxy(gpointer data, gint source,
+		const gchar *error_message) {
+	/* This is the PurpleProxyConnectData for the overall SOCKS5 connection */
+	PurpleProxyConnectData *connect_data = data;
+
+	/* Check that the overall SOCKS5 connection wasn't cancelled while we were
+	 * connecting to it (we don't have a way of associating the process of
+	 * connecting to the SOCKS5 server to the overall PurpleProxyConnectData)
+	 */
+	if (!PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data))
+		return;
+
+	if (error_message != NULL) {
+		purple_debug_error("proxy", "Unable to connect to SOCKS5 host.\n");
+		connect_data->connect_cb(connect_data->data, source, error_message);
+		return;
+	}
+
+	purple_debug_info("proxy", "Initiating SOCKS5 negotiation.\n");
+
+	purple_debug_info("proxy",
+			   "Connecting to %s:%d via %s:%d using SOCKS5\n",
+			   connect_data->host, connect_data->port,
+			   purple_proxy_info_get_host(connect_data->gpi),
+			   purple_proxy_info_get_port(connect_data->gpi));
+
+	connect_data->fd = source;
+
+	s5_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
+}
+
 /*
  * Combine some of this code with purple_proxy_connect()
  */
@@ -2421,6 +2454,7 @@
 						  gpointer data)
 {
 	PurpleProxyConnectData *connect_data;
+	PurpleProxyConnectData *account_proxy_conn_data;
 
 	g_return_val_if_fail(host       != NULL, NULL);
 	g_return_val_if_fail(port       >= 0,    NULL);
@@ -2437,17 +2471,26 @@
 	connect_data->gpi = gpi;
 	connect_data->account = account;
 
-	connect_data->query_data =
-			purple_dnsquery_a_account(account,
-					purple_proxy_info_get_host(gpi),
-					purple_proxy_info_get_port(gpi),
-					connection_host_resolved, connect_data);
-	if (connect_data->query_data == NULL)
-	{
+	/* If there is an account proxy, use it to connect to the desired SOCKS5
+	 * proxy.
+	 */
+	account_proxy_conn_data = purple_proxy_connect(connect_data->handle,
+				connect_data->account,
+				purple_proxy_info_get_host(connect_data->gpi),
+				purple_proxy_info_get_port(connect_data->gpi),
+				socks5_connected_to_proxy, connect_data);
+
+	if (account_proxy_conn_data == NULL) {
+		purple_debug_error("proxy", "Unable to initiate connection to account proxy.\n");
 		purple_proxy_connect_data_destroy(connect_data);
 		return NULL;
 	}
 
+	/* The API doesn't really provide us with a way to cancel the specific
+	 * proxy connection attempt (account_proxy_conn_data) when the overall
+	 * SOCKS5 connection (connect_data) attempt is cancelled :(
+	 */
+
 	handles = g_slist_prepend(handles, connect_data);
 
 	return connect_data;
--- a/libpurple/proxy.h	Tue May 03 05:42:13 2011 +0000
+++ b/libpurple/proxy.h	Tue May 03 12:49:56 2011 +0000
@@ -289,11 +289,15 @@
 /**
  * Makes a connection through a SOCKS5 proxy.
  *
+ * Note that if the account that is making the connection uses a proxy, this
+ * connection to a SOCKS5 proxy will be made through the account proxy.
+ *
  * @param handle     A handle that should be associated with this
  *                   connection attempt.  The handle can be used
  *                   to cancel the connection attempt using the
  *                   purple_proxy_connect_cancel_with_handle()
  *                   function.
+ * @param account    The account making the connection.
  * @param gpi        The PurpleProxyInfo specifying the proxy settings
  * @param host       The destination host.
  * @param port       The destination port.