changeset 10602:f52ab405f1ab

[gaim-migrate @ 12032] This is patch 1112281 from Felipe Contreras, it prevents file transfers being cancelled when closing a conversation window with the sender/recipient. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Wed, 16 Feb 2005 20:14:12 +0000
parents e46b51de549a
children 03aa223a14d9
files src/protocols/msn/msn.c src/protocols/msn/session.c src/protocols/msn/session.h src/protocols/msn/slp.c src/protocols/msn/slpcall.c src/protocols/msn/slplink.c src/protocols/msn/slplink.h src/protocols/msn/switchboard.h
diffstat 8 files changed, 111 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msn.c	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/msn.c	Wed Feb 16 20:14:12 2005 +0000
@@ -338,6 +338,7 @@
 	/* TODO: This might move somewhere else, after USR might be */
 	swboard->chat_id = session->conv_seq++;
 	swboard->conv = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat");
+	swboard->flag = MSN_SB_FLAG_IM;
 
 	gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
 							gaim_account_get_username(buddy->account), NULL, GAIM_CBFLAGS_NONE, TRUE);
@@ -738,7 +739,7 @@
 		MsnSwitchBoard *swboard;
 
 		session = gc->proto_data;
-		swboard = msn_session_get_swboard(session, who);
+		swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM);
 
 		msn_switchboard_send_msg(swboard, msg, TRUE);
 	}
@@ -794,7 +795,7 @@
 		return MSN_TYPING_SEND_TIMEOUT;
 	}
 
-	swboard = msn_session_find_swboard(session, who);
+	swboard = msn_session_find_swboard(session, who, MSN_SB_FLAG_IM);
 
 	if (swboard == NULL || !msn_switchboard_can_send(swboard))
 		return 0;
@@ -1081,7 +1082,7 @@
 
 	session = gc->proto_data;
 
-	swboard = msn_session_find_switch_with_id(session, id);
+	swboard = msn_session_find_swboard_with_id(session, id, MSN_SB_FLAG_IM);
 
 	if (swboard == NULL)
 	{
@@ -1090,6 +1091,7 @@
 		msn_switchboard_request(swboard);
 		swboard->chat_id = id;
 		swboard->conv = gaim_find_chat(gc, id);
+		swboard->flag = MSN_SB_FLAG_IM;
 	}
 
 	msn_switchboard_request_add_user(swboard, who);
@@ -1103,7 +1105,7 @@
 
 	session = gc->proto_data;
 
-	swboard = msn_session_find_switch_with_id(session, id);
+	swboard = msn_session_find_swboard_with_id(session, id, MSN_SB_FLAG_IM);
 
 	/* if swboard is NULL we were the only person left anyway */
 	if (swboard == NULL)
@@ -1124,7 +1126,7 @@
 
 	account = gaim_connection_get_account(gc);
 	session = gc->proto_data;
-	swboard = msn_session_find_switch_with_id(session, id);
+	swboard = msn_session_find_swboard_with_id(session, id, MSN_SB_FLAG_IM);
 
 	if (swboard == NULL)
 		return -EINVAL;
@@ -1160,14 +1162,17 @@
 msn_keepalive(GaimConnection *gc)
 {
 	MsnSession *session;
-	MsnCmdProc *cmdproc;
 
 	session = gc->proto_data;
 
-	cmdproc = session->notification->cmdproc;
+	if (!session->http_method)
+	{
+		MsnCmdProc *cmdproc;
 
-	if (!session->http_method)
+		cmdproc = session->notification->cmdproc;
+
 		msn_cmdproc_send_quick(cmdproc, "PNG", NULL, NULL);
+	}
 }
 
 static void
@@ -1217,17 +1222,20 @@
 
 	session = gc->proto_data;
 
-	swboard = msn_session_find_swboard(session, who);
+	swboard = msn_session_find_swboard(session, who, MSN_SB_FLAG_IM);
 
 	/*
-	 * Don't perform an assertion here. It swboard is NULL, then the
+	 * Don't perform an assertion here. If swboard is NULL, then the
 	 * switchboard was either closed by the other party, or the person
 	 * is talking to himself.
 	 */
 	if (swboard == NULL)
 		return;
 
-	msn_switchboard_close(swboard);
+	if (!(swboard->flag & MSN_SB_FLAG_FT))
+		msn_switchboard_close(swboard);
+	else
+		swboard->conv = NULL;
 }
 
 static void
