[telepathy-gabble/telepathy-gabble-0.8] Cache our own caps before announcing them.
Will Thompson
will.thompson at collabora.co.uk
Fri Oct 2 18:03:38 PDT 2009
Previously, Gabble didn't put its own capabilities in the cache. So,
when it received its own presence echoed back by the server, it would...
disco itself.
---
src/connection.c | 4 ++++
src/presence-cache.c | 31 +++++++++++++++++++++++++++++++
src/presence-cache.h | 5 +++++
tests/twisted/Makefile.am | 1 +
tests/twisted/caps/trust-thyself.py | 33 +++++++++++++++++++++++++++++++++
5 files changed, 74 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/caps/trust-thyself.py
diff --git a/src/connection.c b/src/connection.c
index d421af6..a95618c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1542,6 +1542,10 @@ _gabble_connection_signal_own_presence (GabbleConnection *self, GError **error)
"ver", caps_hash,
NULL);
+ /* Ensure this set of capabilities is in the cache. */
+ gabble_presence_cache_add_own_caps (self->presence_cache, caps_hash,
+ presence->caps, presence->per_channel_manager_caps);
+
/* XEP-0115 deprecates 'ext' feature bundles. But we still need
* BUNDLE_VOICE_V1 it for backward-compatibility with Gabble 0.2 */
diff --git a/src/presence-cache.c b/src/presence-cache.c
index dbd07a9..2a92604 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -1785,6 +1785,37 @@ void gabble_presence_cache_add_bundle_caps (GabblePresenceCache *cache,
}
void
+gabble_presence_cache_add_own_caps (
+ GabblePresenceCache *cache,
+ const gchar *ver,
+ GabblePresenceCapabilities caps,
+ GHashTable *contact_caps)
+{
+ gchar *uri = g_strdup_printf ("%s#%s", NS_GABBLE_CAPS, ver);
+ CapabilityInfo *info = capability_info_get (cache, uri);
+ GHashTable *copy = NULL;
+
+ DEBUG ("caching our own caps (%s)", uri);
+
+ /* If this node was already in the cache, either the entry's correct, or
+ * someone's poisoning us with a SHA-1 collision. Let's update the entry just
+ * in case.
+ */
+ info->caps_set = TRUE;
+ info->trust = CAPABILITY_BUNDLE_ENOUGH_TRUST;
+ info->caps = caps;
+ tp_intset_add (info->guys, cache->priv->conn->parent.self_handle);
+
+ if (contact_caps != NULL)
+ gabble_presence_cache_copy_cache_entry (©, contact_caps);
+
+ gabble_presence_cache_free_cache_entry (info->per_channel_manager_caps);
+ info->per_channel_manager_caps = copy;
+
+ g_free (uri);
+}
+
+void
gabble_presence_cache_really_remove (
GabblePresenceCache *cache,
TpHandle handle)
diff --git a/src/presence-cache.h b/src/presence-cache.h
index 0c832d3..6cd57ad 100644
--- a/src/presence-cache.h
+++ b/src/presence-cache.h
@@ -82,6 +82,11 @@ void gabble_presence_cache_maybe_remove (GabblePresenceCache *cache,
TpHandle handle);
void gabble_presence_cache_add_bundle_caps (GabblePresenceCache *cache,
const gchar *node, GabblePresenceCapabilities caps);
+void gabble_presence_cache_add_own_caps (
+ GabblePresenceCache *cache,
+ const gchar *ver,
+ GabblePresenceCapabilities caps,
+ GHashTable *contact_caps);
void gabble_presence_cache_really_remove (GabblePresenceCache *cache,
TpHandle handle);
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index b041ee3..97001b2 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -11,6 +11,7 @@ TWISTED_TESTS = \
caps/initial-caps.py \
caps/jingle-caps.py \
caps/receive-jingle.py \
+ caps/trust-thyself.py \
caps/tube-caps.py \
muc/name-conflict.py \
muc/renamed.py \
diff --git a/tests/twisted/caps/trust-thyself.py b/tests/twisted/caps/trust-thyself.py
new file mode 100644
index 0000000..8732dc5
--- /dev/null
+++ b/tests/twisted/caps/trust-thyself.py
@@ -0,0 +1,33 @@
+"""
+Test that we cache our own capabilities, so that we don't disco other people
+with the same caps hash.
+"""
+from twisted.words.xish import xpath
+
+from gabbletest import exec_test, make_presence, sync_stream
+from servicetest import EventPattern
+import ns
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ self_presence = q.expect('stream-presence')
+
+ c = xpath.queryForNodes('/presence/c', self_presence.stanza)[0]
+
+ jid = 'lol at great.big/omg'
+ p = make_presence(jid,
+ caps={'node': c['node'],
+ 'hash': c['hash'],
+ 'ver': c['ver'],
+ })
+ stream.send(p)
+
+ uri = c['node'] + '#' + c['ver']
+ q.forbid_events([
+ EventPattern('stream-iq', to=jid, query_ns=ns.DISCO_INFO,
+ query_node=uri)
+ ])
+ sync_stream(q, stream)
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list