changeset 10296:a7b2fd5efcf2

[gaim-migrate @ 11476] Some "random updates" updates from patch 1077274 by Felipe Contreras: "Some changes in the behaviour of slpcalls (for FT), free some unused structures and properly close switchboard connections." Looks good to me, and seems to have fixed a mysterious FT problem that I had been pretending didn't exist. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 02 Dec 2004 16:07:26 +0000
parents 0cf2a686266e
children ec140184437b
files src/protocols/msn/history.c src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/msn/servconn.c src/protocols/msn/session.c src/protocols/msn/session.h src/protocols/msn/slp.c src/protocols/msn/slpcall.c src/protocols/msn/slpcall.h src/protocols/msn/slplink.c
diffstat 10 files changed, 130 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/history.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/history.c	Thu Dec 02 16:07:26 2004 +0000
@@ -67,7 +67,12 @@
 void
 msn_history_add(MsnHistory *history, MsnTransaction *trans)
 {
-	GQueue *queue = history->queue;
+	GQueue *queue;
+
+	g_return_if_fail(history != NULL);
+	g_return_if_fail(trans   != NULL);
+
+	queue = history->queue;
 
 	trans->trId = history->trId++;
 
--- a/src/protocols/msn/msn.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/msn.c	Thu Dec 02 16:07:26 2004 +0000
@@ -1255,18 +1255,16 @@
 
 	cmdproc = swboard->servconn->cmdproc;
 
+#if 0
 	if (swboard->current_users == 1)
 	{
-		/* This must happen on both IM's and Chat's, right? */
-		GaimAccount *account;
-
-		account = gaim_connection_get_account(gc);
-
-		msn_cmdproc_send_quick(cmdproc, "BYE", "%s",
-							   gaim_account_get_username(account));
-
+		msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL);
 		msn_switchboard_destroy(swboard);
 	}
+#else
+	msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL);
+	msn_switchboard_destroy(swboard);
+#endif
 }
 
 static void
--- a/src/protocols/msn/notification.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/notification.c	Thu Dec 02 16:07:26 2004 +0000
@@ -30,6 +30,7 @@
 
 #include "userlist.h"
 #include "sync.h"
+#include "slplink.h"
 
 #define BUDDY_ALIAS_MAXLEN 388
 
@@ -447,9 +448,17 @@
 {
 	GaimAccount *account;
 
+	MsnSlpLink *slplink;
+
 	account = cmdproc->session->account;
 
 	gaim_prpl_got_user_status(account, cmd->params[0], "offline", NULL);
+
+	slplink = msn_session_find_slplink(cmdproc->session, cmd->params[0]);
+
+	if (slplink != NULL)
+		msn_slplink_destroy(slplink);
+
 }
 
 /*
@@ -1143,21 +1152,17 @@
 static void
 connect_cb(MsnServConn *servconn)
 {
-	MsnNotification *notification;
 	MsnCmdProc *cmdproc;
 	MsnSession *session;
 	GaimAccount *account;
-	GaimConnection *gc;
 	char **a, **c, *vers;
 	int i;
 
 	g_return_if_fail(servconn != NULL);
 
-	notification = servconn->data;
 	cmdproc = servconn->cmdproc;
 	session = servconn->session;
 	account = session->account;
-	gc = gaim_account_get_connection(account);
 
 	/* Allocate an array for CVR0, NULL, and all the versions */
 	a = c = g_new0(char *, session->protocol_ver - 8 + 3);
@@ -1180,11 +1185,6 @@
 	if (session->user == NULL)
 		session->user = msn_user_new(session->userlist,
 									 gaim_account_get_username(account), NULL);
-
-#if 0
-	gaim_connection_update_progress(gc, _("Syncing with server"),
-									4, MSN_CONNECT_STEPS);
-#endif
 }
 
 void
--- a/src/protocols/msn/servconn.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/servconn.c	Thu Dec 02 16:07:26 2004 +0000
@@ -27,85 +27,6 @@
 
 static void read_cb(gpointer data, gint source, GaimInputCondition cond);
 
