diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-03-10 15:55:29 +0100 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-03-10 16:25:50 +0100 |
commit | a17332c8441b3e5dddb46ff50987bb1f38def647 (patch) | |
tree | 4b1072b0c09d90087b8e037fa1d62fb78b8be76e | |
parent | 71303eba13770a8628b8af62c3b08e9c6fb79954 (diff) |
Refine behavior of wocky_xmpp_error_extract() for specialized errors.
We return the first specialized error. There should only be one
according to the XMPP specs. @specialized and @specialized_node always
match.
https://bugs.freedesktop.org/show_bug.cgi?id=35086
-rw-r--r-- | tests/wocky-stanza-test.c | 68 | ||||
-rw-r--r-- | wocky/wocky-xmpp-error.c | 11 |
2 files changed, 68 insertions, 11 deletions
diff --git a/tests/wocky-stanza-test.c b/tests/wocky-stanza-test.c index 2f6e782..135053d 100644 --- a/tests/wocky-stanza-test.c +++ b/tests/wocky-stanza-test.c @@ -402,12 +402,14 @@ test_extract_errors_application_specific_unknown (void) g_assert_no_error (specialized); - /* This is questionable: maybe wocky_xmpp_error_extract() should assume that - * a child of <error/> in a NS it doesn't understand is a specialized error, - * rather than requiring the ns to be registered with - * wocky_xmpp_error_register_domain(). + /* The namespace is not registered, @specialized is not set. However we + * assume that any other namespace element is a specialized error, and it + * should get returned in @specialized_node */ - g_assert (specialized_node == NULL); + g_assert (specialized_node); + g_assert_cmpstr (specialized_node->name, ==, "buy-a-private-cloud"); + g_assert_cmpstr (wocky_node_get_ns (specialized_node), ==, + "http://example.com/angry-cloud"); g_object_unref (stanza); } @@ -464,6 +466,57 @@ test_extract_errors_jingle_error (void) } static void +test_extract_errors_extra_application_specific (void) +{ + WockyStanza *stanza; + const gchar *description = "I am a sentence."; + WockyXmppErrorType type; + GError *core = NULL, *specialized = NULL; + WockyNode *specialized_node = NULL; + + /* Jingle error! + Bogus extra app specific error, which should be ignored */ + stanza = wocky_stanza_build ( + WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_ERROR, + "from", "to", + '(', "error", + '@', "type", "cancel", + '(', "tie-break", + ':', WOCKY_XMPP_NS_JINGLE_ERRORS, + ')', + '(', "out-of-order", + ':', WOCKY_XMPP_NS_JINGLE_ERRORS, + ')', + '(', "text", + ':', WOCKY_XMPP_NS_STANZAS, + '$', description, + ')', + '(', "conflict", + ':', WOCKY_XMPP_NS_STANZAS, + ')', + ')', + NULL); + + wocky_stanza_extract_errors (stanza, &type, &core, &specialized, + &specialized_node); + + g_assert_cmpuint (type, ==, WOCKY_XMPP_ERROR_TYPE_CANCEL); + + g_assert_error (core, WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_CONFLICT); + g_assert_cmpstr (core->message, ==, description); + g_clear_error (&core); + + g_assert_error (specialized, WOCKY_JINGLE_ERROR, + WOCKY_JINGLE_ERROR_TIE_BREAK); + g_assert_cmpstr (specialized->message, ==, description); + g_clear_error (&specialized); + + g_assert (specialized_node != NULL); + g_assert_cmpstr (specialized_node->name, ==, "tie-break"); + + g_object_unref (stanza); +} + +static void test_extract_errors_legacy_code (void) { WockyStanza *stanza; @@ -531,7 +584,8 @@ test_extract_errors_no_sense (void) g_clear_error (&core); g_assert_no_error (specialized); - g_assert (specialized_node == NULL); + g_assert (specialized_node != NULL); + g_assert_cmpstr (specialized_node->name, ==, "hoobily-lala-whee"); g_object_unref (stanza); } @@ -697,6 +751,8 @@ main (int argc, char **argv) test_extract_errors_application_specific_unknown); g_test_add_func ("/xmpp-stanza/errors/jingle-error", test_extract_errors_jingle_error); + g_test_add_func ("/xmpp-stanza/errors/extra-application-specific", + test_extract_errors_extra_application_specific); g_test_add_func ("/xmpp-stanza/errors/legacy-code", test_extract_errors_legacy_code); g_test_add_func ("/xmpp-stanza/errors/no-sense", diff --git a/wocky/wocky-xmpp-error.c b/wocky/wocky-xmpp-error.c index 3b1c402..44f98f1 100644 --- a/wocky/wocky-xmpp-error.c +++ b/wocky/wocky-xmpp-error.c @@ -439,19 +439,20 @@ wocky_xmpp_error_extract (WockyNode *error, child->name, &core_code); } } - else if (specialized_domain == 0) + else if (specialized_node_tmp == NULL) { + WockyXmppErrorDomain *domain; + + specialized_node_tmp = child; + /* This could be a specialized error; let's check if it's in a * namespace we know about, and if so that it's an element name we * know. */ - WockyXmppErrorDomain *domain = xmpp_error_find_domain (child->ns); - + domain = xmpp_error_find_domain (child->ns); if (domain != NULL) { - specialized_node_tmp = child; specialized_domain = child->ns; - if (wocky_enum_from_nick (domain->enum_type, child->name, &specialized_code)) { |