diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-05-04 14:27:04 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-05-04 14:27:04 +0100 |
commit | b1de837ebae853467aff11fb5096a934dfb865a5 (patch) | |
tree | 57390620f08f67590c0f8046fe3e8eae6c37c974 /lib/gibber | |
parent | 01a4df8810bf41ecbb8c44eb3ce10d0a360dd379 (diff) | |
download | telepathy-salut-b1de837ebae853467aff11fb5096a934dfb865a5.tar.gz |
gibber-xmpp-error: remove
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'lib/gibber')
-rw-r--r-- | lib/gibber/Makefile.am | 2 | ||||
-rw-r--r-- | lib/gibber/gibber-xmpp-error.c | 481 | ||||
-rw-r--r-- | lib/gibber/gibber-xmpp-error.h | 86 | ||||
-rw-r--r-- | lib/gibber/tests/Makefile.am | 1 | ||||
-rw-r--r-- | lib/gibber/tests/check-gibber-xmpp-error.c | 145 |
5 files changed, 0 insertions, 715 deletions
diff --git a/lib/gibber/Makefile.am b/lib/gibber/Makefile.am index f4e7ed24..1305fc47 100644 --- a/lib/gibber/Makefile.am +++ b/lib/gibber/Makefile.am @@ -51,8 +51,6 @@ HANDWRITTEN_SOURCES = \ gibber-oob-file-transfer.h \ gibber-listener.c \ gibber-listener.h \ - gibber-xmpp-error.h \ - gibber-xmpp-error.c \ gibber-sockets.c \ gibber-sockets.h \ gibber-sockets-unix.h \ diff --git a/lib/gibber/gibber-xmpp-error.c b/lib/gibber/gibber-xmpp-error.c deleted file mode 100644 index 2ec6c1b1..00000000 --- a/lib/gibber/gibber-xmpp-error.c +++ /dev/null @@ -1,481 +0,0 @@ -/* - * gibber-xmpp-error.c - Source for Gibber's XMPP error handling API - * Copyright (C) 2006-2007 Collabora Ltd. - * Copyright (C) 2006 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "gibber-xmpp-error.h" - -#include <stdlib.h> -#include <stdio.h> - -#include <wocky/wocky-namespaces.h> - -#define MAX_LEGACY_ERRORS 3 - -typedef struct { - const gchar *name; - const gchar *description; - const gchar *type; - guint specialises; - const gchar *namespace; - const guint16 legacy_errors[MAX_LEGACY_ERRORS]; -} XmppErrorSpec; - -static const XmppErrorSpec xmpp_errors[NUM_XMPP_ERRORS] = -{ - { - "undefined-condition", - "application-specific condition", - NULL, - 0, - WOCKY_XMPP_NS_STANZAS, - { 500, 0, }, - }, - { - "redirect", - "the recipient or server is redirecting requests for this information " - "to another entity", - "modify", - 0, - WOCKY_XMPP_NS_STANZAS, - { 302, 0, }, - }, - - { - "gone", - "the recipient or server can no longer be contacted at this address", - "modify", - 0, - WOCKY_XMPP_NS_STANZAS, - { 302, 0, }, - }, - - { - "bad-request", - "the sender has sent XML that is malformed or that cannot be processed", - "modify", - 0, - WOCKY_XMPP_NS_STANZAS, - { 400, 0, }, - }, - { - "unexpected-request", - "the recipient or server understood the request but was not expecting " - "it at this time", - "wait", - 0, - WOCKY_XMPP_NS_STANZAS, - { 400, 0, }, - }, - { - "jid-malformed", - "the sending entity has provided or communicated an XMPP address or " - "aspect thereof (e.g., a resource identifier) that does not adhere " - "to the syntax defined in Addressing Scheme (Section 3)", - "modify", - 0, - WOCKY_XMPP_NS_STANZAS, - { 400, 0, }, - }, - - { - "not-authorized", - "the sender must provide proper credentials before being allowed to " - "perform the action, or has provided improper credentials", - "auth", - 0, - WOCKY_XMPP_NS_STANZAS, - { 401, 0, }, - }, - - { - "payment-required", - "the requesting entity is not authorized to access the requested " - "service because payment is required", - "auth", - 0, - WOCKY_XMPP_NS_STANZAS, - { 402, 0, }, - }, - - { - "forbidden", - "the requesting entity does not possess the required permissions to " - "perform the action", - "auth", - 0, - WOCKY_XMPP_NS_STANZAS, - { 403, 0, }, - }, - - { - "item-not-found", - "the addressed JID or item requested cannot be found", - "cancel", - 0, - WOCKY_XMPP_NS_STANZAS, - { 404, 0, }, - }, - { - "recipient-unavailable", - "the intended recipient is temporarily unavailable", - "wait", - 0, - WOCKY_XMPP_NS_STANZAS, - { 404, 0, }, - }, - { - "remote-server-not-found", - "a remote server or service specified as part or all of the JID of the " - "intended recipient (or required to fulfill a request) could not be " - "contacted within a reasonable amount of time", - "cancel", - 0, - WOCKY_XMPP_NS_STANZAS, - { 404, 0, }, - }, - - { - "not-allowed", - "the recipient or server does not allow any entity to perform the action", - "cancel", - 0, - WOCKY_XMPP_NS_STANZAS, - { 405, 0, }, - }, - - { - "not-acceptable", - "the recipient or server understands the request but is refusing to " - "process it because it does not meet criteria defined by the recipient " - "or server (e.g., a local policy regarding acceptable words in messages)", - "modify", - 0, - WOCKY_XMPP_NS_STANZAS, - { 406, 0, }, - }, - - { - "registration-required", - "the requesting entity is not authorized to access the requested service " - "because registration is required", - "auth", - 0, - WOCKY_XMPP_NS_STANZAS, - { 407, 0, }, - }, - { - "subscription-required", - "the requesting entity is not authorized to access the requested service " - "because a subscription is required", - "auth", - 0, - WOCKY_XMPP_NS_STANZAS, - { 407, 0, }, - }, - - { - "remote-server-timeout", - "a remote server or service specified as part or all of the JID of the " - "intended recipient (or required to fulfill a request) could not be " - "contacted within a reasonable amount of time", - "wait", - 0, - WOCKY_XMPP_NS_STANZAS, - { 408, 504, 0, }, - }, - - { - "conflict", - "access cannot be granted because an existing resource or session exists " - "with the same name or address", - "cancel", - 0, - WOCKY_XMPP_NS_STANZAS, - { 409, 0, }, - }, - - { - "internal-server-error", - "the server could not process the stanza because of a misconfiguration " - "or an otherwise-undefined internal server error", - "wait", - 0, - WOCKY_XMPP_NS_STANZAS, - { 500, 0, }, - }, - { - "resource-constraint", - "the server or recipient lacks the system resources necessary to service " - "the request", - "wait", - 0, - WOCKY_XMPP_NS_STANZAS, - { 500, 0, }, - }, - - { - "feature-not-implemented", - "the feature requested is not implemented by the recipient or server and " - "therefore cannot be processed", - "cancel", - 0, - WOCKY_XMPP_NS_STANZAS, - { 501, 0, }, - }, - - { - "service-unavailable", - "the server or recipient does not currently provide the requested " - "service", - "cancel", - 0, - WOCKY_XMPP_NS_STANZAS, - { 502, 503, 510, }, - }, - - { - "out-of-order", - "the request cannot occur at this point in the state machine", - "cancel", - XMPP_ERROR_UNEXPECTED_REQUEST, - WOCKY_XMPP_NS_JINGLE_ERRORS, - { 0, }, - }, - - { - "unknown-session", - "the 'sid' attribute specifies a session that is unknown to the " - "recipient", - "cancel", - XMPP_ERROR_BAD_REQUEST, - WOCKY_XMPP_NS_JINGLE_ERRORS, - { 0, }, - }, - - { - "unsupported-transports", - "the recipient does not support any of the desired content transport " - "methods", - "cancel", - XMPP_ERROR_FEATURE_NOT_IMPLEMENTED, - WOCKY_XMPP_NS_JINGLE_ERRORS, - { 0, }, - }, - - { - "unsupported-content", - "the recipient does not support any of the desired content description" - "formats", - "cancel", - XMPP_ERROR_FEATURE_NOT_IMPLEMENTED, - WOCKY_XMPP_NS_JINGLE_ERRORS, - { 0, }, - }, - - { - "no-valid-streams", - "None of the available streams are acceptable.", - "cancel", - XMPP_ERROR_BAD_REQUEST, - WOCKY_XMPP_NS_SI, - { 400, 0 }, - }, - - { - "bad-profile", - "The profile is not understood or invalid.", - "modify", - XMPP_ERROR_BAD_REQUEST, - WOCKY_XMPP_NS_SI, - { 400, 0 }, - }, -}; - -GQuark -gibber_xmpp_error_quark (void) -{ - static GQuark quark = 0; - if (!quark) - quark = g_quark_from_static_string ("gibber-xmpp-error"); - return quark; -} - -GibberXmppError -gibber_xmpp_error_from_node (WockyNode *error_node) -{ - gint i, j; - const gchar *error_code_str; - - g_return_val_if_fail (error_node != NULL, XMPP_ERROR_UNDEFINED_CONDITION); - - /* First, try to look it up the modern way */ - if (error_node->children) - { - /* we loop backwards because the most specific errors are the larger - * numbers; the >= 0 test is OK because i is signed */ - for (i = NUM_XMPP_ERRORS - 1; i >= 0; i--) - { - if (wocky_node_get_child_ns (error_node, xmpp_errors[i].name, - xmpp_errors[i].namespace)) - { - return i; - } - } - } - - /* Ok, do it the legacy way */ - error_code_str = wocky_node_get_attribute (error_node, "code"); - if (error_code_str) - { - gint error_code; - - error_code = atoi (error_code_str); - - /* skip UNDEFINED_CONDITION, we want code 500 to be translated - * to INTERNAL_SERVER_ERROR */ - for (i = 1; i < NUM_XMPP_ERRORS; i++) - { - const XmppErrorSpec *spec = &xmpp_errors[i]; - - for (j = 0; j < MAX_LEGACY_ERRORS; j++) - { - gint cur_code = spec->legacy_errors[j]; - if (cur_code == 0) - break; - - if (cur_code == error_code) - return i; - } - } - } - - return XMPP_ERROR_UNDEFINED_CONDITION; -} - -static GError * -gibber_xmpp_error_to_g_error (GibberXmppError error) -{ - if (error >= NUM_XMPP_ERRORS) - return g_error_new (GIBBER_XMPP_ERROR, XMPP_ERROR_UNDEFINED_CONDITION, - "Unknown or invalid XMPP error"); - - return g_error_new_literal (GIBBER_XMPP_ERROR, error, - xmpp_errors[error].description); -} - -/* - * See RFC 3920: 4.7 Stream Errors, 9.3 Stanza Errors. - */ -WockyNode * -gibber_xmpp_error_to_node (GibberXmppError error, - WockyNode *parent_node, - const gchar *errmsg) -{ - const XmppErrorSpec *spec, *extra; - WockyNode *error_node, *node; - gchar str[6]; - - g_return_val_if_fail (error != XMPP_ERROR_UNDEFINED_CONDITION && - error < NUM_XMPP_ERRORS, NULL); - - if (xmpp_errors[error].specialises) - { - extra = &xmpp_errors[error]; - spec = &xmpp_errors[extra->specialises]; - } - else - { - extra = NULL; - spec = &xmpp_errors[error]; - } - - error_node = wocky_node_add_child (parent_node, "error"); - - sprintf (str, "%d", spec->legacy_errors[0]); - wocky_node_set_attribute (error_node, "code", str); - - if (spec->type) - { - wocky_node_set_attribute (error_node, "type", spec->type); - } - - node = wocky_node_add_child_ns (error_node, spec->name, - WOCKY_XMPP_NS_STANZAS); - - if (extra != NULL) - { - node = wocky_node_add_child_ns (error_node, extra->name, - extra->namespace); - } - - if (NULL != errmsg) - { - node = wocky_node_add_child (error_node, "text"); - wocky_node_set_content (node, errmsg); - } - - return error_node; -} - -const gchar * -gibber_xmpp_error_string (GibberXmppError error) -{ - if (error < NUM_XMPP_ERRORS) - return xmpp_errors[error].name; - else - return NULL; -} - -const gchar * -gibber_xmpp_error_description (GibberXmppError error) -{ - if (error < NUM_XMPP_ERRORS) - return xmpp_errors[error].description; - else - return NULL; -} - -GError * -gibber_message_get_xmpp_error (WockyStanza *msg) -{ - WockyStanzaSubType sub_type; - g_return_val_if_fail (msg != NULL, NULL); - - wocky_stanza_get_type_info (msg, NULL, &sub_type); - - if (sub_type == WOCKY_STANZA_SUB_TYPE_ERROR) - { - WockyNode *error_node = wocky_node_get_child ( - wocky_stanza_get_top_node (msg), "error"); - - if (error_node != NULL) - { - return gibber_xmpp_error_to_g_error - (gibber_xmpp_error_from_node (error_node)); - } - else - { - return g_error_new (GIBBER_XMPP_ERROR, - XMPP_ERROR_UNDEFINED_CONDITION, "Unknown or invalid XMPP error"); - } - } - - /* no error */ - return NULL; -} diff --git a/lib/gibber/gibber-xmpp-error.h b/lib/gibber/gibber-xmpp-error.h deleted file mode 100644 index 8e7a540a..00000000 --- a/lib/gibber/gibber-xmpp-error.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * gibber-xmpp-error.h - Header for Gibber's XMPP error handling API - * Copyright (C) 2006-2007 Collabora Ltd. - * Copyright (C) 2006 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __GIBBER_XMPP_ERROR_H__ -#define __GIBBER_XMPP_ERROR_H__ - -#include <glib.h> -#include <wocky/wocky-stanza.h> - -typedef enum { - XMPP_ERROR_UNDEFINED_CONDITION = 0, /* 500 */ - - XMPP_ERROR_REDIRECT, /* 302 */ - XMPP_ERROR_GONE, /* 302 */ - - XMPP_ERROR_BAD_REQUEST, /* 400 */ - XMPP_ERROR_UNEXPECTED_REQUEST, /* 400 */ - XMPP_ERROR_JID_MALFORMED, /* 400 */ - - XMPP_ERROR_NOT_AUTHORIZED, /* 401 */ - - XMPP_ERROR_PAYMENT_REQUIRED, /* 402 */ - - XMPP_ERROR_FORBIDDEN, /* 403 */ - - XMPP_ERROR_ITEM_NOT_FOUND, /* 404 */ - XMPP_ERROR_RECIPIENT_UNAVAILABLE, /* 404 */ - XMPP_ERROR_REMOTE_SERVER_NOT_FOUND, /* 404 */ - - XMPP_ERROR_NOT_ALLOWED, /* 405 */ - - XMPP_ERROR_NOT_ACCEPTABLE, /* 406 */ - - XMPP_ERROR_REGISTRATION_REQUIRED, /* 407 */ - XMPP_ERROR_SUBSCRIPTION_REQUIRED, /* 407 */ - - XMPP_ERROR_REMOTE_SERVER_TIMEOUT, /* 408, 504 */ - - XMPP_ERROR_CONFLICT, /* 409 */ - - XMPP_ERROR_INTERNAL_SERVER_ERROR, /* 500 */ - XMPP_ERROR_RESOURCE_CONSTRAINT, /* 500 */ - - XMPP_ERROR_FEATURE_NOT_IMPLEMENTED, /* 501 */ - - XMPP_ERROR_SERVICE_UNAVAILABLE, /* 502, 503, 510 */ - - XMPP_ERROR_JINGLE_OUT_OF_ORDER, - XMPP_ERROR_JINGLE_UNKNOWN_SESSION, - XMPP_ERROR_JINGLE_UNSUPPORTED_CONTENT, - XMPP_ERROR_JINGLE_UNSUPPORTED_TRANSPORT, - - XMPP_ERROR_SI_NO_VALID_STREAMS, - XMPP_ERROR_SI_BAD_PROFILE, - - NUM_XMPP_ERRORS, -} GibberXmppError; - -GQuark gibber_xmpp_error_quark (void); -#define GIBBER_XMPP_ERROR (gibber_xmpp_error_quark ()) - -GibberXmppError gibber_xmpp_error_from_node (WockyNode *error_node); -WockyNode *gibber_xmpp_error_to_node (GibberXmppError error, - WockyNode *parent_node, const gchar *errmsg); -const gchar *gibber_xmpp_error_string (GibberXmppError error); -const gchar *gibber_xmpp_error_description (GibberXmppError error); -GError *gibber_message_get_xmpp_error (WockyStanza *msg); - -#endif /* __GIBBER_XMPP_ERROR_H__ */ diff --git a/lib/gibber/tests/Makefile.am b/lib/gibber/tests/Makefile.am index 36c49712..8fe6e19b 100644 --- a/lib/gibber/tests/Makefile.am +++ b/lib/gibber/tests/Makefile.am @@ -65,7 +65,6 @@ check_PROGRAMS = \ check-gibber-r-multicast-packet \ check-gibber-r-multicast-sender \ check-gibber-listener \ - check-gibber-xmpp-error \ check-gibber-unix-transport test: ${TEST_PROGS} diff --git a/lib/gibber/tests/check-gibber-xmpp-error.c b/lib/gibber/tests/check-gibber-xmpp-error.c deleted file mode 100644 index 926b2720..00000000 --- a/lib/gibber/tests/check-gibber-xmpp-error.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * check-gibber-xmpp-error.c - Test for gibber-xmpp-error functions - * Copyright (C) 2007 Collabora Ltd. - * @author Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <gibber/gibber-xmpp-error.h> - -#define DEBUG_FLAG DEBUG_XMPP -#include <gibber/gibber-debug.h> - -static void -test_xmpp_error_to_node_with_bad_request (void) -{ - WockyStanza *stanza; - WockyNode *node; - const gchar *code; - const gchar *type; - - stanza = wocky_stanza_build ( - WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_ERROR, - "from", "to", - NULL); - node = gibber_xmpp_error_to_node (XMPP_ERROR_BAD_REQUEST, - wocky_stanza_get_top_node (stanza), NULL); - - g_assert (node != NULL); - g_assert_cmpstr (node->name, ==, "error"); - - code = wocky_node_get_attribute (node, "code"); - g_assert (!(code == NULL || strcmp (code, "400") != 0)); - - type = wocky_node_get_attribute (node, "type"); - g_assert (!(type == NULL || strcmp (type, "modify") != 0)); - - g_assert (wocky_node_get_child_ns (node, "bad-request", - "urn:ietf:params:xml:ns:xmpp-stanzas") != NULL); - - g_object_unref (stanza); -} - -static void -test_xmpp_error_to_node_with_si_bad_profile (void) -{ - WockyStanza *stanza; - WockyNode *node; - const gchar *code; - const gchar *type; - - stanza = wocky_stanza_build ( - WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_ERROR, - "from", "to", - NULL); - node = gibber_xmpp_error_to_node (XMPP_ERROR_SI_BAD_PROFILE, - wocky_stanza_get_top_node (stanza), NULL); - - g_assert (node != NULL); - g_assert_cmpstr (node->name, ==, "error"); - - code = wocky_node_get_attribute (node, "code"); - g_assert (!(code == NULL || strcmp (code, "400") != 0)); - - type = wocky_node_get_attribute (node, "type"); - g_assert (!(type == NULL || strcmp (type, "modify") != 0)); - - g_assert (wocky_node_get_child_ns (node, "bad-request", - "urn:ietf:params:xml:ns:xmpp-stanzas") != NULL); - - g_assert (wocky_node_get_child_ns (node, "bad-profile", - "http://jabber.org/protocol/si") != NULL); - - g_object_unref (stanza); -} - -static void -test_xmpp_error_to_node (void) -{ - test_xmpp_error_to_node_with_bad_request (); - test_xmpp_error_to_node_with_si_bad_profile (); -} - -static void -test_message_get_xmpp_error (void) -{ - GibberXmppError xmpp_error; - - for (xmpp_error = 1; xmpp_error < NUM_XMPP_ERRORS; xmpp_error++) - { - WockyStanza *stanza; - GError *error = NULL; - - stanza = wocky_stanza_build ( - WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_ERROR, - "from", "to", - NULL); - gibber_xmpp_error_to_node (xmpp_error, - wocky_stanza_get_top_node (stanza), NULL); - - error = gibber_message_get_xmpp_error (stanza); - g_assert (error != NULL); - - g_assert (error->domain == GIBBER_XMPP_ERROR); - g_assert (error->code == (gint) xmpp_error); - g_assert_cmpstr (error->message, ==, - gibber_xmpp_error_description (xmpp_error)); - - g_object_unref (stanza); - g_error_free (error); - } - -} - -int -main (int argc, - char **argv) -{ - g_test_init (&argc, &argv, NULL); - g_type_init (); - - g_test_add_func ("/gibber/xmpp-error/to-node", - test_xmpp_error_to_node); - g_test_add_func ("/gibber/xmpp-error/message-get-xmpp-error", - test_message_get_xmpp_error); - - return g_test_run (); -} |