From 54ad65c744cfd7de296cfb5b0f3e6a84acf38038 Mon Sep 17 00:00:00 2001
From: Stephan Erb <steve-e@h3c.de>
Date: Sun, 27 Dec 2009 16:23:31 +0100
Subject: [PATCH] Show warning if calculated and received caps hash are
 different.

---
 src/common/caps_cache.py    | 5 +++--
 src/common/protocol/caps.py | 5 ++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/common/caps_cache.py b/src/common/caps_cache.py
index 37ff65bab8..6a3b3591a0 100644
--- a/src/common/caps_cache.py
+++ b/src/common/caps_cache.py
@@ -251,7 +251,8 @@ class NullClientCaps(AbstractClientCaps):
 	def _lookup_in_cache(self, caps_cache):
 		# lookup something which does not exist to get a new CacheItem created
 		cache_item = caps_cache[('dummy', '')]
-		assert cache_item.status != CACHED
+		# Mark the item as cached so that protocol/caps.py does not update it
+		cache_item.status = CACHED
 		return cache_item
 
 	def _discover(self, connection, jid):
@@ -390,4 +391,4 @@ class CapsCache(object):
 		else:
 			q.update_last_seen()
 
-# vim: se ts=3:
\ No newline at end of file
+# vim: se ts=3:
diff --git a/src/common/protocol/caps.py b/src/common/protocol/caps.py
index 268f1ffe23..3fd6c13868 100644
--- a/src/common/protocol/caps.py
+++ b/src/common/protocol/caps.py
@@ -90,6 +90,8 @@ class ConnectionCaps(object):
 		cache_item = lookup(self._capscache)
 
 		if cache_item.is_valid():
+			# we already know that the hash is fine and have already cached
+			# the identities and features
 			return
 		else:
 			validate = contact.client_caps.get_hash_validation_strategy()
@@ -101,8 +103,9 @@ class ConnectionCaps(object):
 				node = caps_hash = hash_method = None
 				contact.client_caps = self._create_suitable_client_caps(node,
 					caps_hash, hash_method)
+				log.warn("Computed and retrieved caps hash differ." +
+					"Ignoring caps of contact %s" % contact.get_full_jid())
 
 			self._dispatch_event('CAPS_RECEIVED', (jid,))
-
 		
 # vim: se ts=3:
-- 
GitLab