[telepathy-gabble/master] Expose some utility functions related to gabble/tp specific MUC functionality.

Vivek Dasmohapatra vivek at collabora.co.uk
Sun Dec 27 11:29:23 PST 2009


---
 src/error.c        |   10 +++++-----
 src/error.h        |    2 ++
 src/message-util.c |   34 ++++++++++++++++++++++++++++++++++
 src/message-util.h |    4 ++++
 4 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/src/error.c b/src/error.c
index 55dc463..a2a63aa 100644
--- a/src/error.c
+++ b/src/error.c
@@ -311,8 +311,8 @@ static const XmppErrorSpec xmpp_errors[NUM_XMPP_ERRORS] =
 };
 
 
-static GabbleXmppErrorType
-error_type_to_enum (const gchar *error_type)
+GabbleXmppErrorType
+gabble_xmpp_error_type_to_enum (const gchar *error_type)
 {
   if (!tp_strdiff (error_type, "cancel"))
     return XMPP_ERROR_TYPE_CANCEL;
@@ -355,8 +355,8 @@ gabble_xmpp_error_from_node (LmMessageNode *error_node,
   if (node_iter (error_node))
     {
       if (type_out != NULL)
-        *type_out = error_type_to_enum (lm_message_node_get_attribute (
-            error_node, "type"));
+        *type_out = gabble_xmpp_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 */
@@ -393,7 +393,7 @@ gabble_xmpp_error_from_node (LmMessageNode *error_node,
               if (cur_code == error_code)
                 {
                   if (type_out != NULL)
-                    *type_out = error_type_to_enum (spec->type);
+                    *type_out = gabble_xmpp_error_type_to_enum (spec->type);
 
                   return i;
                 }
diff --git a/src/error.h b/src/error.h
index 989311c..98a3569 100644
--- a/src/error.h
+++ b/src/error.h
@@ -92,4 +92,6 @@ const gchar *gabble_xmpp_error_string (GabbleXmppError error);
 const gchar *gabble_xmpp_error_description (GabbleXmppError error);
 GError *gabble_message_get_xmpp_error (LmMessage *msg);
 
+GabbleXmppErrorType gabble_xmpp_error_type_to_enum (const gchar *error_type);
+
 #endif /* __GABBLE_ERROR_H__ */
diff --git a/src/message-util.c b/src/message-util.c
index a033d4f..1c28306 100644
--- a/src/message-util.c
+++ b/src/message-util.c
@@ -225,6 +225,40 @@ gabble_message_util_send_chat_state (GObject *obj,
   return result;
 }
 
+TpChannelTextSendError
+gabble_tp_send_error_from_wocky_xmpp_error (WockyXmppError err)
+{
+  switch (err)
+    {
+      /* Note: Google replies with <service-unavailable/> if you send a
+       * message to someone you're not subscribed to. But
+       * http://xmpp.org/rfcs/rfc3921.html#rules explicitly says that means
+       * the user is offline and doesn't have offline storage. I think Google
+       * should be returning <forbidden/> or <not-authorized/>. --wjt
+       */
+      case WOCKY_XMPP_ERROR_SERVICE_UNAVAILABLE:
+      case WOCKY_XMPP_ERROR_RECIPIENT_UNAVAILABLE:
+        return TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE;
+
+      case WOCKY_XMPP_ERROR_ITEM_NOT_FOUND:
+      case WOCKY_XMPP_ERROR_JID_MALFORMED:
+      case WOCKY_XMPP_ERROR_REMOTE_SERVER_TIMEOUT:
+        return TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT;
+
+      case WOCKY_XMPP_ERROR_FORBIDDEN:
+      case WOCKY_XMPP_ERROR_NOT_AUTHORIZED:
+        return TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED;
+
+      case WOCKY_XMPP_ERROR_RESOURCE_CONSTRAINT:
+        return TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG;
+
+      case WOCKY_XMPP_ERROR_FEATURE_NOT_IMPLEMENTED:
+        return TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED;
+
+      default:
+        return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
+    }
+}
 
 static TpChannelTextSendError
 _tp_send_error_from_error_node (LmMessageNode *error_node,
diff --git a/src/message-util.h b/src/message-util.h
index 3da8406..7e8d743 100644
--- a/src/message-util.h
+++ b/src/message-util.h
@@ -24,6 +24,7 @@
 #include <telepathy-glib/message-mixin.h>
 
 #include <loudmouth/loudmouth.h>
+#include <wocky/wocky-xmpp-error.h>
 
 #include "connection.h"
 
@@ -46,6 +47,9 @@ gboolean gabble_message_util_parse_incoming_message (LmMessage *message,
     const gchar **id, const gchar **body_ret, gint *state,
     TpChannelTextSendError *send_error, TpDeliveryStatus *delivery_status);
 
+TpChannelTextSendError
+gabble_tp_send_error_from_wocky_xmpp_error (WockyXmppError err);
+
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_MESSAGE_UTIL_H__ */
-- 
1.5.6.5




More information about the telepathy-commits mailing list