changeset 14109:a21da42126d6

[gaim-migrate @ 16743] Almost all of oscar is using gaim_proxy_connect_cancel() now committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 14 Aug 2006 06:24:17 +0000
parents 7a205b430d19
children 5cefeb370262
files src/protocols/oscar/flap_connection.c src/protocols/oscar/oscar.c src/protocols/oscar/oscar.h src/protocols/oscar/peer.c src/protocols/oscar/peer.h src/protocols/oscar/peer_proxy.c
diffstat 6 files changed, 110 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/oscar/flap_connection.c	Mon Aug 14 04:43:38 2006 +0000
+++ b/src/protocols/oscar/flap_connection.c	Mon Aug 14 06:24:17 2006 +0000
@@ -21,6 +21,7 @@
 #include "oscar.h"
 
 #include "eventloop.h"
+#include "proxy.h"
 
 #ifndef _WIN32
 #include <netdb.h>
@@ -131,21 +132,37 @@
 /**
  * Close (but not free) a connection.
  *
- * This leaves everything untouched except for setting the fd
- * to -1 (used to recognize dead connections).
+ * This cancels any currently pending connection attempt,
+ * closes any open fd and frees the auth cookie.
  *
  * @param conn The connection to close.
  */
 void
 flap_connection_close(OscarData *od, FlapConnection *conn)
 {
-	if (conn->fd == -1)
-		return;
+	if (conn->connect_info != NULL)
+	{
+		gaim_proxy_connect_cancel(conn->connect_info);
+		conn->connect_info = NULL;
+	}
 
-	if (conn->type == SNAC_FAMILY_LOCATE)
-		flap_connection_send_close(od, conn);
+	if (conn->connect_data != NULL)
+	{
+		if (conn->type == SNAC_FAMILY_CHAT)
+		{
+			oscar_chat_destroy(conn->connect_data);
+			conn->connect_data = NULL;
+		}
+	}
 
-	close(conn->fd);
+	if (conn->fd != -1)
+	{
+		if (conn->type == SNAC_FAMILY_LOCATE)
+			flap_connection_send_close(od, conn);
+
+		close(conn->fd);
+		conn->fd = -1;
+	}
 }
 
 static void
@@ -188,6 +205,8 @@
 
 	flap_connection_close(od, conn);
 
+	g_free(conn->cookie);
+
 	if (conn->watcher_incoming != 0)
 		gaim_input_remove(conn->watcher_incoming);
 	if (conn->watcher_outgoing != 0)
--- a/src/protocols/oscar/oscar.c	Mon Aug 14 04:43:38 2006 +0000
+++ b/src/protocols/oscar/oscar.c	Mon Aug 14 06:24:17 2006 +0000
@@ -76,35 +76,11 @@
 static guint8 features_icq_offline[] = {0x01};
 static guint8 ck[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
 
-typedef struct _NewFlapConnectionData NewFlapConnectionData;
-struct _NewFlapConnectionData
-{
-	GaimConnection *gc;
-	FlapConnection *conn;
-	guint16 cookielen;
-	guint8 *cookie;
-	gpointer data;
-};
-
 struct create_room {
 	char *name;
 	int exchange;
 };
 
-struct chat_connection
-{
-	char *name;
-	char *show; /* AOL did something funny to us */
-	guint16 exchange;
-	guint16 instance;
-	FlapConnection *conn;
-	int id;
-	GaimConnection *gc; /* i hate this. */
-	GaimConversation *conv; /* bah. */
-	int maxlen;
-	int maxvis;
-};
-
 struct oscar_ask_directim_data
 {
 	OscarData *od;
@@ -903,7 +879,7 @@
 	return NULL;
 }
 
-static void
+void
 oscar_chat_destroy(struct chat_connection *cc)
 {
 	g_free(cc->name);
@@ -925,46 +901,25 @@
 	oscar_chat_destroy(cc);
 }
 
-static void
-destroy_new_conn_data(NewFlapConnectionData *new_conn_data)
-{
-	if ((new_conn_data->data != NULL) &&
-		(new_conn_data->conn->type == SNAC_FAMILY_CHAT))
-	{
-		oscar_chat_destroy(new_conn_data->data);
-	}
-	g_free(new_conn_data->cookie);
-	g_free(new_conn_data);
-}
-
 /**
  * This is the callback function anytime gaim_proxy_connect()
  * establishes a new TCP connection with an oscar host.  Depending
  * on the type of host, we do a few different things here.
  */
 static void
-connection_established_cb(gpointer data, gint source)
+connection_established_cb(gpointer data, gint source, const gchar *error_message)
 {
-	NewFlapConnectionData *new_conn_data;
 	GaimConnection *gc;
 	OscarData *od;
 	GaimAccount *account;
 	FlapConnection *conn;
 
-	new_conn_data = data;
-	gc = new_conn_data->gc;
-
-	if (!GAIM_CONNECTION_IS_VALID(gc))
-	{
-		if (source >= 0)
-			close(source);
-		destroy_new_conn_data(new_conn_data);
-		return;
-	}
-
-	od = gc->proto_data;
+	conn = data;
+	od = conn->od;
+	gc = od->gc;
 	account = gaim_connection_get_account(gc);
-	conn = new_conn_data->conn;
+
+	conn->connect_info = NULL;
 	conn->fd = source;
 
 	if (source < 0)
@@ -978,7 +933,6 @@
 		else /* Maybe we should call this for BOS connections, too? */
 			flap_connection_schedule_destroy(conn,
 					OSCAR_DISCONNECT_COULD_NOT_CONNECT);
-		destroy_new_conn_data(new_conn_data);
 		return;
 	}
 
@@ -986,7 +940,7 @@
 			conn->type);
 	conn->watcher_incoming = gaim_input_add(conn->fd,
 			GAIM_INPUT_READ, flap_connection_recv_cb, conn);
