pidgin: 27bc2af8: Remove a double call to xmlnode_get_name...

qulogic at pidgin.im qulogic at pidgin.im
Sun Dec 14 03:45:42 EST 2008


-----------------------------------------------------------------
Revision: 27bc2af8520e6a136c45cbc8960816006738d900
Ancestor: bd99328511f28be3b349cad4ddacc7b8abb01259
Author: qulogic at pidgin.im
Date: 2008-12-14T04:09:23
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/27bc2af8520e6a136c45cbc8960816006738d900

Modified files:
        libpurple/protocols/jabber/message.c
        libpurple/protocols/jabber/presence.c

ChangeLog: 

Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
!= NULL.
I'm not sure about the one case in jabber_message_parse if child->name=="x"
and xmlns == NULL which fell through in the previous code. I've put that in
the new version, but I don't know if that's correct.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/message.c	44ab3eec7927c3b454853a9aaa1ccc100aad5c00
+++ libpurple/protocols/jabber/message.c	6294dd8a4e9b85afe7ec739fb8597b88150aafb0
@@ -571,12 +571,39 @@ void jabber_message_parse(JabberStream *
 
 	for(child = packet->child; child; child = child->next) {
 		const char *xmlns = xmlnode_get_namespace(child);
-		if(!xmlns)
-			xmlns = "";
 		if(child->type != XMLNODE_TYPE_TAG)
 			continue;
 
-		if(!strcmp(child->name, "subject") && !strcmp(xmlns,"jabber:client")) {
+		if(!strcmp(child->name, "error")) {
+			const char *code = xmlnode_get_attrib(child, "code");
+			char *code_txt = NULL;
+			char *text = xmlnode_get_data(child);
+			if (!text) {
+				xmlnode *enclosed_text_node;
+				
+				if ((enclosed_text_node = xmlnode_get_child(child, "text")))
+					text = xmlnode_get_data(enclosed_text_node);
+			}
+
+			if(code)
+				code_txt = g_strdup_printf(_("(Code %s)"), code);
+
+			if(!jm->error)
+				jm->error = g_strdup_printf("%s%s%s",
+						text ? text : "",
+						text && code_txt ? " " : "",
+						code_txt ? code_txt : "");
+
+			g_free(code_txt);
+			g_free(text);
+		} else if (xmlns == NULL) {
+			/* QuLogic: Not certain this is correct, but it would have happened
+			   with the previous code. */
+			if(!strcmp(child->name, "x"))
+				jm->etc = g_list_append(jm->etc, child);
+			/* The following tests expect xmlns != NULL */
+			continue;
+		} else if(!strcmp(child->name, "subject") && !strcmp(xmlns,"jabber:client")) {
 			if(!jm->subject)
 				jm->subject = xmlnode_get_data(child);
 		} else if(!strcmp(child->name, "thread") && !strcmp(xmlns,"jabber:client")) {
@@ -706,46 +733,24 @@ void jabber_message_parse(JabberStream *
 				jm->eventitems = g_list_append(jm->eventitems, items);
 		} else if(!strcmp(child->name, "attention") && !strcmp(xmlns,"http://www.xmpp.org/extensions/xep-0224.html#ns")) {
 			jm->hasBuzz = TRUE;
-		} else if(!strcmp(child->name, "error")) {
-			const char *code = xmlnode_get_attrib(child, "code");
-			char *code_txt = NULL;
-			char *text = xmlnode_get_data(child);
-			if (!text) {
-				xmlnode *enclosed_text_node;
-				
-				if ((enclosed_text_node = xmlnode_get_child(child, "text")))
-					text = xmlnode_get_data(enclosed_text_node);
-			}
-
-			if(code)
-				code_txt = g_strdup_printf(_("(Code %s)"), code);
-
-			if(!jm->error)
-				jm->error = g_strdup_printf("%s%s%s",
-						text ? text : "",
-						text && code_txt ? " " : "",
-						code_txt ? code_txt : "");
-
-			g_free(code_txt);
-			g_free(text);
-		} else if(!strcmp(child->name, "delay") && xmlns && !strcmp(xmlns,"urn:xmpp:delay")) {
+		} else if(!strcmp(child->name, "delay") && !strcmp(xmlns,"urn:xmpp:delay")) {
 			const char *timestamp = xmlnode_get_attrib(child, "stamp");
 			jm->delayed = TRUE;
 			if(timestamp)
 				jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL);
 		} else if(!strcmp(child->name, "x")) {
-			if(xmlns && !strcmp(xmlns, "jabber:x:event")) {
+			if(!strcmp(xmlns, "jabber:x:event")) {
 				if(xmlnode_get_child(child, "composing")) {
 					if(jm->chat_state == JM_STATE_ACTIVE)
 						jm->chat_state = JM_STATE_COMPOSING;
 					jm->typing_style |= JM_TS_JEP_0022;
 				}
-			} else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
+			} else if(!strcmp(xmlns, "jabber:x:delay")) {
 				const char *timestamp = xmlnode_get_attrib(child, "stamp");
 				jm->delayed = TRUE;
 				if(timestamp)
 					jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL);
-			} else if(xmlns && !strcmp(xmlns, "jabber:x:conference") &&
+			} else if(!strcmp(xmlns, "jabber:x:conference") &&
 					jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE &&
 					jm->type != JABBER_MESSAGE_ERROR) {
 				const char *jid = xmlnode_get_attrib(child, "jid");
@@ -754,8 +759,7 @@ void jabber_message_parse(JabberStream *
 					g_free(jm->to);
 					jm->to = g_strdup(jid);
 				}
-			} else if(xmlns && !strcmp(xmlns,
-						"http://jabber.org/protocol/muc#user") &&
+			} else if(!strcmp(xmlns, "http://jabber.org/protocol/muc#user") &&
 					jm->type != JABBER_MESSAGE_ERROR) {
 				xmlnode *invite = xmlnode_get_child(child, "invite");
 				if(invite) {
============================================================
--- libpurple/protocols/jabber/presence.c	48a8f3d90123149ab50561e55a5c4e317e4f4a64
+++ libpurple/protocols/jabber/presence.c	93c18869585feb24d9fae02c395caa6e839f8303
@@ -502,17 +502,19 @@ void jabber_presence_parse(JabberStream 
 				priority = atoi(p);
 				g_free(p);
 			}
+		} else if(xmlns == NULL) {
+			/* The rest of the cases used to check xmlns individually. */
+			continue;
 		} else if(!strcmp(y->name, "delay") && !strcmp(xmlns, "urn:xmpp:delay")) {
 			/* XXX: compare the time.  jabber:x:delay can happen on presence packets that aren't really and truly delayed */
 			delayed = TRUE;
-		} else if(xmlns && !strcmp(y->name, "c") && !strcmp(xmlns, "http://jabber.org/protocol/caps")) {
+		} else if(!strcmp(y->name, "c") && !strcmp(xmlns, "http://jabber.org/protocol/caps")) {
 			caps = y; /* store for later, when creating buddy resource */
 		} else if(!strcmp(y->name, "x")) {
-			const char *xmlns = xmlnode_get_namespace(y);
-			if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
+			if(!strcmp(xmlns, "jabber:x:delay")) {
 				/* XXX: compare the time.  jabber:x:delay can happen on presence packets that aren't really and truly delayed */
 				delayed = TRUE;
-			} else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
+			} else if(!strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
 				xmlnode *z;
 
 				muc = TRUE;
@@ -555,7 +557,7 @@ void jabber_presence_parse(JabberStream 
 							flags |= PURPLE_CBFLAGS_VOICE;
 					}
 				}
-			} else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) {
+			} else if(!strcmp(xmlns, "vcard-temp:x:update")) {
 				xmlnode *photo = xmlnode_get_child(y, "photo");
 				if(photo) {
 					g_free(avatar_hash);


More information about the Commits mailing list