# HG changeset patch # User Goffi # Date 1322609081 -3600 # Node ID 02c633a0ddcfe103c865cee7440466f39c3cbf0b # Parent 5e9d28ca5109c0f4899f8a654019649d824324ca plugin XEP-0115: entity capabilities now use PersistentBinaryDict to store hash cache diff -r 5e9d28ca5109 -r 02c633a0ddcf src/plugins/plugin_misc_cs.py --- a/src/plugins/plugin_misc_cs.py Wed Nov 30 00:23:50 2011 +0100 +++ b/src/plugins/plugin_misc_cs.py Wed Nov 30 00:24:41 2011 +0100 @@ -246,7 +246,6 @@ 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 -r 5e9d28ca5109 -r 02c633a0ddcf src/plugins/plugin_xep_0054.py --- a/src/plugins/plugin_xep_0054.py Wed Nov 30 00:23:50 2011 +0100 +++ b/src/plugins/plugin_xep_0054.py Wed Nov 30 00:24:41 2011 +0100 @@ -237,6 +237,7 @@ 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 -r 5e9d28ca5109 -r 02c633a0ddcf src/plugins/plugin_xep_0115.py --- a/src/plugins/plugin_xep_0115.py Wed Nov 30 00:23:50 2011 +0100 +++ b/src/plugins/plugin_xep_0115.py Wed Nov 30 00:24:41 2011 +0100 @@ -24,6 +24,7 @@ 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 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 @@ 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 @@ 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: