From a17634a620622b765118e8eae39df6a5754d8f4d Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 31 May 2012 13:23:44 +0100 Subject: muc-channel: add extract_tube_information This is copied from tubes-channel.c (soon to be removed). Signed-off-by: Jonny Lamb --- src/muc-channel.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'src') diff --git a/src/muc-channel.c b/src/muc-channel.c index e316c795..b961e887 100644 --- a/src/muc-channel.c +++ b/src/muc-channel.c @@ -936,6 +936,105 @@ salut_muc_channel_remove_members (SalutMucChannel *self, tp_intset_destroy (empty); } +/* tube_node is a MUC */ +static gboolean +extract_tube_information (SalutMucChannel *self, + WockyNode *tube_node, + TpTubeType *type, + TpHandle *initiator_handle, + const gchar **service, + GHashTable **parameters, + guint *tube_id) +{ + TpBaseChannel *base = TP_BASE_CHANNEL (self); + TpBaseConnection *base_conn = tp_base_channel_get_connection (base); + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( + base_conn, TP_HANDLE_TYPE_CONTACT); + + if (type != NULL) + { + const gchar *_type; + + _type = wocky_node_get_attribute (tube_node, "type"); + + + if (!tp_strdiff (_type, "stream")) + { + *type = TP_TUBE_TYPE_STREAM; + } + else if (!tp_strdiff (_type, "dbus")) + { + *type = TP_TUBE_TYPE_DBUS; + } + else + { + DEBUG ("Unknown tube type: %s", _type); + return FALSE; + } + } + + if (initiator_handle != NULL) + { + const gchar *initiator; + + initiator = wocky_node_get_attribute (tube_node, "initiator"); + + if (initiator != NULL) + { + *initiator_handle = tp_handle_ensure (contact_repo, initiator, NULL, + NULL); + + if (*initiator_handle == 0) + { + DEBUG ("invalid initiator ID %s", initiator); + return FALSE; + } + } + else + { + *initiator_handle = 0; + } + } + + if (service != NULL) + { + *service = wocky_node_get_attribute (tube_node, "service"); + } + + if (parameters != NULL) + { + WockyNode *node; + + node = wocky_node_get_child (tube_node, "parameters"); + *parameters = salut_wocky_node_extract_properties (node, + "parameter"); + } + + if (tube_id != NULL) + { + const gchar *str; + gchar *endptr; + long int tmp; + + str = wocky_node_get_attribute (tube_node, "id"); + if (str == NULL) + { + DEBUG ("no tube id in SI request"); + return FALSE; + } + + tmp = strtol (str, &endptr, 10); + if (!endptr || *endptr) + { + DEBUG ("tube id is not numeric: %s", str); + return FALSE; + } + *tube_id = (int) tmp; + } + + return TRUE; +} + static void salut_muc_channel_received_stanza (GibberMucConnection *conn, const gchar *sender, -- cgit v1.2.1