diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-03-26 17:52:33 -0400 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-18 09:09:46 +0100 |
commit | 1b245cccca2f3863adb211aca95548494e08b909 (patch) | |
tree | d1e6f1b57d5d1e258b8d64bdc276e5f725e5a356 | |
parent | 3ff4f054d6220a515cd00481ebad6da50628f21f (diff) |
muc-channel: enable SI stream requests again
This code came from GabbleTubesChannel.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | src/muc-channel.c | 61 | ||||
-rw-r--r-- | src/muc-channel.h | 4 | ||||
-rw-r--r-- | 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 e8075559f..fda9200c5 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 32c5b929b..3800f680a 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 53389379f..1cbe58739 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 * |