diff libpurple/protocols/msn/notification.c @ 24058:ce51405b7a7e

merge of 'd50e4b01c210ebbcd8f8d5a001fa72450e021a97' and 'e550112b97817b0eafc647bd8c0adddf2a262a62'
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 17 Sep 2008 00:30:18 +0000
parents 2d7a8d15f3a3 b8d38a11f9c6
children f5923e2e6513
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c	Wed Sep 17 00:29:56 2008 +0000
+++ b/libpurple/protocols/msn/notification.c	Wed Sep 17 00:30:18 2008 +0000
@@ -947,10 +947,11 @@
 	PurpleAccount *account;
 	PurpleConnection *gc;
 	MsnUser *user;
-	MsnObject *msnobj;
+	MsnObject *msnobj = NULL;
 	unsigned long clientid;
-	int networkid;
-	const char *state, *passport, *friendly;
+	int networkid = 0;
+	const char *state, *passport;
+	char *friendly;
 
 	session = cmdproc->session;
 	account = session->account;
@@ -958,23 +959,47 @@
 
 	state    = cmd->params[1];
 	passport = cmd->params[2];
-	/*if a contact is actually on the WLM part or the yahoo part*/
-	networkid = atoi(cmd->params[3]);
-	friendly = purple_url_decode(cmd->params[4]);
 
 	user = msn_userlist_find_user(session->userlist, passport);
+	if (user == NULL)
+		/* Where'd this come from? */
+		return;
+
+	if (cmd->param_count == 7) {
+		/* MSNP14+ with Display Picture object */
+		networkid = atoi(cmd->params[3]);
+		friendly = g_strdup(purple_url_decode(cmd->params[4]));
+		clientid = strtoul(cmd->params[5], NULL, 10);
+		msnobj = msn_object_new_from_string(purple_url_decode(cmd->params[6]));
+	} else if (cmd->param_count == 6) {
+		/* Yes, this is 5. The friendly name could start with a number,
+		   but the display picture object can't... */
+		if (isdigit(cmd->params[5][0])) {
+			/* MSNP14 without Display Picture object */
+			networkid = atoi(cmd->params[3]);
+			friendly = g_strdup(purple_url_decode(cmd->params[4]));
+			clientid = strtoul(cmd->params[5], NULL, 10);
+		} else {
+			/* MSNP8+ with Display Picture object */
+			friendly = g_strdup(purple_url_decode(cmd->params[3]));
+			clientid = strtoul(cmd->params[4], NULL, 10);
+			msnobj = msn_object_new_from_string(purple_url_decode(cmd->params[5]));
+		}
+	} else if (cmd->param_count == 5) {
+		/* MSNP8+ without Display Picture object */
+		friendly = g_strdup(purple_url_decode(cmd->params[3]));
+		clientid = strtoul(cmd->params[4], NULL, 10);
+	} else {
+		purple_debug_warning("msn", "Received ILN with unknown number of parameters.\n");
+		return;
+	}
 
 	serv_got_alias(gc, passport, friendly);
-
 	msn_user_set_friendly_name(user, friendly);
+	g_free(friendly);
 
-	if (cmd->param_count == 7)
-	{
-		msnobj = msn_object_new_from_string(purple_url_decode(cmd->params[6]));
-		msn_user_set_object(user, msnobj);
-	}
+	msn_user_set_object(user, msnobj);
 
-	clientid = strtoul(cmd->params[5], NULL, 10);
 	user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->phone.mobile && user->phone.mobile[0] == '+');
 	msn_user_set_clientid(user, clientid);
 	msn_user_set_network(user, networkid);
@@ -1481,6 +1506,13 @@
 
 	passport = cmd->params[0];
 	user = msn_userlist_find_user(session->userlist, passport);
+	if (user == NULL) {
+		char *str = g_strndup(payload, len);
+		purple_debug_info("msn", "unknown user %s, payload is %s",
+			passport, str);
+		g_free(str);
+		return;
+	}
 
 	psm_str = msn_get_psm(cmd->payload,len);
 	msn_user_set_statusline(user, psm_str);