pidgin: 0130292e: Rearrange some of the HTTP proxy handlin...
datallah at pidgin.im
datallah at pidgin.im
Tue May 20 15:56:03 EDT 2008
-----------------------------------------------------------------
Revision: 0130292e82764988f2d833f4a5d3ff5523f2eb7f
Ancestor: 43cf42d58f68c1f3f9ae27b10c66dbc351612f30
Author: datallah at pidgin.im
Date: 2008-05-20T19:49:26
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0130292e82764988f2d833f4a5d3ff5523f2eb7f
Modified files:
libpurple/proxy.c
ChangeLog:
Rearrange some of the HTTP proxy handling to make sure that we're actually
connected to the proxy server before calling the callback (in the case where
we were trying to bypass CONNECT tunneling, that wasn't happening).
Thanks to dasvo for tracking down what was happening. Fixes #5057.
-------------- next part --------------
============================================================
--- libpurple/proxy.c 5cb7ec6c3379d7a141cf160882514cda8aca8262
+++ libpurple/proxy.c 079719d988d356ed029d43599fda286cb54b33bb
@@ -837,33 +837,10 @@ static void
}
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,10 +889,48 @@ http_canwrite(gpointer data, gint source
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
proxy_connect_http(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
{
int flags;
@@ -940,39 +955,15 @@ proxy_connect_http(PurpleProxyConnectDat
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);
More information about the Commits
mailing list