[Telepathy-commits] [telepathy-salut/master] Start to parse iq query and replies

Alban Crequy alban.crequy at collabora.co.uk
Tue Nov 25 03:59:10 PST 2008


20080424160747-a41c0-89117deaf72726dafa3fe5b9baec9bbe138ecb8f.gz
---
 src/salut-tubes-channel.c |   21 ++++++++++++---
 src/salut-tubes-manager.c |   62 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/src/salut-tubes-channel.c b/src/salut-tubes-channel.c
index 2e2f58a..f9d2164 100644
--- a/src/salut-tubes-channel.c
+++ b/src/salut-tubes-channel.c
@@ -1753,11 +1753,24 @@ stream_tube_new_connection_cb (SalutTubeIface *tube,
 
 static void
 iq_reply_cb (GibberIqHelper *helper,
-            GibberXmppStanza *sent_stanza,
-            GibberXmppStanza *reply_stanza,
-            GObject *object,
-            gpointer user_data)
+             GibberXmppStanza *sent_stanza,
+             GibberXmppStanza *reply_stanza,
+             GObject *object,
+             gpointer user_data)
 {
+  /*
+  SalutTubesChannel *self = (SalutTubesChannel *) user_data;
+  SalutTubesChannelPrivate *priv = SALUT_TUBES_CHANNEL_GET_PRIVATE (self);
+  */
+  GibberStanzaSubType sub_type;
+
+  gibber_xmpp_stanza_get_type_info (reply_stanza, NULL, &sub_type);
+  if (sub_type != GIBBER_STANZA_SUB_TYPE_RESULT)
+    {
+      DEBUG ("tube offer declined declined");
+      return;
+    }
+
   DEBUG ("Got a IQ reply :-)");
 }
 
diff --git a/src/salut-tubes-manager.c b/src/salut-tubes-manager.c
index 55601a7..2eba88a 100644
--- a/src/salut-tubes-manager.c
+++ b/src/salut-tubes-manager.c
@@ -121,6 +121,39 @@ iq_tube_request_filter (SalutXmppConnectionManager *xcm,
                  GIBBER_TELEPATHY_NS_TUBES) != NULL);
 }
 
+static gboolean
+iq_tube_request_parse (GibberXmppStanza *stanza,
+                       const gchar **from,
+                       const gchar **tube_type,
+                       const gchar **id)
+{
+  GibberXmppNode *iq;
+  GibberXmppNode *tube;
+
+  iq = stanza->node;
+
+  *from = gibber_xmpp_node_get_attribute (stanza->node, "from");
+  if (*from == NULL)
+    {
+      DEBUG ("got a message without a from field");
+      return FALSE;
+    }
+
+  tube = gibber_xmpp_node_get_child_ns (iq, "tube",
+      GIBBER_TELEPATHY_NS_TUBES);
+  if (tube == NULL)
+    {
+      DEBUG ("The <iq> does not have a <tube>");
+      return FALSE;
+    }
+
+  *id = gibber_xmpp_node_get_attribute (iq, "id");
+
+  *tube_type = "";
+
+  return TRUE;
+}
+
 static void
 iq_tube_request_cb (SalutXmppConnectionManager *xcm,
                     GibberXmppConnection *conn,
@@ -133,19 +166,36 @@ iq_tube_request_cb (SalutXmppConnectionManager *xcm,
   SalutTubesManagerPrivate *priv =
     SALUT_TUBES_MANAGER_GET_PRIVATE (self);
   */
-  GibberXmppNode *tube, *close;
+  GibberXmppNode *close;
   GibberXmppStanza *reply;
+  const gchar *from, *tube_type, *id;
 
   /* after this point, the message is for us, so in all cases we either handle
    * it or send an error reply */
 
-  tube = gibber_xmpp_node_get_child_ns (stanza->node, "tube", GIBBER_TELEPATHY_NS_TUBES);
-  close = gibber_xmpp_node_get_child_ns (stanza->node, "close", GIBBER_TELEPATHY_NS_TUBES);
+  close = gibber_xmpp_node_get_child_ns (stanza->node, "close",
+      GIBBER_TELEPATHY_NS_TUBES);
+  if (close != NULL)
+    {
+      DEBUG ("received a close tube request. Not implemented.");
+      return;
+    }
+
+  if (!iq_tube_request_parse (stanza, &from, &tube_type, &id))
+    {
+      GibberXmppStanza *reply;
+
+      reply = gibber_iq_helper_new_error_reply (stanza, XMPP_ERROR_BAD_REQUEST,
+          "failed to parse SI request");
+      gibber_xmpp_connection_send (conn, reply, NULL);
+
+      g_object_unref (reply);
+      return;
+    }
 
-  DEBUG ("received a tube request: tube=%p close=%p", tube, close);
+  DEBUG ("received a tube request of type %s, id %s", tube_type, id);
 
-  reply = gibber_iq_helper_new_error_reply (stanza, XMPP_ERROR_FEATURE_NOT_IMPLEMENTED,
-      "Implementation not finished yet...");
+  reply = gibber_iq_helper_new_result_reply (stanza);
   gibber_xmpp_connection_send (conn, reply, NULL);
 
   g_object_unref (reply);
-- 
1.5.6.5




More information about the Telepathy-commits mailing list