summaryrefslogtreecommitdiff
path: root/libpurple
diff options
context:
space:
mode:
authorDaniel Atallah <datallah@pidgin.im>2011-05-03 04:57:17 +0000
committerDaniel Atallah <datallah@pidgin.im>2011-05-03 04:57:17 +0000
commit0c7fd384bcf4405317a2c5fad801d85eef8a19e9 (patch)
tree1d3482a0dc04fbb02e6936ab451c81bd842f9e51 /libpurple
parent46499d89dd58ce36efd202e14c77bd0a1652fd47 (diff)
downloadpidgin-0c7fd384bcf4405317a2c5fad801d85eef8a19e9.tar.gz
proxy: Use account proxy when making standalone SOCKS5 connections.
This ends up being potentially weird in that you may end up tunnelling a SOCKS5 proxy connection though another SOCKS5 proxy. It may mean that non-IBB file xmpp transfers work more consistently on restricted networks, but may make the situation worse some situations e.g. when a proxy is required to connect to the xmpp server, but you want to send a file to someone on your local network. What it does do though is to allow you to prevent the streamhost from knowing where you're connecting from. Fixes #13928
Diffstat (limited to 'libpurple')
-rw-r--r--libpurple/proxy.c63
-rw-r--r--libpurple/proxy.h4
2 files changed, 57 insertions, 10 deletions
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
index 2ff562b41a..efdd877567 100644
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -2397,9 +2397,6 @@ purple_proxy_connect_udp(void *handle, PurpleAccount *account,
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,
@@ -2409,6 +2406,42 @@ purple_proxy_connect_socks5(void *handle, PurpleProxyInfo *gpi,
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()
*/
@@ -2420,6 +2453,7 @@ purple_proxy_connect_socks5_account(void *handle, PurpleAccount *account,
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);
@@ -2436,17 +2470,26 @@ purple_proxy_connect_socks5_account(void *handle, PurpleAccount *account,
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;
diff --git a/libpurple/proxy.h b/libpurple/proxy.h
index b1861dc3d6..279a04d78e 100644
--- a/libpurple/proxy.h
+++ b/libpurple/proxy.h
@@ -289,11 +289,15 @@ PurpleProxyConnectData *purple_proxy_connect_udp(void *handle,
/**
* 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.