-	if (new_conn_data->cookie == NULL)
+	if (conn->cookie == NULL)
 	{
 		if (!aim_sn_is_icq(gaim_account_get_username(account)))
 			/*
@@ -997,8 +951,12 @@
 			flap_connection_send_version(od, conn);
 	}
 	else
+	{
 		flap_connection_send_version_with_cookie(od, conn,
-				new_conn_data->cookielen, new_conn_data->cookie);
+				conn->cookielen, conn->cookie);
+		g_free(conn->cookie);
+		conn->cookie = NULL;
+	}
 
 	if (conn->type == SNAC_FAMILY_AUTH)
 	{
@@ -1014,11 +972,9 @@
 	}
 	else if (conn->type == SNAC_FAMILY_CHAT)
 	{
-		od->oscar_chats = g_slist_append(od->oscar_chats, new_conn_data->data);
-		new_conn_data->data = NULL;
-	}
-
-	destroy_new_conn_data(new_conn_data);
+		od->oscar_chats = g_slist_append(od->oscar_chats, conn->connect_data);
+		conn->connect_data = NULL;
+	}
 }
 
 static void
@@ -1152,7 +1108,7 @@
 {
 	GaimConnection *gc;
 	OscarData *od;
-	NewFlapConnectionData *new_conn_data;
+	FlapConnection *newconn;
 
 	gc = gaim_account_get_connection(account);
 	od = gc->proto_data = oscar_data_new();
@@ -1240,17 +1196,12 @@
 	/* Connect to core Gaim signals */
 	gaim_prefs_connect_callback(gc, "/plugins/prpl/oscar/recent_buddies", recent_buddies_cb, gc);
 
-	new_conn_data = g_new(NewFlapConnectionData, 1);
-	new_conn_data->gc = gc;
-	new_conn_data->conn = flap_connection_new(od, SNAC_FAMILY_AUTH);
-	new_conn_data->cookielen = 0;
-	new_conn_data->cookie = NULL;
-	new_conn_data->data = NULL;
-
-	if (gaim_proxy_connect(account,
+	newconn = flap_connection_new(od, SNAC_FAMILY_AUTH);
+	newconn->connect_info = gaim_proxy_connect(account,
 			gaim_account_get_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER),
 			gaim_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT),
-			connection_established_cb, new_conn_data) == NULL)
+			connection_established_cb, newconn);
+	if (newconn->connect_info == NULL)
 	{
 		gaim_connection_error(gc, _("Couldn't connect to host"));
 		return;
@@ -1295,8 +1246,7 @@
 	GaimAccount *account = gc->account;
 	char *host; int port;
 	int i;
-	GaimProxyConnectInfo *connect_info;
-	NewFlapConnectionData *new_conn_data;
+	FlapConnection *newconn;
 	va_list ap;
 	struct aim_authresp_info *info;
 
@@ -1361,16 +1311,14 @@
 		}
 	}
 	host = g_strndup(info->bosip, i);
