summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2012-05-31 13:31:54 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2012-05-31 13:54:14 +0100
commitc63a7e740c0d29b12e6688fde35f7030615745cd (patch)
treea1e4f3b462b05e34390e0d5591f63644c60d255c /src
parenta980fd2ecee2548749ca71e85f8fac688b314f0f (diff)
downloadtelepathy-salut-c63a7e740c0d29b12e6688fde35f7030615745cd.tar.gz
muc-channel: add public function to deal with offered bytestreams
Again, more code copied from tubes-channel.c. Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/muc-channel.c73
-rw-r--r--src/muc-channel.h4
2 files changed, 77 insertions, 0 deletions
diff --git a/src/muc-channel.c b/src/muc-channel.c
index 626f4ac6..e54b6ad3 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -1748,3 +1748,76 @@ salut_muc_channel_foreach (SalutMucChannel *self,
func (TP_EXPORTABLE_CHANNEL (value), user_data);
}
}
+
+void
+salut_muc_channel_bytestream_offered (SalutMucChannel *self,
+ GibberBytestreamIface *bytestream,
+ WockyStanza *msg)
+{
+ SalutMucChannelPrivate *priv = self->priv;
+ WockyNode *node = wocky_stanza_get_top_node (msg);
+ const gchar *stream_id, *tmp;
+ gchar *endptr;
+ WockyNode *si_node, *stream_node;
+ guint tube_id;
+ unsigned long tube_id_tmp;
+ SalutTubeIface *tube;
+ WockyStanzaType type;
+ WockyStanzaSubType sub_type;
+
+ /* Caller is expected to have checked that we have a stream or muc-stream
+ * node with a stream ID and the TUBES profile
+ */
+ wocky_stanza_get_type_info (msg, &type, &sub_type);
+ g_return_if_fail (type == WOCKY_STANZA_TYPE_IQ);
+ g_return_if_fail (sub_type == WOCKY_STANZA_SUB_TYPE_SET);
+
+ si_node = wocky_node_get_child_ns (node, "si",
+ WOCKY_XMPP_NS_SI);
+ g_return_if_fail (si_node != NULL);
+
+ stream_node = wocky_node_get_child_ns (si_node,
+ "muc-stream", WOCKY_TELEPATHY_NS_TUBES);
+ g_return_if_fail (stream_node != NULL);
+
+ stream_id = wocky_node_get_attribute (si_node, "id");
+ g_return_if_fail (stream_id != 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" };
+
+ DEBUG ("%s", e.message);
+ gibber_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);
+ gibber_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);
+ gibber_bytestream_iface_close (bytestream, &e);
+ return;
+ }
+
+ DEBUG ("received new bytestream request for existing tube: %u", tube_id);
+
+ salut_tube_iface_add_bytestream (tube, bytestream);
+}
diff --git a/src/muc-channel.h b/src/muc-channel.h
index 47abcb5f..8c888d18 100644
--- a/src/muc-channel.h
+++ b/src/muc-channel.h
@@ -96,6 +96,10 @@ SalutTubeIface * salut_muc_channel_tube_request (SalutMucChannel *self,
void salut_muc_channel_foreach (SalutMucChannel *self,
TpExportableChannelFunc func, gpointer user_data);
+void salut_muc_channel_bytestream_offered (SalutMucChannel *self,
+ GibberBytestreamIface *bytestream,
+ WockyStanza *msg);
+
G_END_DECLS
#endif /* #ifndef __SALUT_MUC_CHANNEL_H__*/