diff options
author | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2010-09-30 17:46:06 +0100 |
---|---|---|
committer | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2010-09-30 18:42:07 +0100 |
commit | f2cb0f6fc98b7d75b08516710046977195e26faa (patch) | |
tree | bc6a225fe8e088aa6610cdd8bc3f97880fee8107 | |
parent | d3e68d03f79625f695601b3b69dd853785fc14f3 (diff) |
Accept recoverable errors and fixup namespaces with extra spaces
-rw-r--r-- | tests/wocky-xmpp-reader-test.c | 33 | ||||
-rw-r--r-- | wocky/wocky-xmpp-reader.c | 21 |
2 files changed, 49 insertions, 5 deletions
diff --git a/tests/wocky-xmpp-reader-test.c b/tests/wocky-xmpp-reader-test.c index 5212a8c..62cdb64 100644 --- a/tests/wocky-xmpp-reader-test.c +++ b/tests/wocky-xmpp-reader-test.c @@ -61,6 +61,15 @@ " </vCard> " \ "</iq> " +#define VALID_NAMESPACE "http://garden.with.spaces" +#define INVALID_NAMESPACE_MESSAGE \ +"<iq id='badger0' to='plant@collabora.cbg' type='result'> "\ +" <branch xmlns=' "VALID_NAMESPACE" '> " \ +" <leaf colour='green' /> " \ +" </branch> " \ +"</iq> " + + static void test_stream_no_stanzas (void) { @@ -250,6 +259,29 @@ test_vcard_namespace (void) g_object_unref (reader); } +static void +test_invalid_namespace (void) +{ + WockyXmppReader *reader; + WockyStanza *stanza; + + reader = wocky_xmpp_reader_new_no_stream (); + + wocky_xmpp_reader_push (reader, + (guint8 *) INVALID_NAMESPACE_MESSAGE, strlen (INVALID_NAMESPACE_MESSAGE)); + + g_assert ((stanza = wocky_xmpp_reader_pop_stanza (reader)) != NULL); + g_assert (wocky_xmpp_reader_get_state (reader) + == WOCKY_XMPP_READER_STATE_CLOSED); + + g_assert_cmpstr (VALID_NAMESPACE, ==, + wocky_node_get_ns ( + wocky_node_get_child (wocky_stanza_get_top_node (stanza), "branch"))); + + g_object_unref (stanza); + g_object_unref (reader); +} + int main (int argc, char **argv) @@ -264,6 +296,7 @@ main (int argc, g_test_add_func ("/xmpp-reader/no-stream-hunks", test_no_stream_hunks); g_test_add_func ("/xmpp-reader/no-stream-resetting", test_no_stream_reset); g_test_add_func ("/xmpp-reader/vcard-namespace", test_vcard_namespace); + g_test_add_func ("/xmpp-reader/invalid-namespace", test_invalid_namespace); result = g_test_run (); test_deinit (); diff --git a/wocky/wocky-xmpp-reader.c b/wocky/wocky-xmpp-reader.c index 4ced332..e01f685 100644 --- a/wocky/wocky-xmpp-reader.c +++ b/wocky/wocky-xmpp-reader.c @@ -404,14 +404,20 @@ wocky_xmpp_reader_new_no_stream (void) static void _start_element_ns (void *user_data, const xmlChar *localname, - const xmlChar *prefix, const xmlChar *uri, int nb_namespaces, + const xmlChar *prefix, const xmlChar *ns_uri, int nb_namespaces, const xmlChar **namespaces, int nb_attributes, int nb_defaulted, const xmlChar **attributes) { WockyXmppReader *self = WOCKY_XMPP_READER (user_data); WockyXmppReaderPrivate *priv = self->priv; + gchar *uri; int i; + if (ns_uri != NULL) + uri = g_strstrip (g_strdup ((const gchar *) ns_uri)); + else + uri = NULL; + if (priv->stream_mode && G_UNLIKELY (priv->depth == 0)) { if (strcmp ("stream", (gchar *) localname) @@ -421,7 +427,7 @@ _start_element_ns (void *user_data, const xmlChar *localname, WOCKY_XMPP_READER_ERROR_INVALID_STREAM_START, "Invalid start of the XMPP stream"); g_queue_push_tail (priv->stanzas, NULL); - return; + goto out; } DEBUG ("Received stream opening: %s, prefix: %s, uri: %s", @@ -475,7 +481,7 @@ _start_element_ns (void *user_data, const xmlChar *localname, } } priv->depth++; - return; + goto out; } if (priv->stanza == NULL) @@ -531,6 +537,9 @@ _start_element_ns (void *user_data, const xmlChar *localname, } } priv->depth++; + +out: + g_free (uri); } static void @@ -590,9 +599,11 @@ _error (void *user_data, xmlErrorPtr error) WockyXmppReader *self = WOCKY_XMPP_READER (user_data); WockyXmppReaderPrivate *priv = self->priv; - if (error->level < XML_ERR_ERROR) + if (error->level < XML_ERR_FATAL) { - DEBUG ("Ignoring parser warning: %s", error->message); + DEBUG ("Ignoring parser %s: %s", + error->level == XML_ERR_WARNING ? "warning" : "recoverable error", + error->message); return; } |