diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-03-14 18:54:17 +0100 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-03-14 18:54:17 +0100 |
commit | 084d6cb5d9cd017a084c4a2b30741ccf5180de98 (patch) | |
tree | 37d6fa97865a2e3b814ab8837f2efba1e082cf0a | |
parent | 51847133560e9ef6aaa3d13578fcdf87cb049b32 (diff) | |
download | slixmpp-084d6cb5d9cd017a084c4a2b30741ccf5180de98.tar.gz slixmpp-084d6cb5d9cd017a084c4a2b30741ccf5180de98.tar.bz2 slixmpp-084d6cb5d9cd017a084c4a2b30741ccf5180de98.tar.xz slixmpp-084d6cb5d9cd017a084c4a2b30741ccf5180de98.zip |
session: Don’t bind if it is optional.
See https://tools.ietf.org/html/draft-cridland-xmpp-session-01
-rw-r--r-- | slixmpp/features/feature_session/session.py | 9 | ||||
-rw-r--r-- | slixmpp/features/feature_session/stanza.py | 18 |
2 files changed, 21 insertions, 6 deletions
diff --git a/slixmpp/features/feature_session/session.py b/slixmpp/features/feature_session/session.py index 2f9548eb..b525d50c 100644 --- a/slixmpp/features/feature_session/session.py +++ b/slixmpp/features/feature_session/session.py @@ -43,10 +43,11 @@ class FeatureSession(BasePlugin): Arguments: feature -- The stream features element. """ - iq = self.xmpp.Iq() - iq['type'] = 'set' - iq.enable('session') - yield from iq.send(callback=self._on_start_session_response) + if not features['session']['optional']: + iq = self.xmpp.Iq() + iq['type'] = 'set' + iq.enable('session') + yield from iq.send(callback=self._on_start_session_response) def _on_start_session_response(self, response): self.xmpp.features.add('session') diff --git a/slixmpp/features/feature_session/stanza.py b/slixmpp/features/feature_session/stanza.py index f68483d6..4ed8c4db 100644 --- a/slixmpp/features/feature_session/stanza.py +++ b/slixmpp/features/feature_session/stanza.py @@ -6,7 +6,7 @@ See the file LICENSE for copying permission. """ -from slixmpp.xmlstream import ElementBase +from slixmpp.xmlstream import ElementBase, ET class Session(ElementBase): @@ -16,5 +16,19 @@ class Session(ElementBase): name = 'session' namespace = 'urn:ietf:params:xml:ns:xmpp-session' - interfaces = set() + interfaces = {'optional'} 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) |