changeset 27199:67c992cc4b3c

Fix a crash when there are offline messages from both MSN and Yahoo buddies.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 28 Jun 2009 01:03:07 +0000
parents 478e0b091731
children a2508ac2e536
files libpurple/protocols/yahoo/yahoo.c
diffstat 1 files changed, 18 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo.c	Sat Jun 27 23:49:12 2009 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Sun Jun 28 01:03:07 2009 +0000
@@ -834,6 +834,7 @@
 	int buddy_icon;
 	char *id;
 	char *msg;
+	gboolean msn;
 };
 
 static void yahoo_process_sms_message(PurpleConnection *gc, struct yahoo_packet *pkt)
@@ -907,8 +908,6 @@
 	struct _yahoo_im *im = NULL;
 	const char *imv = NULL;
 	gint val_11 = 0;
-	gboolean msn = FALSE;
-	char *msn_from = NULL;
 
 	account = purple_connection_get_account(gc);
 
@@ -938,9 +937,9 @@
 				if (im)
 					im->msg = pair->value;
 			}
-			if (pair->key == 241) {
+			if (im && pair->key == 241) {
 				if(strtol(pair->value, NULL, 10) == 2)
-					msn = TRUE;
+					im->msn = TRUE;
 			}
 			/* peer session id */
 			if (pair->key == 11) {
@@ -962,9 +961,6 @@
 		                  _("Your Yahoo! message did not get sent."), NULL);
 	}
 
-	if(msn)
-		msn_from = g_strconcat("msn/", im->from, NULL);
-
 	/* disconnect the peer if connected through p2p and sends wrong value for session id */
 	if( (pkt_type == YAHOO_PKT_TYPE_P2P) && (val_11 != yd->session_id) ) {
 		purple_debug_warning("yahoo","p2p: %s sent us message with wrong session id. Disconnecting p2p connection to peer\n", im->from);
@@ -1009,6 +1005,8 @@
 	for (l = list; l; l = l->next) {
 		YahooFriend *f;
 		char *m, *m2;
+		char *msn_from = NULL;
+		const char *from;
 		PurpleConversation *c;
 		im = l->data;
 
@@ -1054,24 +1052,22 @@
 		m = m2;
 		purple_util_chrreplace(m, '\r', '\n');
 
-		c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, im->from, account);
-		if ((c == NULL) && msn)
-			c=purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, msn_from, account);
+		if (im->msn) {
+			msn_from = g_strconcat("msn/", im->from, NULL);
+			from = msn_from;
+		} else {
+			from = im->from;
+		}
+
+		c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, account);
 
 		if (!strcmp(m, "<ding>")) {
 			char *username;
 
-			if(c == NULL) {
-				if(msn)
-					c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, msn_from);
-				else
-					c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from);
+			if (c == NULL) {
+				c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, from);
 			}
-			if(msn)
-				username = g_markup_escape_text(msn_from, -1);
-			else
-				username = g_markup_escape_text(im->from, -1);
-
+			username = g_markup_escape_text(from, -1);
 			purple_prpl_got_attention(gc, username, YAHOO_BUZZ);
 			g_free(username);
 			g_free(m);
@@ -1083,15 +1079,11 @@
 		m2 = yahoo_codes_to_html(m);
 		g_free(m);
 
-		if(msn)
-			serv_got_im(gc, msn_from, m2, 0, im->time);
-		else
-			serv_got_im(gc, im->from, m2, 0, im->time);
-
+		serv_got_im(gc, from, m2, 0, im->time);
 		g_free(m2);
 
 		/* laters : implement buddy icon for msn friends */
-		if(!msn) {
+		if (!im->msn) {
 			if ((f = yahoo_friend_find(gc, im->from)) && im->buddy_icon == 2) {
 				if (yahoo_friend_get_buddy_icon_need_request(f)) {
 					yahoo_send_picture_request(gc, im->from);