plugin XEP-0115: entity capabilities now use PersistentBinaryDict to store hash cache

This commit is contained in:
Goffi 2011-11-30 00:24:41 +01:00
commit 9102048217
3 changed files with 13 additions and 12 deletions

View file

@ -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)

View file

@ -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=''):

View file

@ -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: