session: Don’t bind if it is optional.
See https://tools.ietf.org/html/draft-cridland-xmpp-session-01
This commit is contained in:
parent
5184713356
commit
084d6cb5d9
@ -43,10 +43,11 @@ class FeatureSession(BasePlugin):
|
|||||||
Arguments:
|
Arguments:
|
||||||
feature -- The stream features element.
|
feature -- The stream features element.
|
||||||
"""
|
"""
|
||||||
iq = self.xmpp.Iq()
|
if not features['session']['optional']:
|
||||||
iq['type'] = 'set'
|
iq = self.xmpp.Iq()
|
||||||
iq.enable('session')
|
iq['type'] = 'set'
|
||||||
yield from iq.send(callback=self._on_start_session_response)
|
iq.enable('session')
|
||||||
|
yield from iq.send(callback=self._on_start_session_response)
|
||||||
|
|
||||||
def _on_start_session_response(self, response):
|
def _on_start_session_response(self, response):
|
||||||
self.xmpp.features.add('session')
|
self.xmpp.features.add('session')
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
See the file LICENSE for copying permission.
|
See the file LICENSE for copying permission.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from slixmpp.xmlstream import ElementBase
|
from slixmpp.xmlstream import ElementBase, ET
|
||||||
|
|
||||||
|
|
||||||
class Session(ElementBase):
|
class Session(ElementBase):
|
||||||
@ -16,5 +16,19 @@ class Session(ElementBase):
|
|||||||
|
|
||||||
name = 'session'
|
name = 'session'
|
||||||
namespace = 'urn:ietf:params:xml:ns:xmpp-session'
|
namespace = 'urn:ietf:params:xml:ns:xmpp-session'
|
||||||
interfaces = set()
|
interfaces = {'optional'}
|
||||||
plugin_attrib = 'session'
|
plugin_attrib = 'session'
|
||||||
|
|
||||||
|
def get_optional(self):
|
||||||
|
return self.xml.find('{%s}optional' % self.namespace) is not None
|
||||||
|
|
||||||
|
def set_optional(self, value):
|
||||||
|
if value:
|
||||||
|
optional = ET.Element('{%s}optional' % self.namespace)
|
||||||
|
self.xml.append(optional)
|
||||||
|
else:
|
||||||
|
self.del_optional()
|
||||||
|
|
||||||
|
def del_optional(self):
|
||||||
|
optional = self.xml.find('{%s}optional' % self.namespace)
|
||||||
|
self.xml.remove(optional)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user