telepathy-gabble: muc-channel: enable SI stream requests again

Jonny Lamb jonny at kemper.freedesktop.org
Tue Aug 28 06:19:32 PDT 2012


Module: telepathy-gabble
Branch: master
Commit: 353db90ad65b2f5749384505bd8372ca8264f44c
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=353db90ad65b2f5749384505bd8372ca8264f44c

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Mon Mar 26 17:52:33 2012 -0400

muc-channel: enable SI stream requests again

This code came from GabbleTubesChannel.

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>

---

 src/muc-channel.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/muc-channel.h |    4 +++
 src/muc-factory.c |   18 +++++++++------
 3 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/src/muc-channel.c b/src/muc-channel.c
index e807555..fda9200 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -2043,6 +2043,67 @@ gabble_muc_channel_foreach_tubes (GabbleMucChannel *gmuc,
     }
 }
 
+void
+gabble_muc_channel_handle_si_stream_request (GabbleMucChannel *self,
+    GabbleBytestreamIface *bytestream,
+    const gchar *stream_id,
+    WockyStanza *msg)
+{
+  GabbleMucChannelPrivate *priv = self->priv;
+  WockyNode *si_node, *stream_node;
+  const gchar *tmp;
+  gchar *endptr;
+  unsigned long tube_id_tmp;
+  guint tube_id;
+  GabbleTubeIface *tube;
+
+  si_node = wocky_node_get_child_ns (
+      wocky_stanza_get_top_node (msg), "si", NS_SI);
+  g_return_if_fail (si_node != NULL);
+
+  stream_node = wocky_node_get_child_ns (si_node,
+      "muc-stream", NS_TUBES);
+  g_return_if_fail (stream_node != NULL);
+
+  tmp = wocky_node_get_attribute (stream_node, "tube");
+  if (tmp == NULL)
+    {
+      GError e = { WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_BAD_REQUEST,
+          "<muc-stream> has no tube attribute" };
+
+      NODE_DEBUG (stream_node, e.message);
+      gabble_bytestream_iface_close (bytestream, &e);
+      return;
+    }
+  tube_id_tmp = strtoul (tmp, &endptr, 10);
+  if (!endptr || *endptr || tube_id_tmp > G_MAXUINT32)
+    {
+      GError e = { WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_BAD_REQUEST,
+          "<muc-stream> tube attribute not numeric or > 2**32" };
+
+      DEBUG ("tube id is not numeric or > 2**32: %s", tmp);
+      gabble_bytestream_iface_close (bytestream, &e);
+      return;
+    }
+  tube_id = (guint) tube_id_tmp;
+
+  tube = g_hash_table_lookup (priv->tubes, GUINT_TO_POINTER (tube_id));
+  if (tube == NULL)
+    {
+      GError e = { WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_BAD_REQUEST,
+          "<muc-stream> tube attribute points to a nonexistent "
+          "tube" };
+
+      DEBUG ("tube %u doesn't exist", tube_id);
+      gabble_bytestream_iface_close (bytestream, &e);
+      return;
+    }
+
+  DEBUG ("received new bytestream request for existing tube: %u", tube_id);
+
+  gabble_tube_iface_add_bytestream (tube, bytestream);
+}
+
 static void
 tubes_presence_update (GabbleMucChannel *gmuc,
     TpHandle contact,
diff --git a/src/muc-channel.h b/src/muc-channel.h
index 32c5b92..3800f68 100644
--- a/src/muc-channel.h
+++ b/src/muc-channel.h
@@ -102,6 +102,10 @@ GabbleTubeIface * gabble_muc_channel_tube_request (GabbleMucChannel *self,
 void gabble_muc_channel_foreach_tubes (GabbleMucChannel *gmuc,
     TpExportableChannelFunc foreach, gpointer user_data);
 
+void gabble_muc_channel_handle_si_stream_request (GabbleMucChannel *self,
+    GabbleBytestreamIface *bytestream, const gchar *stream_id,
+    WockyStanza *msg);
+
 #ifdef ENABLE_VOIP
 GabbleCallMucChannel * gabble_muc_channel_get_call (GabbleMucChannel *gmuc);
 GList * gabble_muc_channel_get_call_channels (GabbleMucChannel *self);
diff --git a/src/muc-factory.c b/src/muc-factory.c
index 5338937..1cbe587 100644
--- a/src/muc-factory.c
+++ b/src/muc-factory.c
@@ -1025,26 +1025,30 @@ gabble_muc_factory_handle_si_stream_request (GabbleMucFactory *self,
   TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
      (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_ROOM);
   GabbleMucChannel *gmuc = NULL;
-  GabbleTubesChannel *tube = NULL;
+  WockyStanzaType stanza_type;
+  WockyStanzaSubType sub_type;
 
   g_return_if_fail (tp_handle_is_valid (room_repo, room_handle, NULL));
 
+  wocky_stanza_get_type_info (msg, &stanza_type, &sub_type);
+  g_return_if_fail (stanza_type == WOCKY_STANZA_TYPE_IQ);
+  g_return_if_fail (sub_type == WOCKY_STANZA_SUB_TYPE_SET);
+
   gmuc = g_hash_table_lookup (priv->text_channels,
       GUINT_TO_POINTER (room_handle));
-  g_object_get (gmuc, "tube", &tube, NULL);
 
-  if (tube == NULL)
+  if (gmuc == NULL)
     {
       GError e = { WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_BAD_REQUEST,
-          "No tubes channel available for this MUC" };
+          "No MUC channel available" };
 
-      DEBUG ("tubes channel doesn't exist for muc %d", room_handle);
+      DEBUG ("MUC channel doesn't exist handle %d", room_handle);
       gabble_bytestream_iface_close (bytestream, &e);
       return;
     }
 
-  gabble_tubes_channel_bytestream_offered (tube, bytestream, msg);
-  g_object_unref (tube);
+ gabble_muc_channel_handle_si_stream_request (
+     gmuc, bytestream, stream_id, msg);
 }
 
 GabbleMucChannel *



More information about the telepathy-commits mailing list