Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/nbxmpp
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2020-03-24 00:55:29 +0300
committerlovetox <philipp@hoerist.com>2020-03-24 00:55:29 +0300
commit93e0a046cbc5e14e08b5ebe6a670fcbd5cddbbb3 (patch)
treea842c23582f9a017d2cf6e571008dea437e70870 /nbxmpp
parent7fca95381821c3f247c5e79da3865fb2df0a695b (diff)
Client: Add anonymous login test mode
Diffstat (limited to 'nbxmpp')
-rw-r--r--nbxmpp/client.py10
-rw-r--r--nbxmpp/const.py5
-rw-r--r--nbxmpp/protocol.py5
3 files changed, 20 insertions, 0 deletions
diff --git a/nbxmpp/client.py b/nbxmpp/client.py
index 6ca8244..58e33d9 100644
--- a/nbxmpp/client.py
+++ b/nbxmpp/client.py
@@ -62,6 +62,7 @@ class Client(Observable):
resume-failed
resume-successful
login-successful
+ anonymous-supported
disconnected
connected
connection-failed
@@ -685,6 +686,15 @@ class Client(Observable):
'register-not-supported')
return
+ if self._mode.is_anonymous_test:
+ if features.has_anonymous():
+ self.notify('anonymous-supported')
+ self.disconnect()
+ else:
+ self._disconnect_with_error(StreamError.SASL,
+ 'anonymous-not-supported')
+ return
+
self._start_auth(features)
else:
diff --git a/nbxmpp/const.py b/nbxmpp/const.py
index 4e64807..4904e66 100644
--- a/nbxmpp/const.py
+++ b/nbxmpp/const.py
@@ -391,6 +391,7 @@ class Mode(IntEnum):
CLIENT = 0
REGISTER = 1
LOGIN_TEST = 2
+ ANONYMOUS_TEST = 3
@property
def is_client(self):
@@ -404,6 +405,10 @@ class Mode(IntEnum):
def is_login_test(self):
return self == Mode.LOGIN_TEST
+ @property
+ def is_anonymous_test(self):
+ return self == Mode.ANONYMOUS_TEST
+
MOODS = [
'afraid',
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py
index 5fc0cd4..ca978d6 100644
--- a/nbxmpp/protocol.py
+++ b/nbxmpp/protocol.py
@@ -1833,6 +1833,8 @@ class Features(Node):
def get_mechs(self):
mechanisms = self.getTag('mechanisms', namespace=NS_SASL)
+ if mechanisms is None:
+ return set()
mechanisms = mechanisms.getTags('mechanism')
return set(mech.getData() for mech in mechanisms)
@@ -1862,6 +1864,9 @@ class Features(Node):
return self.getTag(
'register', namespace=NS_REGISTER_FEATURE) is not None
+ def has_anonymous(self):
+ return 'ANONYMOUS' in self.get_mechs()
+
class ErrorNode(Node):
"""