[Telepathy-commits] [telepathy-gabble/master] gabble_xmpp_error_from_node: extract type attribute from <error>
Will Thompson
will.thompson at collabora.co.uk
Tue Feb 3 06:34:50 PST 2009
---
src/conn-aliasing.c | 3 ++-
src/conn-olpc.c | 4 ++--
src/error.c | 42 +++++++++++++++++++++++++++++++++++++++---
src/error.h | 12 +++++++++++-
src/media-factory.c | 2 +-
src/message-util.c | 2 +-
src/muc-channel.c | 4 ++--
src/register.c | 2 +-
8 files changed, 59 insertions(+), 12 deletions(-)
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 87c2383..b03735e 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -447,7 +447,8 @@ nick_publish_msg_reply_cb (GabbleConnection *conn,
if (error_node != NULL)
{
- GabbleXmppError error = gabble_xmpp_error_from_node (error_node);
+ GabbleXmppError error = gabble_xmpp_error_from_node (error_node,
+ NULL);
g_warning ("%s: can't publish nick using PEP: %s: %s", G_STRFUNC,
gabble_xmpp_error_string (error),
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 9c132a8..e475685 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -185,7 +185,7 @@ check_publish_reply_msg (LmMessage *reply_msg,
if (error_node != NULL)
{
GabbleXmppError xmpp_error = gabble_xmpp_error_from_node (
- error_node);
+ error_node, NULL);
error = g_error_new (TP_ERRORS, TP_ERROR_NETWORK_ERROR,
"Failed to publish to the PEP node: %s",
@@ -228,7 +228,7 @@ check_query_reply_msg (LmMessage *reply_msg,
if (error_node != NULL)
{
GabbleXmppError xmpp_error = gabble_xmpp_error_from_node (
- error_node);
+ error_node, NULL);
error = g_error_new (TP_ERRORS, TP_ERROR_NETWORK_ERROR,
"Failed to query the PEP node: %s",
diff --git a/src/error.c b/src/error.c
index 9d8eaf4..4dad255 100644
--- a/src/error.c
+++ b/src/error.c
@@ -310,6 +310,29 @@ static const XmppErrorSpec xmpp_errors[NUM_XMPP_ERRORS] =
},
};
+
+static GabbleXmppErrorType
+error_type_to_enum (const gchar *error_type)
+{
+ if (!tp_strdiff (error_type, "cancel"))
+ return XMPP_ERROR_TYPE_CANCEL;
+
+ if (!tp_strdiff (error_type, "continue"))
+ return XMPP_ERROR_TYPE_CONTINUE;
+
+ if (!tp_strdiff (error_type, "modify"))
+ return XMPP_ERROR_TYPE_MODIFY;
+
+ if (!tp_strdiff (error_type, "auth"))
+ return XMPP_ERROR_TYPE_AUTH;
+
+ if (!tp_strdiff (error_type, "wait"))
+ return XMPP_ERROR_TYPE_WAIT;
+
+ return XMPP_ERROR_TYPE_UNDEFINED;
+}
+
+
GQuark
gabble_xmpp_error_quark (void)
{
@@ -320,7 +343,8 @@ gabble_xmpp_error_quark (void)
}
GabbleXmppError
-gabble_xmpp_error_from_node (LmMessageNode *error_node)
+gabble_xmpp_error_from_node (LmMessageNode *error_node,
+ GabbleXmppErrorType *type_out)
{
gint i, j;
const gchar *error_code_str;
@@ -330,6 +354,10 @@ gabble_xmpp_error_from_node (LmMessageNode *error_node)
/* First, try to look it up the modern way */
if (error_node->children)
{
+ if (type_out != NULL)
+ *type_out = error_type_to_enum (lm_message_node_get_attribute (
+ error_node, "type"));
+
/* 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--)
@@ -363,11 +391,19 @@ gabble_xmpp_error_from_node (LmMessageNode *error_node)
break;
if (cur_code == error_code)
- return i;
+ {
+ if (type_out != NULL)
+ *type_out = error_type_to_enum (spec->type);
+
+ return i;
+ }
}
}
}
+ if (type_out != NULL)
+ *type_out = XMPP_ERROR_TYPE_UNDEFINED;
+
return XMPP_ERROR_UNDEFINED_CONDITION;
}
@@ -465,7 +501,7 @@ gabble_message_get_xmpp_error (LmMessage *msg)
if (error_node != NULL)
{
return gabble_xmpp_error_to_g_error
- (gabble_xmpp_error_from_node (error_node));
+ (gabble_xmpp_error_from_node (error_node, NULL));
}
else
{
diff --git a/src/error.h b/src/error.h
index 3aabb9b..f2ee265 100644
--- a/src/error.h
+++ b/src/error.h
@@ -25,6 +25,15 @@
#include <loudmouth/loudmouth.h>
typedef enum {
+ XMPP_ERROR_TYPE_UNDEFINED = 0,
+ XMPP_ERROR_TYPE_CANCEL,
+ XMPP_ERROR_TYPE_CONTINUE,
+ XMPP_ERROR_TYPE_MODIFY,
+ XMPP_ERROR_TYPE_AUTH,
+ XMPP_ERROR_TYPE_WAIT,
+} GabbleXmppErrorType;
+
+typedef enum {
XMPP_ERROR_UNDEFINED_CONDITION = 0, /* 500 */
XMPP_ERROR_REDIRECT, /* 302 */
XMPP_ERROR_GONE, /* 302 */
@@ -75,7 +84,8 @@ typedef enum {
GQuark gabble_xmpp_error_quark (void);
#define GABBLE_XMPP_ERROR (gabble_xmpp_error_quark ())
-GabbleXmppError gabble_xmpp_error_from_node (LmMessageNode *error_node);
+GabbleXmppError gabble_xmpp_error_from_node (LmMessageNode *error_node,
+ GabbleXmppErrorType *type_out);
LmMessageNode *gabble_xmpp_error_to_node (GabbleXmppError error,
LmMessageNode *parent_node, const gchar *errmsg);
const gchar *gabble_xmpp_error_string (GabbleXmppError error);
diff --git a/src/media-factory.c b/src/media-factory.c
index 95668c4..188cff4 100644
--- a/src/media-factory.c
+++ b/src/media-factory.c
@@ -594,7 +594,7 @@ jingle_info_iq_callback (LmMessageHandler *handler,
node = lm_message_node_get_child (message->node, "error");
if (node != NULL)
{
- xmpp_error = gabble_xmpp_error_from_node (node);
+ xmpp_error = gabble_xmpp_error_from_node (node, NULL);
}
DEBUG ("jingle info error: %s", gabble_xmpp_error_string (xmpp_error));
diff --git a/src/message-util.c b/src/message-util.c
index deae3cd..475a96e 100644
--- a/src/message-util.c
+++ b/src/message-util.c
@@ -222,7 +222,7 @@ _tp_send_error_from_error_node (LmMessageNode *error_node)
{
if (error_node != NULL)
{
- GabbleXmppError err = gabble_xmpp_error_from_node (error_node);
+ GabbleXmppError err = gabble_xmpp_error_from_node (error_node, NULL);
DEBUG ("got xmpp error: %s: %s", gabble_xmpp_error_string (err),
gabble_xmpp_error_description (err));
diff --git a/src/muc-channel.c b/src/muc-channel.c
index d11bd61..196176d 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -1418,7 +1418,7 @@ _gabble_muc_channel_presence_error (GabbleMucChannel *chan,
return;
}
- error = gabble_xmpp_error_from_node (error_node);
+ error = gabble_xmpp_error_from_node (error_node, NULL);
if (priv->state >= MUC_STATE_JOINED)
{
@@ -2125,7 +2125,7 @@ _gabble_muc_channel_handle_subject (GabbleMucChannel *chan,
node = lm_message_node_get_child (msg->node, "error");
if (node)
{
- GabbleXmppError xmpp_error = gabble_xmpp_error_from_node (node);
+ GabbleXmppError xmpp_error = gabble_xmpp_error_from_node (node, NULL);
err_desc = gabble_xmpp_error_description (xmpp_error);
}
diff --git a/src/register.c b/src/register.c
index 1485eea..8c5b750 100644
--- a/src/register.c
+++ b/src/register.c
@@ -214,7 +214,7 @@ set_reply_cb (GabbleConnection *conn,
{
GabbleXmppError error;
- error = gabble_xmpp_error_from_node (node);
+ error = gabble_xmpp_error_from_node (node, NULL);
if (error == XMPP_ERROR_CONFLICT)
{
code = TP_ERROR_INVALID_ARGUMENT;
--
1.5.6.5
More information about the telepathy-commits
mailing list