From 9102048217c2b2c763f4ae289465dbc46e9b901b Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 30 Nov 2011 00:24:41 +0100 Subject: [PATCH] plugin XEP-0115: entity capabilities now use PersistentBinaryDict to store hash cache --- src/plugins/plugin_misc_cs.py | 1 - src/plugins/plugin_xep_0054.py | 1 + src/plugins/plugin_xep_0115.py | 23 ++++++++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/plugins/plugin_misc_cs.py b/src/plugins/plugin_misc_cs.py index 4d06d74d..7b5f5f93 100755 --- a/src/plugins/plugin_misc_cs.py +++ b/src/plugins/plugin_misc_cs.py @@ -246,7 +246,6 @@ class CS_Plugin(): friends = data['friends'].split('\t') subject = data['subject'] message = data['message'] - print "send message \o/ :) :) :)" info(_("sending message to %(friends)s with subject [%(subject)s]" % {'friends':friends, 'subject':subject})) self.__sendMessage(None, subject, message, self.data[profile], friends, id, profile) diff --git a/src/plugins/plugin_xep_0054.py b/src/plugins/plugin_xep_0054.py index 60cd7113..3d8e0fce 100755 --- a/src/plugins/plugin_xep_0054.py +++ b/src/plugins/plugin_xep_0054.py @@ -237,6 +237,7 @@ class XEP_0054_handler(XMPPHandler): def connectionInitialized(self): self.parent._vcard_cache = PersistentBinaryDict(NS_VCARD, self.parent.profile) + self.parent._vcard_cache.load() self.xmlstream.addObserver(VCARD_UPDATE, self.update) def getDiscoInfo(self, requestor, target, nodeIdentifier=''): diff --git a/src/plugins/plugin_xep_0115.py b/src/plugins/plugin_xep_0115.py index f3b147ea..4dc69a5c 100755 --- a/src/plugins/plugin_xep_0115.py +++ b/src/plugins/plugin_xep_0115.py @@ -24,6 +24,7 @@ from twisted.words.xish import domish from twisted.words.protocols.jabber import client, jid, xmlstream from twisted.words.protocols.jabber import error as jab_error from twisted.words.protocols.jabber.xmlstream import IQ +from sat.memory.persistent import PersistentBinaryDict import os.path import types @@ -73,14 +74,16 @@ class ByteIdentity(object): class XEP_0115(): - cap_hash = None + cap_hash = None #capabilities hash is class variable as it is common to all profiles + #TODO: this code is really dirty, need to clean it and try to move it to Wokkel def __init__(self, host): info(_("Plugin XEP_0115 initialization")) self.host = host host.trigger.add("Disco Handled", self.checkHash) - self.hash_cache = host.memory.getPrivate("entity_capabilities_cache") or {} #key = hash or jid - self.jid_hash = {} #jid to hash mapping, map to a discoInfo if the hash method is unknown + self.hash_cache = PersistentBinaryDict(NS_ENTITY_CAPABILITY) #key = hash or jid, value = features + self.hash_cache.load() + self.jid_hash = {} #jid to hash mapping, map to a discoInfo features if the hash method is unknown def checkHash(self, profile): if not XEP_0115.cap_hash: @@ -165,15 +168,13 @@ class XEP_0115_handler(XMPPHandler): def _updateCache(self, discoResult, from_jid, key): """Actually update the cache - @param discoResult: result of the requestInfo - @param known_hash: True if it's a hash method we know, we don't save the cache else""" + @param discoResult: result of the requestInfo""" if key: self.plugin_parent.jid_hash[from_jid] = key - self.plugin_parent.hash_cache[key] = discoResult + self.plugin_parent.hash_cache[key] = discoResult.features else: - #No key, that mean unknown hash method - self.plugin_parent.jid_hash[from_jid] = discoResult - self.host.memory.setPrivate("entity_capabilities_cache", self.plugin_parent.hash_cache) + #No key, that means unknown hash method + self.plugin_parent.jid_hash[from_jid] = discoResult.features def update(self, presence): @@ -191,8 +192,8 @@ class XEP_0115_handler(XMPPHandler): except KeyError: warning('Received invalid capabilities tag') return - if not self.plugin_parent.jid_hash.has_key(from_jid): - if self.plugin_parent.hash_cache.has_key(ver): + if not from_jid in self.plugin_parent.jid_hash: + if ver in self.plugin_parent.hash_cache: #we know that hash, we just link it with the jid self.plugin_parent.jid_hash[from_jid] = ver else: