changeset 23016:1c7896012802

applied changes from 43cf42d58f68c1f3f9ae27b10c66dbc351612f30 through 0130292e82764988f2d833f4a5d3ff5523f2eb7f
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 19 Jun 2008 02:55:19 +0000
parents c1b8ee4df034
children adbcf5b84438
files libpurple/proxy.c
diffstat 1 files changed, 46 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/proxy.c	Thu Jun 19 02:54:57 2008 +0000
+++ b/libpurple/proxy.c	Thu Jun 19 02:55:19 2008 +0000
@@ -837,33 +837,10 @@
 }
 
 static void
-http_canwrite(gpointer data, gint source, PurpleInputCondition cond)
-{
+http_start_connect_tunneling(PurpleProxyConnectData *connect_data) {
 	GString *request;
-	PurpleProxyConnectData *connect_data;
-	int error = ETIMEDOUT;
 	int ret;
 
-	connect_data = data;
-
-	purple_debug_info("proxy", "Connected to %s:%d.\n",
-		connect_data->host, connect_data->port);
-
-	if (connect_data->inpa > 0)
-	{
-		purple_input_remove(connect_data->inpa);
-		connect_data->inpa = 0;
-	}
-
-	ret = purple_input_get_error(connect_data->fd, &error);
-	if ((ret != 0) || (error != 0))
-	{
-		if (ret != 0)
-			error = errno;
-		purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
-		return;
-	}
-
 	purple_debug_info("proxy", "Using CONNECT tunneling for %s:%d\n",
 		connect_data->host, connect_data->port);
 
@@ -912,7 +889,45 @@
 
 	connect_data->inpa = purple_input_add(connect_data->fd,
 			PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
-	proxy_do_write(connect_data, connect_data->fd, cond);
+	proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
+}
+
+static void
+http_canwrite(gpointer data, gint source, PurpleInputCondition cond) {
+	PurpleProxyConnectData *connect_data = data;
+	int ret, error = ETIMEDOUT;
+
+	purple_debug_info("proxy", "Connected to %s:%d.\n",
+		connect_data->host, connect_data->port);
+
+	if (connect_data->inpa > 0)	{
+		purple_input_remove(connect_data->inpa);
+		connect_data->inpa = 0;
+	}
+
+	ret = purple_input_get_error(connect_data->fd, &error);
+	if (ret != 0 || error != 0) {
+		if (ret != 0)
+			error = errno;
+		purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
+		return;
+	}
+
+	if (connect_data->port == 80) {
+		/*
+		 * If we're trying to connect to something running on
+		 * port 80 then we assume the traffic using this
+		 * connection is going to be HTTP traffic.  If it's
+		 * not then this will fail (uglily).  But it's good
+		 * to avoid using the CONNECT method because it's
+		 * not always allowed.
+		 */
+		purple_debug_info("proxy", "HTTP proxy connection established\n");
+		purple_proxy_connect_data_connected(connect_data);
+	} else {
+		http_start_connect_tunneling(connect_data);
+	}
+
 }
 
 static void
@@ -940,39 +955,15 @@
 	fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
 #endif
 
-	if (connect(connect_data->fd, addr, addrlen) != 0)
-	{
-		if ((errno == EINPROGRESS) || (errno == EINTR))
-		{
+	if (connect(connect_data->fd, addr, addrlen) != 0) {
+		if (errno == EINPROGRESS || errno == EINTR) {
 			purple_debug_info("proxy", "Connection in progress\n");
 
-			if (connect_data->port != 80)
-			{
-				/* we need to do CONNECT first */
-				connect_data->inpa = purple_input_add(connect_data->fd,
-						PURPLE_INPUT_WRITE, http_canwrite, connect_data);
-			}
-			else
-			{
-				/*
-				 * If we're trying to connect to something running on
-				 * port 80 then we assume the traffic using this
-				 * connection is going to be HTTP traffic.  If it's
-				 * not then this will fail (uglily).  But it's good
-				 * to avoid using the CONNECT method because it's
-				 * not always allowed.
-				 */
-				purple_debug_info("proxy", "HTTP proxy connection established\n");
-				purple_proxy_connect_data_connected(connect_data);
-			}
-		}
-		else
-		{
+			connect_data->inpa = purple_input_add(connect_data->fd,
+					PURPLE_INPUT_WRITE, http_canwrite, connect_data);
+		} else
 			purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
-		}
-	}
-	else
-	{
+	} else {
 		purple_debug_info("proxy", "Connected immediately.\n");
 
 		http_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);