diff libpurple/protocols/msn/oim.c @ 20439:bee467c81570

A bunch of MSNP14 stuff: Don't store the group id on the group blist node. Fix & tidy up payload length detection for commands (errors can have payloads too) Avoid a crash when connecting to a new account with no contact list Tidy up addressbook parsing slightly Fix crashes when buddy list sync issues are detected Fix initial email notifications, Fixes #1293 Plug a few memory leaks Detect OIM authentication failures correctly NOTE: I have disabled dynamic address book retrieval, instead we now receive the whole address book. This is because the blist sync stuff is still very wonky.
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 27 May 2007 17:00:06 +0000
parents f0bc92602072
children 45e3739de7fd
line wrap: on
line diff
--- a/libpurple/protocols/msn/oim.c	Sun May 27 11:23:09 2007 +0000
+++ b/libpurple/protocols/msn/oim.c	Sun May 27 17:00:06 2007 +0000
@@ -195,7 +195,7 @@
 	faultCodeStr = xmlnode_get_data(faultCodeNode);
 	purple_debug_info("MaYuan","fault code:{%s}\n",faultCodeStr);
 
-	if(strcmp(faultCodeStr,"q0:AuthenticationFailed")){
+	if(!strcmp(faultCodeStr,"q0:AuthenticationFailed")){
 		/*other Fault Reason?*/
 		goto oim_send_process_fail;
 	}
@@ -209,9 +209,12 @@
 	 */
 	detailNode = xmlnode_get_child(faultNode, "detail");
 	if(detailNode == NULL){
-			goto oim_send_process_fail;
+		goto oim_send_process_fail;
 	}
 	challengeNode = xmlnode_get_child(detailNode,"LockKeyChallenge");
+	if (challengeNode == NULL) {
+		goto oim_send_process_fail;
+	}
 
 	g_free(oim->challenge);
 	oim->challenge = xmlnode_get_data(challengeNode);
@@ -520,10 +523,38 @@
 void
 msn_parse_oim_msg(MsnOim *oim,const char *xmlmsg)
 {
-	xmlnode *mdNode,*mNode,*ENode,*INode,*rtNode,*nNode;
-	char *passport,*msgid,*nickname, *rTime = NULL;
+	xmlnode *node, *mdNode,*mNode,*ENode,*INode,*rtNode,*nNode;
+	char *passport,*msgid,*nickname, *unread, *rTime = NULL;
+
+	node = xmlnode_from_str(xmlmsg, strlen(xmlmsg));
+
+	ENode = xmlnode_get_child(node, "E");
+	INode = xmlnode_get_child(ENode, "IU");
+	unread = xmlnode_get_data(INode);
+
+	if (unread != NULL)
+	{
+		int count = atoi(unread);
 
-	mdNode = xmlnode_from_str(xmlmsg, strlen(xmlmsg));
+		if (count > 0)
+		{
+			MsnSession *session = oim->session;
+			const char *passport;
+			const char *url;
+
+			passport = msn_user_get_passport(session->user);
+			url = session->passport_info.file;
+
+			purple_notify_emails(session->account->gc, atoi(unread), FALSE, NULL, NULL,
+					&passport, &url, NULL, NULL);
+		}
+	}
+
+	mdNode = xmlnode_get_child(node, "MD");
+	if (mdNode == NULL) {
+		xmlnode_free(node);
+		return;
+	}
 	for(mNode = xmlnode_get_child(mdNode, "M"); mNode;
 					mNode = xmlnode_get_next_twin(mNode)){
 		/*email Node*/
@@ -537,17 +568,21 @@
 		nickname = xmlnode_get_data(nNode);
 		/*receive time*/
 		rtNode = xmlnode_get_child(mNode,"RT");
-		if(rtNode != NULL)
+		if(rtNode != NULL) {
 			rTime = xmlnode_get_data(rtNode);
-/*		purple_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime);*/
+			rtNode = NULL;
+		}
+/*		purple_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime); */
 
 		oim->oim_list = g_list_append(oim->oim_list,msgid);
 		msn_oim_post_single_get_msg(oim,msgid);
 		g_free(passport);
-//		g_free(msgid);
+		g_free(msgid);
 		g_free(rTime);
+		rTime = NULL;
 		g_free(nickname);
 	}
+	xmlnode_free(node);
 }
 
 /*Post to get the Offline Instant Message*/