Mercurial > pidgin
changeset 29601:f5f3c5134eb7
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.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 12 Mar 2010 06:16:43 +0000 |
parents | 782bf663733d |
children | 6e598ca344b3 |
files | libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/namespaces.h |
diffstat | 2 files changed, 27 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c Fri Mar 12 05:37:44 2010 +0000 +++ b/libpurple/protocols/jabber/jabber.c Fri Mar 12 06:16:43 2010 +0000 @@ -261,6 +261,7 @@ 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 @@ if(NULL == *packet) return; + name = (*packet)->name; xmlns = xmlnode_get_namespace(*packet); if(!strcmp((*packet)->name, "iq")) { @@ -277,30 +279,30 @@ 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); }
--- a/libpurple/protocols/jabber/namespaces.h Fri Mar 12 05:37:44 2010 +0000 +++ b/libpurple/protocols/jabber/namespaces.h Fri Mar 12 06:16:43 2010 +0000 @@ -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"