comparison src/plugins/plugin_xep_0049.py @ 989:93359853e4bc

plugins XEP-0048, XEP-0049: feature is not checked anymore before using private XML storage, as feature announcement is not mandatory in XEP-0049
author Goffi <goffi@goffi.org>
date Thu, 10 Apr 2014 16:12:50 +0200
parents f0bba18835ef
children 301b342c697a
comparison
equal deleted inserted replaced
988:b3076b5797f6 989:93359853e4bc
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from logging import debug, info, error, warning 21 from logging import debug, info, error, warning
22 from twisted.internet import defer
23 from wokkel import compat 22 from wokkel import compat
24 from twisted.words.xish import domish 23 from twisted.words.xish import domish
25 24
26 25
27 26
42 41
43 def __init__(self, host): 42 def __init__(self, host):
44 info(_("Plugin XEP-0049 initialization")) 43 info(_("Plugin XEP-0049 initialization"))
45 self.host = host 44 self.host = host
46 45
47 @defer.inlineCallbacks
48 def privateXMLStore(self, element, profile_key): 46 def privateXMLStore(self, element, profile_key):
49 """Store private data 47 """Store private data
50 @param element: domish.Element to store (must have a namespace) 48 @param element: domish.Element to store (must have a namespace)
51 @param profile_key: %(doc_profile_key)s 49 @param profile_key: %(doc_profile_key)s
52 50
53 """ 51 """
54 assert isinstance(element, domish.Element) 52 assert isinstance(element, domish.Element)
55 client = self.host.getClient(profile_key) 53 client = self.host.getClient(profile_key)
56 yield self.host.checkFeature(XEP_0049.NS_PRIVATE, profile_key=client.profile) 54 # 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
57 iq_elt = compat.IQ(client.xmlstream) 55 iq_elt = compat.IQ(client.xmlstream)
58 query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE) 56 query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE)
59 query_elt.addChild(element) 57 query_elt.addChild(element)
60 yield iq_elt.send() 58 return iq_elt.send()
61 59
62 @defer.inlineCallbacks
63 def privateXMLGet(self, node_name, namespace, profile_key): 60 def privateXMLGet(self, node_name, namespace, profile_key):
64 """Store private data 61 """Store private data
65 @param node_name: name of the node to get 62 @param node_name: name of the node to get
66 @param namespace: namespace of the node to get 63 @param namespace: namespace of the node to get
67 @param profile_key: %(doc_profile_key)s 64 @param profile_key: %(doc_profile_key)s
68 @return (domish.Element): a deferred which fire the stored data 65 @return (domish.Element): a deferred which fire the stored data
69 66
70 """ 67 """
71 client = self.host.getClient(profile_key) 68 client = self.host.getClient(profile_key)
72 yield self.host.checkFeature(XEP_0049.NS_PRIVATE, profile_key=client.profile) 69 # XXX: see privateXMLStore note about feature checking
73 iq_elt = compat.IQ(client.xmlstream, 'get') 70 iq_elt = compat.IQ(client.xmlstream, 'get')
74 query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE) 71 query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE)
75 query_elt.addElement(node_name, namespace) 72 query_elt.addElement(node_name, namespace)
76 answer_iq_elt = yield iq_elt.send() 73 def getCb(answer_iq_elt):
77 answer_query_elt = answer_iq_elt.elements(XEP_0049.NS_PRIVATE, 'query').next() 74 answer_query_elt = answer_iq_elt.elements(XEP_0049.NS_PRIVATE, 'query').next()
78 defer.returnValue(answer_query_elt.firstChildElement()) 75 return answer_query_elt.firstChildElement()
76 d = iq_elt.send()
77 d.addCallback(getCb)
78 return d
79 79