-	new_conn_data = g_new(NewFlapConnectionData, 1);
-	new_conn_data->gc = gc;
-	new_conn_data->conn = flap_connection_new(od, SNAC_FAMILY_LOCATE);
-	new_conn_data->cookielen = info->cookielen;
-	new_conn_data->cookie = g_memdup(info->cookie, info->cookielen);
-	new_conn_data->data = NULL;
-	connect_info = gaim_proxy_connect(gc->account, host, port,
-			connection_established_cb, new_conn_data);
+	newconn = flap_connection_new(od, SNAC_FAMILY_LOCATE);
+	newconn->cookielen = info->cookielen;
+	newconn->cookie = g_memdup(info->cookie, info->cookielen);
+	newconn->connect_info = gaim_proxy_connect(account, host, port,
+			connection_established_cb, newconn);
 	g_free(host);
-	if (connect_info == NULL) {
+	if (newconn->connect_info == NULL)
+	{
 		gaim_connection_error(gc, _("Could Not Connect"));
 		od->killme = TRUE;
 		return 0;
@@ -1482,11 +1430,18 @@
 }
 
 static void
-straight_to_hell(gpointer data, gint source)
+straight_to_hell(gpointer data, gint source, const gchar *error_message)
 {
 	struct pieceofcrap *pos = data;
 	gchar *buf;
 
+	if (!GAIM_CONNECTION_IS_VALID(pos->gc))
+	{
+		g_free(pos->modname);
+		g_free(pos);
+		return;
+	}
+
 	pos->fd = source;
 
 	if (source < 0) {
@@ -1496,8 +1451,7 @@
 							_("Gaim was unable to get a valid AIM login hash."),
 							buf);
 		g_free(buf);
-		if (pos->modname)
-			g_free(pos->modname);
+		g_free(pos->modname);
 		g_free(pos);
 		return;
 	}
@@ -1506,8 +1460,7 @@
 			pos->offset, pos->len, pos->modname ? pos->modname : "");
 	write(pos->fd, buf, strlen(buf));
 	g_free(buf);
-	if (pos->modname)
-		g_free(pos->modname);
+	g_free(pos->modname);
 	pos->inpa = gaim_input_add(pos->fd, GAIM_INPUT_READ, damn_you, pos);
 	return;
 }
@@ -1573,6 +1526,7 @@
 	pos->len = len;
 	pos->modname = g_strdup(modname);
 
+	/* TODO: Keep track of this return value. */
 	if (gaim_proxy_connect(pos->gc->account, "gaim.sourceforge.net", 80,
 			straight_to_hell, pos) == NULL)
 	{
@@ -1622,7 +1576,7 @@
 	GaimAccount *account = gaim_connection_get_account(gc);
 	char *host, *separator;
 	int port;
-	NewFlapConnectionData *new_conn_data;
+	FlapConnection *newconn;
 	va_list ap;
 	struct aim_redirect_data *redir;
 
@@ -1642,36 +1596,30 @@
 
 	gaim_debug_info("oscar", "Connecting to FLAP server %s:%d of type 0x%04hx\n",
 					host, port, redir->group);
-	new_conn_data = g_new(NewFlapConnectionData, 1);
-	new_conn_data->gc = gc;
-	new_conn_data->conn = flap_connection_new(od, redir->group);
-	new_conn_data->cookielen = redir->cookielen;
-	new_conn_data->cookie = g_memdup(redir->cookie, redir->cookielen);
-	if (new_conn_data->conn->type == SNAC_FAMILY_CHAT)
+	newconn = flap_connection_new(od, redir->group);
+	newconn->cookielen = redir->cookielen;
+	newconn->cookie = g_memdup(redir->cookie, redir->cookielen);
+	if (newconn->type == SNAC_FAMILY_CHAT)
 	{
 		struct chat_connection *cc;
 		cc = g_new0(struct chat_connection, 1);
-		cc->conn = new_conn_data->conn;
+		cc->conn = newconn;
 		cc->gc = gc;
 		cc->name = g_strdup(redir->chat.room);
 		cc->exchange = redir->chat.exchange;
 		cc->instance = redir->chat.instance;
 		cc->show = extract_name(redir->chat.room);
-		new_conn_data->data = cc;
+		newconn->connect_data = cc;
 		gaim_debug_info("oscar", "Connecting to chat room %s exchange %hu\n", cc->name, cc->exchange);
 	}
-	else
+
+	newconn->connect_info = gaim_proxy_connect(account, host, port,
+			connection_established_cb, newconn);
+	if (newconn->connect_info == NULL)
 	{
-		new_conn_data->data = NULL;
-	}
-
-	if (gaim_proxy_connect(account, host, port, connection_established_cb, new_conn_data) == NULL)
-	{
-		flap_connection_schedule_destroy(new_conn_data->conn,
-				OSCAR_DISCONNECT_COULD_NOT_CONNECT);
+		flap_connection_schedule_destroy(newconn, OSCAR_DISCONNECT_COULD_NOT_CONNECT);
 		gaim_debug_error("oscar", "Unable to connect to FLAP server "
 				"of type 0x%04hx\n", redir->group);
-		destroy_new_conn_data(new_conn_data);
 	}
 	g_free(host);
 
--- a/src/protocols/oscar/oscar.h	Mon Aug 14 04:43:38 2006 +0000
+++ b/src/protocols/oscar/oscar.h	Mon Aug 14 06:24:17 2006 +0000
@@ -33,6 +33,7 @@
 #include "debug.h"
 #include "eventloop.h"
 #include "internal.h"
+#include "proxy.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -366,6 +367,12 @@
 	guint destroy_timeout;
 	OscarDisconnectReason disconnect_reason;
 
+	/* A few variables that are only used when connecting */
+	GaimProxyConnectInfo *connect_info;
+	guint16 cookielen;
+	guint8 *cookie;
+	gpointer connect_data;
+
 	int fd;
 	FlapFrame buffer_incoming;
 	GaimCircBuffer *buffer_outgoing;
@@ -661,6 +668,9 @@
 	guint32 minmsginterval; /* in milliseconds? */
 };
 
