/pidgin/main: 392525df2d0a: Merged in CMaiku/pidgin/purple-proxy...
Gary Kramlich
grim at reaperworld.com
Thu Jan 14 20:42:57 EST 2016
Changeset: 392525df2d0ab74f1c28e2bdd156ec7833239ac0
Author: Gary Kramlich <grim at reaperworld.com>
Date: 2016-01-14 19:42 -0600
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/392525df2d0a
Description:
Merged in CMaiku/pidgin/purple-proxy-to-gio (pull request #9)
Port libpurple proxy code to use Gio internally
diffstat:
libpurple/proxy.c | 2067 +++++++---------------------------------------------
libpurple/proxy.h | 46 +-
2 files changed, 297 insertions(+), 1816 deletions(-)
diffs (truncated from 2301 to 300 lines):
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -55,32 +55,9 @@ struct _PurpleProxyConnectData {
gchar *host;
int port;
int fd;
- int socket_type;
- guint inpa;
PurpleProxyInfo *gpi;
GCancellable *cancellable;
-
- /*
- * This list contains GInetAddress and they should be freed with
- * g_resolver_free_addresses when done with.
- */
- GList *hosts;
-
- PurpleProxyConnectData *child;
-
- /*
- * All of the following variables are used when establishing a
- * connection through a proxy.
- */
- guchar *write_buffer;
- gsize write_buf_len;
- gsize written_len;
- PurpleInputFunction read_cb;
- guchar *read_buffer;
- gsize read_buf_len;
- gsize read_len;
- PurpleAccount *account;
};
static const char * const socks5errors[] = {
@@ -99,8 +76,6 @@ static PurpleProxyInfo *global_proxy_inf
static GSList *handles = NULL;
-static void try_connect(PurpleProxyConnectData *connect_data);
-
/*
* TODO: Eventually (GObjectification) this bad boy will be removed, because it is
* a gross fix for a crashy problem.
@@ -584,8 +559,6 @@ purple_proxy_connect_data_destroy(Purple
connect_data->cancellable = NULL;
}
- g_resolver_free_addresses(connect_data->hosts);
-
g_free(connect_data->host);
g_free(connect_data);
}
@@ -602,72 +575,29 @@ purple_proxy_connect_data_destroy(Purple
* to another IP address.
*
* If an error message is passed in, then we know the connection
- * attempt failed. If the connection attempt failed and
- * connect_data->hosts is not empty then we try the next IP address.
- * If the connection attempt failed and we have no more hosts
- * try try then we call the callback with the given error message,
- * then destroy the connect_data.
+ * attempt failed. If so, we call the callback with the given
+ * error message, then destroy the connect_data.
*/
static void
purple_proxy_connect_data_disconnect(PurpleProxyConnectData *connect_data, const gchar *error_message)
{
- if (connect_data->child != NULL)
- {
- purple_proxy_connect_cancel(connect_data->child);
- connect_data->child = NULL;
- }
-
- if (connect_data->inpa > 0)
- {
- purple_input_remove(connect_data->inpa);
- connect_data->inpa = 0;
- }
-
if (connect_data->fd >= 0)
{
close(connect_data->fd);
connect_data->fd = -1;
}
- g_free(connect_data->write_buffer);
- connect_data->write_buffer = NULL;
-
- g_free(connect_data->read_buffer);
- connect_data->read_buffer = NULL;
-
if (error_message != NULL)
{
purple_debug_error("proxy", "Connection attempt failed: %s\n",
error_message);
- if (connect_data->hosts != NULL)
- try_connect(connect_data);
- else
- {
- /* Everything failed! Tell the originator of the request. */
- connect_data->connect_cb(connect_data->data, -1, error_message);
- purple_proxy_connect_data_destroy(connect_data);
- }
+
+ /* Everything failed! Tell the originator of the request. */
+ connect_data->connect_cb(connect_data->data, -1, error_message);
+ purple_proxy_connect_data_destroy(connect_data);
}
}
-/*
- * This calls purple_proxy_connect_data_disconnect(), but it lets you
- * specify the error_message using a printf()-like syntax.
- */
-static void
-purple_proxy_connect_data_disconnect_formatted(PurpleProxyConnectData *connect_data, const char *format, ...)
-{
- va_list args;
- gchar *tmp;
-
- va_start(args, format);
- tmp = g_strdup_vprintf(format, args);
- va_end(args);
-
- purple_proxy_connect_data_disconnect(connect_data, tmp);
- g_free(tmp);
-}
-
static void
purple_proxy_connect_data_connected(PurpleProxyConnectData *connect_data)
{
@@ -687,1572 +617,6 @@ purple_proxy_connect_data_connected(Purp
purple_proxy_connect_data_destroy(connect_data);
}
-static void
-socket_ready_cb(gpointer data, gint source, PurpleInputCondition cond)
-{
- PurpleProxyConnectData *connect_data = data;
- int error = 0;
- int ret;
-
- /* If the socket-connected message had already been triggered when connect_data
- * was destroyed via purple_proxy_connect_cancel(), we may get here with a freed connect_data.
- */
- if (!PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data))
- return;
-
- purple_debug_info("proxy", "Connecting to %s:%d.\n",
- connect_data->host, connect_data->port);
-
- /*
- * purple_input_get_error after a non-blocking connect returns -1 if something is
- * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
- * error holds what connect would have returned if it blocked until now.
- * Thus, error == 0 is success, error == EINPROGRESS means "try again",
- * and anything else is a real error.
- *
- * (error == EINPROGRESS can happen after a select because the kernel can
- * be overly optimistic sometimes. select is just a hint that you might be
- * able to do something.)
- */
- ret = purple_input_get_error(connect_data->fd, &error);
-
- if (ret == 0 && error == EINPROGRESS) {
- /* No worries - we'll be called again later */
- /* TODO: Does this ever happen? */
- purple_debug_info("proxy", "(ret == 0 && error == EINPROGRESS)\n");
- return;
- }
-
- if (ret != 0 || error != 0) {
- if (ret != 0)
- error = errno;
- purple_debug_error("proxy", "Error connecting to %s:%d (%s).\n",
- connect_data->host, connect_data->port, g_strerror(error));
-
- purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
- return;
- }
-
- purple_proxy_connect_data_connected(connect_data);
-}
-
-static gboolean
-clean_connect(gpointer data)
-{
- purple_proxy_connect_data_connected(data);
-
- return FALSE;
-}
-
-static void
-proxy_connect_udp_none(PurpleProxyConnectData *connect_data, common_sockaddr_t *addr, socklen_t addrlen)
-{
- purple_debug_info("proxy", "UDP Connecting to %s:%d with no proxy\n",
- connect_data->host, connect_data->port);
-
- connect_data->fd = socket(addr->sa.sa_family, SOCK_DGRAM, 0);
- if (connect_data->fd < 0)
- {
- purple_proxy_connect_data_disconnect_formatted(connect_data,
- _("Unable to create socket: %s"), g_strerror(errno));
- return;
- }
- _purple_network_set_common_socket_flags(connect_data->fd);
-
- if (connect(connect_data->fd, &addr->sa, addrlen) != 0)
- {
- if ((errno == EINPROGRESS) || (errno == EINTR))
- {
- purple_debug_info("proxy", "UDP connection in progress\n");
- connect_data->inpa = purple_input_add(connect_data->fd,
- PURPLE_INPUT_WRITE, socket_ready_cb, connect_data);
- }
- else
- {
- purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
- }
- }
- else
- {
- /*
- * The connection happened IMMEDIATELY... strange, but whatever.
- */
- int error = ETIMEDOUT;
- int ret;
-
- purple_debug_info("proxy", "UDP Connected immediately.\n");
-
- 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;
- }
-
- /*
- * We want to call the "connected" callback eventually, but we
- * don't want to call it before we return, just in case.
- */
- purple_timeout_add(10, clean_connect, connect_data);
- }
-}
-
-static void
-proxy_connect_none(PurpleProxyConnectData *connect_data, common_sockaddr_t *addr, socklen_t addrlen)
-{
- purple_debug_info("proxy", "Connecting to %s:%d with no proxy\n",
- connect_data->host, connect_data->port);
-
- connect_data->fd = socket(addr->sa.sa_family, SOCK_STREAM, 0);
- if (connect_data->fd < 0)
- {
- purple_proxy_connect_data_disconnect_formatted(connect_data,
- _("Unable to create socket: %s"), g_strerror(errno));
- return;
- }
- _purple_network_set_common_socket_flags(connect_data->fd);
-
- if (connect(connect_data->fd, &addr->sa, addrlen) != 0)
- {
- if ((errno == EINPROGRESS) || (errno == EINTR))
- {
- purple_debug_info("proxy", "Connection in progress\n");
- connect_data->inpa = purple_input_add(connect_data->fd,
- PURPLE_INPUT_WRITE, socket_ready_cb, connect_data);
- }
- else
- {
- purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
- }
- }
- else
- {
- /*
- * The connection happened IMMEDIATELY... strange, but whatever.
- */
- int error = ETIMEDOUT;
- int ret;
-
- purple_debug_info("proxy", "Connected immediately.\n");
-
- 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;
- }
-
- /*
- * We want to call the "connected" callback eventually, but we
- * don't want to call it before we return, just in case.
- */
More information about the Commits
mailing list