-static void
-show_error(MsnServConn *servconn)
-{
-	GaimConnection *gc;
-	char *tmp;
-	char *cmd;
-
-	const char *names[] = { "Notification", "Switchboard" };
-	const char *name;
-
-	gc = gaim_account_get_connection(servconn->session->account);
-	name = names[servconn->type];
-
-	switch (servconn->cmdproc->error)
-	{
-		case MSN_ERROR_CONNECT:
-			tmp = g_strdup_printf(_("Unable to connect to %s server"),
-								  name);
-			break;
-		case MSN_ERROR_WRITE:
-			tmp = g_strdup_printf(_("Error writing to %s server"), name);
-			break;
-		case MSN_ERROR_READ:
-			cmd = servconn->cmdproc->last_trans;
-			tmp = g_strdup_printf(_("Error reading from %s server"), name);
-			gaim_debug_info("msn", "Last command was: %s\n", cmd);
-			break;
-		default:
-			tmp = g_strdup_printf(_("Unknown error from %s server"), name);
-			break;
-	}
-
-	if (servconn->type != MSN_SERVER_SB)
-	{
-		gaim_connection_error(gc, tmp);
-	}
-	else
-	{
-		MsnSwitchBoard *swboard;
-		swboard = servconn->data;
-		swboard->error = MSN_SB_ERROR_CONNECTION;
-		/*
-		GaimAccount *account;
-		char *primary;
-
-		account = gaim_connection_get_account(gc);
-		primary = g_strdup_printf(_("MSN error for account %s"),
-								  gaim_account_get_username(account));
-
-		gaim_notify_error(gc, NULL, primary, tmp);
-
-		g_free(primary);
-		*/
-	}
-
-	g_free(tmp);
-}
-
-static void
-connect_cb(gpointer data, gint source, GaimInputCondition cond)
-{
-	MsnServConn *servconn = data;
-
-	servconn->fd = source;
-
-	if (source > 0)
-	{
-		/* Someone wants to know we connected. */
-		servconn->connect_cb(servconn);
-		servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ,
-										read_cb, data);
-	}
-	else
-	{
-		servconn->cmdproc->error = MSN_ERROR_CONNECT;
-		show_error(servconn);
-	}
-}
-
 MsnServConn *
 msn_servconn_new(MsnSession *session, MsnServConnType type)
 {
@@ -149,15 +70,77 @@
 	if (servconn->http_data != NULL)
 		g_free(servconn->http_data);
 
-#if 0
-	if (servconn->rx_buf != NULL)
-		g_free(servconn->rx_buf);
-#endif
-
 	msn_cmdproc_destroy(servconn->cmdproc);
 	g_free(servconn);
 }
 
+static void
+show_error(MsnServConn *servconn)
+{
+	GaimConnection *gc;
+	char *tmp;
+	char *cmd;
+
+	const char *names[] = { "Notification", "Switchboard" };
+	const char *name;
+
+	gc = gaim_account_get_connection(servconn->session->account);
+	name = names[servconn->type];
+
+	switch (servconn->cmdproc->error)
+	{
+		case MSN_ERROR_CONNECT:
+			tmp = g_strdup_printf(_("Unable to connect to %s server"),
+								  name);
+			break;
+		case MSN_ERROR_WRITE:
+			tmp = g_strdup_printf(_("Error writing to %s server"), name);
+			break;
+		case MSN_ERROR_READ:
+			cmd = servconn->cmdproc->last_trans;
+			tmp = g_strdup_printf(_("Error reading from %s server"), name);
+			gaim_debug_info("msn", "Last command was: %s\n", cmd);
+			break;
+		default:
+			tmp = g_strdup_printf(_("Unknown error from %s server"), name);
+			break;
+	}
+
+	if (servconn->type != MSN_SERVER_SB)
+	{
+		gaim_connection_error(gc, tmp);
+	}
+	else
+	{
+		MsnSwitchBoard *swboard;
+		swboard = servconn->data;
+		swboard->error = MSN_SB_ERROR_CONNECTION;
+	}
+
+	g_free(tmp);
+}
+
+static void
+connect_cb(gpointer data, gint source, GaimInputCondition cond)
+{
+	MsnServConn *servconn = data;
+
+	servconn->fd = source;
+
+	if (source > 0)
+	{
+		/* Someone wants to know we connected. */
+		servconn->connect_cb(servconn);
+		servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ,
+										read_cb, data);
+	}
+	else
+	{
+		servconn->cmdproc->error = MSN_ERROR_CONNECT;
+		show_error(servconn);
+	}
+}
+
 gboolean
 msn_servconn_connect(MsnServConn *servconn, const char *host, int port)
 {
--- a/src/protocols/msn/session.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/session.c	Thu Dec 02 16:07:26 2004 +0000
@@ -58,6 +58,8 @@
 {
 	g_return_if_fail(session != NULL);
 
+	session->destroying = TRUE;
+
 	if (session->connected)
 		msn_session_disconnect(session);
 
--- a/src/protocols/msn/session.h	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/session.h	Thu Dec 02 16:07:26 2004 +0000
@@ -51,7 +51,8 @@
 	int dispatch_port;
 
 	gboolean connected;
-	gboolean logged_in; /* temporal flag to ignore local blist adds */
+	gboolean logged_in; /**< A temporal flag to ignore local buddy list adds. */
+	gboolean destroying; /**< A flag that states if the session is being destroyed. */
 
 	MsnNotification *notification;
 	MsnNexus *nexus;
--- a/src/protocols/msn/slp.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/slp.c	Thu Dec 02 16:07:26 2004 +0000
@@ -331,6 +331,8 @@
 		slpcall->progress_cb = msn_xfer_progress_cb;
 		slpcall->branch = g_strdup(branch);
 
+		slpcall->pending = TRUE;
+
 		xfer = gaim_xfer_new(account, GAIM_XFER_RECEIVE,
 							 slpcall->slplink->remote_user);
 
@@ -935,6 +937,10 @@
 
 	userlist = slpcall->slplink->session->userlist;
 
+	/* If the session is being destroyed we better stop doing anything. */
+	if (slpcall->slplink->session->destroying)
+		return;
+
 	/* Free one window slot */
 	userlist->buddy_icon_window++;
 
--- a/src/protocols/msn/slpcall.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/slpcall.c	Thu Dec 02 16:07:26 2004 +0000
@@ -189,11 +189,21 @@
 gboolean
 msn_slp_call_timeout(gpointer data)
 {
+	MsnSlpCall *slpcall;
+
 	gaim_debug_info("msn", "slpcall timeout\n");
 
-	msn_slp_call_destroy(data);
+	slpcall = data;
 
-	return FALSE;
+	if (!slpcall->pending && !slpcall->progress)
+	{
+		msn_slp_call_destroy(slpcall);
+		return FALSE;
+	}
+
+	slpcall->progress = FALSE;
+
+	return TRUE;
 }
 
 MsnSlpCall *
@@ -241,14 +251,5 @@
 	}
 #endif
 
-	if (slpcall != NULL)
-	{
-		if (slpcall->timer)
-			gaim_timeout_remove(slpcall->timer);
-
-		slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT,
-										  msn_slp_call_timeout, slpcall);
-	}
-
 	return slpcall;
 }
