changeset 31101:3140627b93e7

Avoid calling xmlnode_from_str twice when parsing the UBX data.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 09 Dec 2009 21:32:33 +0000
parents 0a22d67651ce
children 8c543e70db7f
files libpurple/protocols/msn/notification.c libpurple/protocols/msn/state.c libpurple/protocols/msn/state.h
diffstat 3 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c	Wed Dec 09 21:29:29 2009 +0000
+++ b/libpurple/protocols/msn/notification.c	Wed Dec 09 21:32:33 2009 +0000
@@ -1625,6 +1625,7 @@
 	PurpleAccount *account;
 	MsnUser *user;
 	const char *passport;
+	xmlnode *payloadNode;
 	char *psm_str, *str;
 	CurrentMedia media = {CURRENT_MEDIA_UNKNOWN, NULL, NULL, NULL};
 
@@ -1642,11 +1643,22 @@
 	}
 
 	if (len != 0) {
-		psm_str = msn_get_psm(cmd->payload,len);
+		payloadNode = xmlnode_from_str(payload, len);
+		if (!payloadNode) {
+			purple_debug_error("msn", "UBX XML parse Error!\n");
+
+			msn_user_set_statusline(user, NULL);
+			msn_user_set_currentmedia(user, NULL);
+
+			msn_user_update(user);
+			return;
+		}
+
+		psm_str = msn_get_psm(payloadNode);
 		msn_user_set_statusline(user, psm_str);
 		g_free(psm_str);
 
-		str = msn_get_currentmedia(cmd->payload, len);
+		str = msn_get_currentmedia(payloadNode);
 		if (msn_parse_currentmedia(str, &media))
 			msn_user_set_currentmedia(user, &media);
 		else
--- a/libpurple/protocols/msn/state.c	Wed Dec 09 21:29:29 2009 +0000
+++ b/libpurple/protocols/msn/state.c	Wed Dec 09 21:32:33 2009 +0000
@@ -161,19 +161,14 @@
 	return parsed;
 }
 
-/* get the CurrentMedia info from the XML string */
+/* get the CurrentMedia info from the XML node */
 char *
-msn_get_currentmedia(char *xml_str, gsize len)
+msn_get_currentmedia(xmlnode *payloadNode)
 {
-	xmlnode *payloadNode, *currentmediaNode;
+	xmlnode *currentmediaNode;
 	char *currentmedia;
 
 	purple_debug_info("msn", "Get CurrentMedia\n");
-	payloadNode = xmlnode_from_str(xml_str, len);
-	if (!payloadNode) {
-		purple_debug_error("msn", "PSM XML parse Error!\n");
-		return NULL;
-	}
 	currentmediaNode = xmlnode_get_child(payloadNode, "CurrentMedia");
 	if (currentmediaNode == NULL) {
 		purple_debug_info("msn", "No CurrentMedia Node\n");
@@ -187,19 +182,14 @@
 	return currentmedia;
 }
 
-/*get the PSM info from the XML string*/
+/* Get the PSM info from the XML node */
 char *
-msn_get_psm(char *xml_str, gsize len)
+msn_get_psm(xmlnode *payloadNode)
 {
-	xmlnode *payloadNode, *psmNode;
+	xmlnode *psmNode;
 	char *psm;
 
 	purple_debug_info("msn", "msn get PSM\n");
-	payloadNode = xmlnode_from_str(xml_str, len);
-	if (!payloadNode) {
-		purple_debug_error("msn", "PSM XML parse Error!\n");
-		return NULL;
-	}
 	psmNode = xmlnode_get_child(payloadNode, "PSM");
 	if (psmNode == NULL) {
 		purple_debug_info("msn", "No PSM status Node\n");
--- a/libpurple/protocols/msn/state.h	Wed Dec 09 21:29:29 2009 +0000
+++ b/libpurple/protocols/msn/state.h	Wed Dec 09 21:32:33 2009 +0000
@@ -64,11 +64,11 @@
 /* Parse CurrentMedia string */
 gboolean msn_parse_currentmedia(const char *cmedia, CurrentMedia *media);
 
-/* Get the CurrentMedia info from the XML string */
-char * msn_get_currentmedia(char *xml_str,gsize len);
+/* Get the CurrentMedia info from the XML node */
+char * msn_get_currentmedia(xmlnode *payloadNode);
 
-/*get the PSM info from the XML string*/
-char * msn_get_psm(char *xml_str,gsize len);
+/* Get the PSM info from the XML node */
+char * msn_get_psm(xmlnode *payloadNode);
 
 MsnAwayType msn_state_from_account(PurpleAccount *account);