--- a/src/protocols/msn/session.c	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/session.c	Wed Feb 16 20:14:12 2005 +0000
@@ -144,7 +144,8 @@
 
 /* TODO: This must go away when conversation is redesigned */
 MsnSwitchBoard *
-msn_session_find_swboard(MsnSession *session, const char *username)
+msn_session_find_swboard(MsnSession *session, const char *username,
+						 MsnSBFlag flag)
 {
 	GList *l;
 
@@ -157,16 +158,17 @@
 
 		swboard = l->data;
 
-		if (swboard->im_user != NULL)
-			if (!strcmp(username, swboard->im_user))
-				return swboard;
+		if ((swboard->im_user != NULL) &&
+			!strcmp(username, swboard->im_user) && (swboard->flag & flag))
+			return swboard;
 	}
 
 	return NULL;
 }
 
 MsnSwitchBoard *
-msn_session_find_switch_with_id(const MsnSession *session, int chat_id)
+msn_session_find_swboard_with_id(const MsnSession *session, int chat_id,
+								 MsnSBFlag flag)
 {
 	GList *l;
 
@@ -179,7 +181,7 @@
 
 		swboard = l->data;
 
-		if (swboard->chat_id == chat_id)
+		if ((swboard->chat_id == chat_id) && (swboard->flag & flag))
 			return swboard;
 	}
 
@@ -187,16 +189,18 @@
 }
 
 MsnSwitchBoard *
-msn_session_get_swboard(MsnSession *session, const char *username)
+msn_session_get_swboard(MsnSession *session, const char *username,
+						MsnSBFlag flag)
 {
 	MsnSwitchBoard *swboard;
 
-	swboard = msn_session_find_swboard(session, username);
+	swboard = msn_session_find_swboard(session, username, flag);
 
 	if (swboard == NULL)
 	{
 		swboard = msn_switchboard_new(session);
 		swboard->im_user = g_strdup(username);
+		swboard->flag = flag;
 		msn_switchboard_request(swboard);
 		msn_switchboard_request_add_user(swboard, username);
 	}
--- a/src/protocols/msn/session.h	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/session.h	Wed Feb 16 20:14:12 2005 +0000
@@ -155,21 +155,41 @@
  */
 void msn_session_disconnect(MsnSession *session);
 
+ /**
+ * Finds a switchboard with the given username.
+ *
+ * @param session The MSN session.
+ * @param username The username to search for.
+ * @param flag The flag of the switchboard.
+ *
+ * @return The switchboard, if found.
+ */
+MsnSwitchBoard *msn_session_find_swboard(MsnSession *session,
+										 const char *username, MsnSBFlag flag);
+
 /**
  * Finds a switchboard with the given chat ID.
  *
  * @param session The MSN session.
  * @param chat_id The chat ID to search for.
+ * @param flag The flag of the switchboard.
  *
  * @return The switchboard, if found.
  */
-MsnSwitchBoard *msn_session_find_switch_with_id(const MsnSession *session,
-												int chat_id);
+MsnSwitchBoard *msn_session_find_swboard_with_id(const MsnSession *session,
+												 int chat_id, MsnSBFlag flag);
 
-MsnSwitchBoard *msn_session_find_swboard(MsnSession *session,
-										 const char *username);
+/**
+ * Returns a switchboard to communicate with certain username.
+ *
+ * @param session The MSN session.
+ * @param username The username to search for.
+ * @param flag The flag of the switchboard.
+ *
+ * @return The switchboard.
+ */
 MsnSwitchBoard *msn_session_get_swboard(MsnSession *session,
-										const char *username);
+										const char *username, MsnSBFlag flag);
 
 /**
  * Sets an error for the MSN session.
--- a/src/protocols/msn/slp.c	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/slp.c	Wed Feb 16 20:14:12 2005 +0000
@@ -732,6 +732,13 @@
 	session = cmdproc->servconn->session;
 	slplink = msn_session_get_slplink(session, msg->remote_user);
 
+	if (slplink->swboard == NULL)
+	{
+		/* We will need this in order to change it's flags. */
+		slplink->swboard = (MsnSwitchBoard *)cmdproc->data;
+		slplink->swboard->slplink = slplink;
+	}
+
 	msn_slplink_process_msg(slplink, msg);
 }
 
