mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
Fix handing caps in Python3, allow update_caps() call before process()
This commit is contained in:
parent
35954cdc90
commit
27c658922e
1 changed files with 21 additions and 16 deletions
|
@ -12,7 +12,7 @@ import base64
|
||||||
|
|
||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
from sleekxmpp.stanza import StreamFeatures, Presence, Iq
|
from sleekxmpp.stanza import StreamFeatures, Presence, Iq
|
||||||
from sleekxmpp.xmlstream import register_stanza_plugin
|
from sleekxmpp.xmlstream import register_stanza_plugin, JID
|
||||||
from sleekxmpp.xmlstream.handler import Callback
|
from sleekxmpp.xmlstream.handler import Callback
|
||||||
from sleekxmpp.xmlstream.matcher import StanzaPath
|
from sleekxmpp.xmlstream.matcher import StanzaPath
|
||||||
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
|
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
|
||||||
|
@ -74,18 +74,18 @@ class xep_0115(base_plugin):
|
||||||
base_plugin.post_init(self)
|
base_plugin.post_init(self)
|
||||||
self.xmpp['xep_0030'].add_feature(stanza.Capabilities.namespace)
|
self.xmpp['xep_0030'].add_feature(stanza.Capabilities.namespace)
|
||||||
|
|
||||||
self.disco = self.xmpp['xep_0030']
|
disco = self.xmpp['xep_0030']
|
||||||
self.static = StaticCaps(self.xmpp, self.disco.static)
|
self.static = StaticCaps(self.xmpp, disco.static)
|
||||||
|
|
||||||
for op in self._disco_ops:
|
for op in self._disco_ops:
|
||||||
self.disco._add_disco_op(op, getattr(self.static, op))
|
disco._add_disco_op(op, getattr(self.static, op))
|
||||||
|
|
||||||
self._run_node_handler = self.disco._run_node_handler
|
self._run_node_handler = disco._run_node_handler
|
||||||
|
|
||||||
self.disco.cache_caps = self.cache_caps
|
disco.cache_caps = self.cache_caps
|
||||||
self.disco.update_caps = self.update_caps
|
disco.update_caps = self.update_caps
|
||||||
self.disco.assign_verstring = self.assign_verstring
|
disco.assign_verstring = self.assign_verstring
|
||||||
self.disco.get_verstring = self.get_verstring
|
disco.get_verstring = self.get_verstring
|
||||||
|
|
||||||
def _filter_add_caps(self, stanza):
|
def _filter_add_caps(self, stanza):
|
||||||
if isinstance(stanza, Presence) and self.broadcast:
|
if isinstance(stanza, Presence) and self.broadcast:
|
||||||
|
@ -125,15 +125,15 @@ class xep_0115(base_plugin):
|
||||||
if pres['caps']['hash'] not in self.hashes:
|
if pres['caps']['hash'] not in self.hashes:
|
||||||
try:
|
try:
|
||||||
log.debug("Unknown caps hash: %s", pres['caps']['hash'])
|
log.debug("Unknown caps hash: %s", pres['caps']['hash'])
|
||||||
self.disco.get_info(jid=pres['from'])
|
self.xmpp['xep_003'].get_info(jid=pres['from'].full)
|
||||||
return
|
return
|
||||||
except XMPPError:
|
except XMPPError:
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug("New caps verification string: %s", pres['caps']['ver'])
|
log.debug("New caps verification string: %s", pres['caps']['ver'])
|
||||||
try:
|
try:
|
||||||
caps = self.disco.get_info(
|
caps = self.xmpp['xep_0030'].get_info(
|
||||||
jid=pres['from'],
|
jid=pres['from'].full,
|
||||||
node='%s#%s' % (pres['caps']['node'],
|
node='%s#%s' % (pres['caps']['node'],
|
||||||
pres['caps']['ver']))
|
pres['caps']['ver']))
|
||||||
|
|
||||||
|
@ -242,15 +242,15 @@ class xep_0115(base_plugin):
|
||||||
S += '<'.join(sorted(vals)) + '<'
|
S += '<'.join(sorted(vals)) + '<'
|
||||||
|
|
||||||
binary = hash(S.encode('utf8')).digest()
|
binary = hash(S.encode('utf8')).digest()
|
||||||
return base64.b64encode(binary)
|
return base64.b64encode(binary).decode('utf-8')
|
||||||
|
|
||||||
def update_caps(self, jid=None, node=None):
|
def update_caps(self, jid=None, node=None):
|
||||||
try:
|
try:
|
||||||
info = self.disco.get_info(jid, node, local=True)
|
info = self.xmpp['xep_0030'].get_info(jid, node, local=True)
|
||||||
if isinstance(info, Iq):
|
if isinstance(info, Iq):
|
||||||
info = info['disco_info']
|
info = info['disco_info']
|
||||||
ver = self.generate_verstring(info, self.hash)
|
ver = self.generate_verstring(info, self.hash)
|
||||||
self.disco.set_info(
|
self.xmpp['xep_0030'].set_info(
|
||||||
jid=jid,
|
jid=jid,
|
||||||
node='%s#%s' % (self.caps_node, ver),
|
node='%s#%s' % (self.caps_node, ver),
|
||||||
info=info)
|
info=info)
|
||||||
|
@ -262,11 +262,15 @@ class xep_0115(base_plugin):
|
||||||
def get_verstring(self, jid=None):
|
def get_verstring(self, jid=None):
|
||||||
if jid in ('', None):
|
if jid in ('', None):
|
||||||
jid = self.xmpp.boundjid.full
|
jid = self.xmpp.boundjid.full
|
||||||
|
if isinstance(jid, JID):
|
||||||
|
jid = jid.full
|
||||||
return self._run_node_handler('get_verstring', jid)
|
return self._run_node_handler('get_verstring', jid)
|
||||||
|
|
||||||
def assign_verstring(self, jid=None, verstring=None):
|
def assign_verstring(self, jid=None, verstring=None):
|
||||||
if jid in (None, ''):
|
if jid in (None, ''):
|
||||||
jid = self.xmpp.boundjid.full
|
jid = self.xmpp.boundjid.full
|
||||||
|
if isinstance(jid, JID):
|
||||||
|
jid = jid.full
|
||||||
return self._run_node_handler('assign_verstring', jid,
|
return self._run_node_handler('assign_verstring', jid,
|
||||||
data={'verstring': verstring})
|
data={'verstring': verstring})
|
||||||
|
|
||||||
|
@ -280,6 +284,7 @@ class xep_0115(base_plugin):
|
||||||
verstring = self.get_verstring(jid)
|
verstring = self.get_verstring(jid)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
if isinstance(jid, JID):
|
||||||
|
jid = jid.full
|
||||||
data = {'verstring': verstring}
|
data = {'verstring': verstring}
|
||||||
return self._run_node_handler('get_caps', jid, None, None, data)
|
return self._run_node_handler('get_caps', jid, None, None, data)
|
||||||
|
|
Loading…
Reference in a new issue