pidgin: cf59840f: jabber: The parser is namespace-aware, s...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Mar 16 22:36:06 EDT 2010


-----------------------------------------------------------------
Revision: cf59840fc04e1a2ee8115e4a1fef6cabe78075d2
Ancestor: 0abffcad910fa64b1fd467e340482c2afda5da94
Author: darkrain42 at pidgin.im
Date: 2010-03-12T06:16:43
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/cf59840fc04e1a2ee8115e4a1fef6cabe78075d2

Modified files:
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/namespaces.h

ChangeLog: 

jabber: The parser is namespace-aware, so don't match on "stream:features".

Also refactor the checks a little and make the SASL/TLS handling
namespace-aware.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	d594709af5c36b8b29c8cc0316eed014981caeb8
+++ libpurple/protocols/jabber/jabber.c	a33cf4c1fa4164c605cbc2efa3648d899b58836e
@@ -261,6 +261,7 @@ void jabber_process_packet(JabberStream 
 
 void jabber_process_packet(JabberStream *js, xmlnode **packet)
 {
+	const char *name;
 	const char *xmlns;
 
 	purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-receiving-xmlnode", js->gc, packet);
@@ -269,6 +270,7 @@ void jabber_process_packet(JabberStream 
 	if(NULL == *packet)
 		return;
 
+	name = (*packet)->name;
 	xmlns = xmlnode_get_namespace(*packet);
 
 	if(!strcmp((*packet)->name, "iq")) {
@@ -277,30 +279,30 @@ void jabber_process_packet(JabberStream 
 		jabber_presence_parse(js, *packet);
 	} else if(!strcmp((*packet)->name, "message")) {
 		jabber_message_parse(js, *packet);
-	} else if(!strcmp((*packet)->name, "stream:features")) {
-		jabber_stream_features_parse(js, *packet);
-	} else if (!strcmp((*packet)->name, "features") && xmlns &&
-		   !strcmp(xmlns, NS_XMPP_STREAMS)) {
-		jabber_stream_features_parse(js, *packet);
-	} else if(!strcmp((*packet)->name, "stream:error") ||
-			 (!strcmp((*packet)->name, "error") && xmlns &&
-				!strcmp(xmlns, NS_XMPP_STREAMS)))
-	{
-		jabber_stream_handle_error(js, *packet);
-	} else if(!strcmp((*packet)->name, "challenge")) {
-		if(js->state == JABBER_STREAM_AUTHENTICATING)
-			jabber_auth_handle_challenge(js, *packet);
-	} else if(!strcmp((*packet)->name, "success")) {
-		if(js->state == JABBER_STREAM_AUTHENTICATING)
-			jabber_auth_handle_success(js, *packet);
-	} else if(!strcmp((*packet)->name, "failure")) {
-		if(js->state == JABBER_STREAM_AUTHENTICATING)
-			jabber_auth_handle_failure(js, *packet);
-	} else if(!strcmp((*packet)->name, "proceed")) {
-		if (js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION && !js->gsc)
-			tls_init(js);
-		else
-			purple_debug_warning("jabber", "Ignoring spurious <proceed/>\n");
+	} else if (purple_strequal(xmlns, NS_XMPP_STREAMS)) {
+		if (g_str_equal(name, "features"))
+			jabber_stream_features_parse(js, *packet);
+		else if (g_str_equal(name, "error"))
+			jabber_stream_handle_error(js, *packet);
+	} else if (purple_strequal(xmlns, NS_XMPP_SASL)) {
+		if (js->state != JABBER_STREAM_AUTHENTICATING)
+			purple_debug_warning("jabber", "Ignoring spurious SASL stanza %s\n", name);
+		else {
+			if (g_str_equal(name, "challenge"))
+				jabber_auth_handle_challenge(js, *packet);
+			else if (g_str_equal(name, "success"))
+				jabber_auth_handle_success(js, *packet);
+			else if (g_str_equal(name, "failure"))
+				jabber_auth_handle_failure(js, *packet);
+		}
+	} else if (purple_strequal(xmlns, NS_XMPP_TLS)) {
+		if (js->state != JABBER_STREAM_INITIALIZING_ENCRYPTION || js->gsc)
+			purple_debug_warning("jabber", "Ignoring spurious %s\n", name);
+		else {
+			if (g_str_equal(name, "proceed"))
+				tls_init(js);
+			/* TODO: Handle <failure/>, I guess? */
+		}
 	} else {
 		purple_debug_warning("jabber", "Unknown packet: %s\n", (*packet)->name);
 	}
============================================================
--- libpurple/protocols/jabber/namespaces.h	c0b1b20e6c5d24f6d5c088d01ebfcfdd1702baf8
+++ libpurple/protocols/jabber/namespaces.h	5bece7bc6ccad6fbd0de68b1b461fa59acaac10e
@@ -30,6 +30,7 @@
 #define NS_XMPP_SESSION "urn:ietf:params:xml:ns:xmpp-session"
 #define NS_XMPP_STANZAS "urn:ietf:params:xml:ns:xmpp-stanzas"
 #define NS_XMPP_STREAMS "http://etherx.jabber.org/streams"
+#define NS_XMPP_TLS "urn:ietf:params:xml:ns:xmpp-tls"
 
 /* XEP-0012 Last Activity (and XEP-0256 Last Activity in Presence) */
 #define NS_LAST_ACTIVITY "jabber:iq:last"


More information about the Commits mailing list