--- a/src/protocols/msn/slpcall.h	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/slpcall.h	Thu Dec 02 16:07:26 2004 +0000
@@ -57,6 +57,15 @@
 	long session_id;
 	long app_id;
 
+	gboolean pending; /**< A flag that states if we should wait for this
+						slpcall to start and do not time out. */
+	gboolean progress; /**< A flag that states if there has been progress since
+						 the last time out. */
+	gboolean wasted; /**< A flag that states if this slpcall is going to be
+					   destroyed. */
+	gboolean started; /**< A flag that states if this slpcall's session has
+						been initiated. */
+
 	void (*progress_cb)(MsnSlpCall *slpcall,
 						gsize total_length, gsize len, gsize offset);
 	void (*session_init_cb)(MsnSlpSession *slpsession);
@@ -68,8 +77,6 @@
 
 	MsnSlpCb cb;
 	void (*end_cb)(MsnSlpCall *slpcall);
-	gboolean wasted;
-	gboolean started;
 
 	int timer;
 };
--- a/src/protocols/msn/slplink.c	Thu Dec 02 13:03:23 2004 +0000
+++ b/src/protocols/msn/slplink.c	Thu Dec 02 16:07:26 2004 +0000
@@ -59,6 +59,8 @@
 {
 	MsnSlpLink *slplink;
 
+	g_return_val_if_fail(session != NULL, NULL);
+
 	slplink = g_new0(MsnSlpLink, 1);
 
 	slplink->session = session;
@@ -80,6 +82,8 @@
 {
 	MsnSession *session;
 
+	g_return_if_fail(slplink != NULL);
+
 	session = slplink->session;
 
 	if (slplink->local_user != NULL)
@@ -91,6 +95,9 @@
 	if (slplink->directconn != NULL)
 		msn_directconn_destroy(slplink->directconn);
 
+	while (slplink->slp_calls != NULL)
+		msn_slp_call_destroy(slplink->slp_calls->data);
+
 	session->slplinks =
 		g_list_remove(session->slplinks, slplink);
 
@@ -288,12 +295,7 @@
 
 	if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL))
 	{
-		if (slpmsg->slpcall->timer)
-		{
-			gaim_timeout_remove(slpmsg->slpcall->timer);
-			slpmsg->slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT,
-													  msn_slp_call_timeout, slpmsg->slpcall);
-		}
+		slpmsg->slpcall->progress = TRUE;
 
 		if (slpmsg->slpcall->progress_cb != NULL)
 		{
@@ -525,12 +527,7 @@
 
 	if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL))
 	{
-		if (slpmsg->slpcall->timer)
-		{
-			gaim_timeout_remove(slpmsg->slpcall->timer);
-			slpmsg->slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT,
-													  msn_slp_call_timeout, slpmsg->slpcall);
-		}
+		slpmsg->slpcall->progress = TRUE;
 
 		if (slpmsg->slpcall->progress_cb != NULL)
 		{
@@ -683,6 +680,8 @@
 	slpcall->cb = msn_xfer_completed_cb;
 	slpcall->xfer = xfer;
 
+	slpcall->pending = TRUE;
+
 	gaim_xfer_set_cancel_send_fnc(xfer, msn_xfer_cancel);
 
 	xfer->data = slpcall;