diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-31 13:23:44 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-31 13:54:14 +0100 |
commit | a17634a620622b765118e8eae39df6a5754d8f4d (patch) | |
tree | 95e3a7e5f0eac5ba237d59fb9c0ec9fe75d77912 /src | |
parent | c23651bfdd6f3bca5891a272bb80e0b36e3d5057 (diff) | |
download | telepathy-salut-a17634a620622b765118e8eae39df6a5754d8f4d.tar.gz |
muc-channel: add extract_tube_information
This is copied from tubes-channel.c (soon to be removed).
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r-- | src/muc-channel.c | 99 |
1 files changed, 99 insertions, 0 deletions
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 <message> */ +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, |