--- a/src/protocols/msn/slpcall.c	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/slpcall.c	Wed Feb 16 20:14:12 2005 +0000
@@ -46,7 +46,7 @@
 }
 
 /**************************************************************************
- * SLP Call
+ * Main
  **************************************************************************/
 
 MsnSlpCall *
@@ -59,8 +59,8 @@
 	slpcall = g_new0(MsnSlpCall, 1);
 
 	slpcall->slplink = slplink;
-	slplink->slp_calls =
-		g_list_append(slplink->slp_calls, slpcall);
+
+	msn_slplink_add_slpcall(slplink, slpcall);
 
 	slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall);
 
@@ -86,8 +86,7 @@
 	if (slpcall->data_info != NULL)
 		g_free(slpcall->data_info);
 
-	slpcall->slplink->slp_calls =
-		g_list_remove(slpcall->slplink->slp_calls, slpcall);
+	msn_slplink_remove_slpcall(slpcall->slplink, slpcall);
 
 	for (e = slpcall->slplink->slp_msgs; e != NULL; )
 	{
--- a/src/protocols/msn/slplink.c	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/slplink.c	Wed Feb 16 20:14:12 2005 +0000
@@ -54,6 +54,10 @@
 }
 #endif
 
+/**************************************************************************
+ * Main
+ **************************************************************************/
+
 MsnSlpLink *
 msn_slplink_new(MsnSession *session, const char *username)
 {
@@ -155,6 +159,31 @@
 	return NULL;
 }
 
+void
+msn_slplink_add_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall)
+{
+	if (slplink->slp_calls == NULL)
+	{
+		if (slplink->swboard != NULL)
+			slplink->swboard->flag |= MSN_SB_FLAG_FT;
+	}
+
+	slplink->slp_calls = g_list_append(slplink->slp_calls, slpcall);
+}
+
+void
+msn_slplink_remove_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall)
+{
+	slplink->slp_calls = g_list_remove(slplink->slp_calls, slpcall);
+
+	/* The slplink has no slpcalls in it, maybe we should destroy it. */
+	if (slplink->slp_calls == NULL)
+	{
+		if (slplink->swboard != NULL)
+			slplink->swboard->flag &= ~MSN_SB_FLAG_FT;
+	}
+}
+
 MsnSlpCall *
 msn_slplink_find_slp_call(MsnSlpLink *slplink, const char *id)
 {
@@ -204,7 +233,8 @@
 		if (slplink->swboard == NULL)
 		{
 			slplink->swboard = msn_session_get_swboard(slplink->session,
-													   slplink->remote_user);
+													   slplink->remote_user,
+													   MSN_SB_FLAG_FT);
 
 			if (slplink->swboard == NULL)
 				return;
--- a/src/protocols/msn/slplink.h	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/slplink.h	Wed Feb 16 20:14:12 2005 +0000
@@ -61,6 +61,8 @@
 MsnSlpLink *msn_session_get_slplink(MsnSession *session, const char *username);
 MsnSlpSession *msn_slplink_find_slp_session(MsnSlpLink *slplink,
 											long session_id);
+void msn_slplink_add_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall);
+void msn_slplink_remove_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall);
 MsnSlpCall *msn_slplink_find_slp_call(MsnSlpLink *slplink,
 									  const char *id);
 MsnSlpCall *msn_slplink_find_slp_call_with_session_id(MsnSlpLink *slplink, long id);
--- a/src/protocols/msn/switchboard.h	Wed Feb 16 03:57:23 2005 +0000
+++ b/src/protocols/msn/switchboard.h	Wed Feb 16 20:14:12 2005 +0000
@@ -50,6 +50,16 @@
 } MsnSBErrorType;
 
 /**
+ * A switchboard flag.
+ */
+typedef enum
+{
+	MSN_SB_FLAG_IM = 0x01, /**< This switchboard is used for instant messaging. */
+	MSN_SB_FLAG_FT = 0x02, /**< This switchboard is used for file transfer. */
+
+} MsnSBFlag;
+
+/**
  * A switchboard.
  *
  * A place where a bunch of users send messages to the rest of the users.
@@ -61,6 +71,7 @@
 	MsnCmdProc *cmdproc;
 	char *im_user;
 
+	MsnSBFlag flag;
 	char *auth_key;
 	char *session_id;