plugins XEP-0048, XEP-0049: feature is not checked anymore before using private XML storage, as feature announcement is not mandatory in XEP-0049
This commit is contained in:
parent
acce568f57
commit
3fcd7e22d9
2 changed files with 11 additions and 12 deletions
|
|
@ -25,6 +25,7 @@ from sat.tools import xml_tools
|
|||
from logging import debug, info, warning, error
|
||||
from twisted.words.xish import domish
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.protocols.jabber.error import StanzaError
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
|
|
@ -98,15 +99,13 @@ class XEP_0048(object):
|
|||
- 'pubsub': XEP-0223 storage
|
||||
@param profile: %(doc_profile)s
|
||||
@return: data dictionary, or None if feature is not available
|
||||
|
||||
@raise: exception.FeatureNotFound
|
||||
"""
|
||||
client = self.host.getClient(profile)
|
||||
if storage_type == 'private':
|
||||
try:
|
||||
bookmarks_private_xml = yield self.private_plg.privateXMLGet('storage', NS_BOOKMARKS, profile)
|
||||
data = client.bookmarks_private = self._bookmarkElt2Dict(bookmarks_private_xml)
|
||||
except (exceptions.FeatureNotFound, AttributeError):
|
||||
except (StanzaError, AttributeError):
|
||||
info(_("Private XML storage not available"))
|
||||
data = client.bookmarks_private = None
|
||||
elif storage_type == 'pubsub':
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
from logging import debug, info, error, warning
|
||||
from twisted.internet import defer
|
||||
from wokkel import compat
|
||||
from twisted.words.xish import domish
|
||||
|
||||
|
|
@ -44,7 +43,6 @@ class XEP_0049(object):
|
|||
info(_("Plugin XEP-0049 initialization"))
|
||||
self.host = host
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def privateXMLStore(self, element, profile_key):
|
||||
"""Store private data
|
||||
@param element: domish.Element to store (must have a namespace)
|
||||
|
|
@ -53,13 +51,12 @@ class XEP_0049(object):
|
|||
"""
|
||||
assert isinstance(element, domish.Element)
|
||||
client = self.host.getClient(profile_key)
|
||||
yield self.host.checkFeature(XEP_0049.NS_PRIVATE, profile_key=client.profile)
|
||||
# XXX: feature announcement in disco#info is not mandatory in XEP-0049, so we have to try to use private XML, and react according to the answer
|
||||
iq_elt = compat.IQ(client.xmlstream)
|
||||
query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE)
|
||||
query_elt.addChild(element)
|
||||
yield iq_elt.send()
|
||||
return iq_elt.send()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def privateXMLGet(self, node_name, namespace, profile_key):
|
||||
"""Store private data
|
||||
@param node_name: name of the node to get
|
||||
|
|
@ -69,11 +66,14 @@ class XEP_0049(object):
|
|||
|
||||
"""
|
||||
client = self.host.getClient(profile_key)
|
||||
yield self.host.checkFeature(XEP_0049.NS_PRIVATE, profile_key=client.profile)
|
||||
# XXX: see privateXMLStore note about feature checking
|
||||
iq_elt = compat.IQ(client.xmlstream, 'get')
|
||||
query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE)
|
||||
query_elt.addElement(node_name, namespace)
|
||||
answer_iq_elt = yield iq_elt.send()
|
||||
answer_query_elt = answer_iq_elt.elements(XEP_0049.NS_PRIVATE, 'query').next()
|
||||
defer.returnValue(answer_query_elt.firstChildElement())
|
||||
def getCb(answer_iq_elt):
|
||||
answer_query_elt = answer_iq_elt.elements(XEP_0049.NS_PRIVATE, 'query').next()
|
||||
return answer_query_elt.firstChildElement()
|
||||
d = iq_elt.send()
|
||||
d.addCallback(getCb)
|
||||
return d
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue