[Telepathy-commits] [telepathy-gabble/master] Parse and store received capabilities of tube caps
Alban Crequy
alban.crequy at collabora.co.uk
Fri Dec 5 09:42:26 PST 2008
---
src/connection.c | 8 +++---
src/presence-cache.c | 65 +++++++++++++++++++++++++++++++++++++++++++------
src/presence.c | 2 +
src/presence.h | 3 +-
tests/test-presence.c | 4 +-
5 files changed, 67 insertions(+), 15 deletions(-)
diff --git a/src/connection.c b/src/connection.c
index 4e88a2e..6d1dbb4 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1927,7 +1927,7 @@ connection_auth_cb (LmConnection *lmconn,
/* set initial capabilities */
gabble_presence_set_capabilities (conn->self_presence, priv->resource,
- capabilities_get_initial_caps (), priv->caps_serial++);
+ capabilities_get_initial_caps (), NULL, NULL, priv->caps_serial++);
if (!gabble_disco_request_with_timeout (conn->disco, GABBLE_DISCO_TYPE_INFO,
priv->stream_server, NULL,
@@ -2213,8 +2213,8 @@ gabble_connection_advertise_capabilities (TpSvcConnectionInterfaceCapabilities *
if (caps ^ save_caps)
{
DEBUG ("before != after, changing");
- gabble_presence_set_capabilities (pres, priv->resource, caps,
- priv->caps_serial++);
+ gabble_presence_set_capabilities (pres, priv->resource, caps, NULL,
+ NULL, priv->caps_serial++);
DEBUG ("set caps: %x", pres->caps);
}
@@ -2988,7 +2988,7 @@ gabble_connection_ensure_capabilities (GabbleConnection *self,
GError *error = NULL;
gabble_presence_set_capabilities (self->self_presence, priv->resource,
- new_caps, priv->caps_serial++);
+ new_caps, NULL, NULL, priv->caps_serial++);
if (!_gabble_connection_signal_own_presence (self, &error))
DEBUG ("error sending presence: %s", error->message);
diff --git a/src/presence-cache.c b/src/presence-cache.c
index b21f94e..cfd25e3 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
+#include <glib.h>
/* When five DIFFERENT guys report the same caps for a given bundle, it'll
* be enough. But if only ONE guy use the verification string (XEP-0115 v1.5),
@@ -193,13 +194,16 @@ typedef struct _CapabilityInfo CapabilityInfo;
struct _CapabilityInfo
{
GabblePresenceCapabilities caps;
+ GHashTable *stream_tube_caps;
+ GHashTable *dbus_tube_caps;
TpIntSet *guys;
guint trust;
};
static CapabilityInfo *
capability_info_get (GabblePresenceCache *cache, const gchar *node,
- GabblePresenceCapabilities caps)
+ GabblePresenceCapabilities caps, GHashTable *stream_tube_caps,
+ GHashTable *dbus_tube_caps)
{
GabblePresenceCachePrivate *priv = GABBLE_PRESENCE_CACHE_PRIV (cache);
CapabilityInfo *info = g_hash_table_lookup (priv->capabilities, node);
@@ -209,6 +213,8 @@ capability_info_get (GabblePresenceCache *cache, const gchar *node,
info = g_slice_new0 (CapabilityInfo);
info->caps = caps;
info->guys = tp_intset_new ();
+ info->stream_tube_caps = stream_tube_caps;
+ info->dbus_tube_caps = dbus_tube_caps;
g_hash_table_insert (priv->capabilities, g_strdup (node), info);
}
@@ -225,9 +231,11 @@ capability_info_free (CapabilityInfo *info)
static guint
capability_info_recvd (GabblePresenceCache *cache, const gchar *node,
TpHandle handle, GabblePresenceCapabilities caps,
+ GHashTable *stream_tube_caps, GHashTable *dbus_tube_caps,
guint trust_inc)
{
- CapabilityInfo *info = capability_info_get (cache, node, caps);
+ CapabilityInfo *info = capability_info_get (cache, node, caps,
+ stream_tube_caps, dbus_tube_caps);
/* Detect inconsistency in reported caps */
if (info->caps != caps)
@@ -708,6 +716,8 @@ _caps_disco_cb (GabbleDisco *disco,
TpHandleRepoIface *contact_repo;
gchar *full_jid = NULL;
GabblePresenceCapabilities caps = 0;
+ GHashTable *stream_tube_caps;
+ GHashTable *dbus_tube_caps;
guint trust, trust_inc;
TpHandle handle = 0;
gboolean bad_hash = FALSE;
@@ -767,6 +777,11 @@ _caps_disco_cb (GabbleDisco *disco,
goto OUT;
}
+ stream_tube_caps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+ NULL);
+ dbus_tube_caps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+ NULL);
+
for (child = query_result->children; NULL != child; child = child->next)
{
const gchar *var;
@@ -805,12 +820,33 @@ _caps_disco_cb (GabbleDisco *disco,
!tp_strdiff (var, NS_OLPC_CURRENT_ACTIVITY "+notify") ||
!tp_strdiff (var, NS_OLPC_ACTIVITY_PROPS "+notify"))
caps |= PRESENCE_CAP_OLPC_1;
+ else if (g_str_has_prefix (var, NS_TUBES "/"))
+ {
+ /* http://telepathy.freedesktop.org/xmpp/tubes/$type/$service */
+ var += strlen (NS_TUBES "/");
+ if (g_str_has_prefix (var, "stream/"))
+ {
+ gchar *service;
+ var += strlen ("stream/");
+ service = g_strdup (var);
+ g_hash_table_insert (stream_tube_caps, service, service);
+ }
+ else if (g_str_has_prefix (var, "dbus/"))
+ {
+ gchar *service;
+ var += strlen ("dbus/");
+ service = g_strdup (var);
+ g_hash_table_insert (dbus_tube_caps, service, service);
+ }
+ }
}
handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
if (handle == 0)
{
DEBUG ("Ignoring presence from invalid JID %s", jid);
+ g_hash_table_destroy (stream_tube_caps);
+ g_hash_table_destroy (dbus_tube_caps);
goto OUT;
}
@@ -829,6 +865,8 @@ _caps_disco_cb (GabbleDisco *disco,
if (NULL == waiter_self)
{
DEBUG ("Ignoring non requested disco reply");
+ g_hash_table_destroy (stream_tube_caps);
+ g_hash_table_destroy (dbus_tube_caps);
goto OUT;
}
@@ -846,7 +884,8 @@ _caps_disco_cb (GabbleDisco *disco,
if (g_str_equal (waiter_self->ver, computed_hash))
{
- trust = capability_info_recvd (cache, node, handle, caps, trust_inc);
+ trust = capability_info_recvd (cache, node, handle, caps,
+ stream_tube_caps, dbus_tube_caps, trust_inc);
}
else
{
@@ -855,12 +894,21 @@ _caps_disco_cb (GabbleDisco *disco,
"our hash '%s'.", waiter_self->ver, computed_hash);
trust = 0;
bad_hash = TRUE;
+ g_hash_table_destroy (stream_tube_caps);
+ g_hash_table_destroy (dbus_tube_caps);
}
}
else
{
trust_inc = 1;
- trust = capability_info_recvd (cache, node, handle, caps, trust_inc);
+ trust = capability_info_recvd (cache, node, handle, caps, NULL, NULL,
+ trust_inc);
+
+ /* Do not allow tubes caps if the contact does not observe XEP-0115
+ * version 1.5: we don't need to bother being compatible with both version
+ * 1.3 and tubes caps */
+ g_hash_table_destroy (stream_tube_caps);
+ g_hash_table_destroy (dbus_tube_caps);
}
for (i = waiters; NULL != i;)
@@ -888,7 +936,8 @@ _caps_disco_cb (GabbleDisco *disco,
"%d (save_caps %d)",
waiter->handle, handle, jid, caps, save_caps);
gabble_presence_set_capabilities (presence,
- waiter->resource,caps, waiter->serial);
+ waiter->resource, caps, stream_tube_caps, dbus_tube_caps,
+ waiter->serial);
DEBUG ("caps for %d (thanks to %d %s) now %d", waiter->handle,
handle, jid, presence->caps);
g_signal_emit (cache, signals[CAPABILITIES_UPDATE], 0,
@@ -968,7 +1017,7 @@ _process_caps_uri (GabblePresenceCache *cache,
priv = GABBLE_PRESENCE_CACHE_PRIV (cache);
contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
- info = capability_info_get (cache, uri, 0);
+ info = capability_info_get (cache, uri, 0, NULL, NULL);
if (info->trust >= CAPABILITY_BUNDLE_ENOUGH_TRUST
|| tp_intset_is_member (info->guys, handle))
@@ -983,7 +1032,7 @@ _process_caps_uri (GabblePresenceCache *cache,
if (presence)
{
gabble_presence_set_capabilities (presence, resource, info->caps,
- serial);
+ info->stream_tube_caps, info->dbus_tube_caps, serial);
DEBUG ("caps for %d (%s) now %d", handle, from, presence->caps);
}
else
@@ -1454,7 +1503,7 @@ void gabble_presence_cache_add_bundle_caps (GabblePresenceCache *cache,
{
CapabilityInfo *info;
- info = capability_info_get (cache, node, 0);
+ info = capability_info_get (cache, node, 0, NULL, NULL);
info->trust = CAPABILITY_BUNDLE_ENOUGH_TRUST;
info->caps |= new_caps;
}
diff --git a/src/presence.c b/src/presence.c
index b5cac6d..8401b12 100644
--- a/src/presence.c
+++ b/src/presence.c
@@ -182,6 +182,8 @@ void
gabble_presence_set_capabilities (GabblePresence *presence,
const gchar *resource,
GabblePresenceCapabilities caps,
+ GHashTable *stream_tube_caps,
+ GHashTable *dbus_tube_caps,
guint serial)
{
GabblePresencePrivate *priv = GABBLE_PRESENCE_PRIV (presence);
diff --git a/src/presence.h b/src/presence.h
index 5663a19..142f3fc 100644
--- a/src/presence.h
+++ b/src/presence.h
@@ -79,7 +79,8 @@ gboolean gabble_presence_update (GabblePresence *presence,
const gchar *status_message, gint8 priority);
void gabble_presence_set_capabilities (GabblePresence *presence,
- const gchar *resource, GabblePresenceCapabilities caps, guint serial);
+ const gchar *resource, GabblePresenceCapabilities caps,
+ GHashTable *stream_tube_caps, GHashTable *dbus_tube_caps, guint serial);
const gchar *gabble_presence_pick_resource_by_caps (GabblePresence *presence,
GabblePresenceCapabilities caps);
diff --git a/tests/test-presence.c b/tests/test-presence.c
index f106af0..3e1d2f1 100644
--- a/tests/test-presence.c
+++ b/tests/test-presence.c
@@ -109,7 +109,7 @@ int main (int argc, char **argv)
g_assert (FALSE == gabble_presence_update (presence, "bar",
GABBLE_PRESENCE_AVAILABLE, "dingoes", -1));
gabble_presence_set_capabilities (presence, "bar",
- PRESENCE_CAP_GOOGLE_VOICE, 0);
+ PRESENCE_CAP_GOOGLE_VOICE, NULL, NULL, 0);
dump = gabble_presence_dump (presence);
g_assert (0 == strcmp (dump,
@@ -138,7 +138,7 @@ int main (int argc, char **argv)
/* give voice cap to first resource */
gabble_presence_set_capabilities (presence, "foo",
- PRESENCE_CAP_GOOGLE_VOICE, 0);
+ PRESENCE_CAP_GOOGLE_VOICE, NULL, NULL, 0);
/* resource has voice cap */
resource = gabble_presence_pick_resource_by_caps (presence,
--
1.5.6.5
More information about the Telepathy-commits
mailing list