+/*
+ * TODO: Should probably combine this with struct chat_connection.
+ */
 struct aim_chat_roominfo
 {
 	guint16 exchange;
@@ -668,6 +678,25 @@
 	guint16 instance;
 };
 
+struct chat_connection
+{
+	char *name;
+	char *show; /* AOL did something funny to us */
+	guint16 exchange;
+	guint16 instance;
+	FlapConnection *conn;
+	int id;
+	GaimConnection *gc;
+	GaimConversation *conv;
+	int maxlen;
+	int maxvis;
+};
+
+/*
+ * All this chat struct stuff should be in family_chat.c
+ */
+void oscar_chat_destroy(struct chat_connection *cc);
+
 #define AIM_IMFLAGS_AWAY				0x0001 /* mark as an autoreply */
 #define AIM_IMFLAGS_ACK					0x0002 /* request a receipt notice */
 #define AIM_IMFLAGS_BUDDYREQ			0x0010 /* buddy icon requested */
--- a/src/protocols/oscar/peer.c	Mon Aug 14 04:43:38 2006 +0000
+++ b/src/protocols/oscar/peer.c	Mon Aug 14 06:24:17 2006 +0000
@@ -482,7 +482,7 @@
  * either connected or failed to connect.
  */
 static void
-peer_connection_established_cb(gpointer data, gint source)
+peer_connection_established_cb(gpointer data, gint source, const gchar *error_message)
 {
 	PeerConnection *conn;
 
--- a/src/protocols/oscar/peer.h	Mon Aug 14 04:43:38 2006 +0000
+++ b/src/protocols/oscar/peer.h	Mon Aug 14 06:24:17 2006 +0000
@@ -265,7 +265,7 @@
 /*
  * For peer proxying
  */
-void peer_proxy_connection_established_cb(gpointer data, gint source);
+void peer_proxy_connection_established_cb(gpointer data, gint source, const gchar *error_message);
 
 #if 0
 int peer_oft_sendheader(OscarData *od, guint16 type, PeerConnection *peer_connection);
--- a/src/protocols/oscar/peer_proxy.c	Mon Aug 14 04:43:38 2006 +0000
+++ b/src/protocols/oscar/peer_proxy.c	Mon Aug 14 06:24:17 2006 +0000
@@ -326,7 +326,7 @@
  * either connected or failed to connect.
  */
 void
-peer_proxy_connection_established_cb(gpointer data, gint source)
+peer_proxy_connection_established_cb(gpointer data, gint source, const gchar *error_message)
 {
 	PeerConnection *conn;