diff options
author | Brian Beggs <macdiesel@gmail.com> | 2010-06-30 14:30:18 -0400 |
---|---|---|
committer | Brian Beggs <macdiesel@gmail.com> | 2010-06-30 14:30:18 -0400 |
commit | fa7f72d0af3f404abb7426a29ed0aad1d792b90c (patch) | |
tree | 98e64da6efe856cac8a0bdedaa8e6c0f4a662a56 /sleekxmpp | |
parent | c538ffae79728f7cb2675e14af64915682c19fe1 (diff) | |
download | slixmpp-fa7f72d0af3f404abb7426a29ed0aad1d792b90c.tar.gz slixmpp-fa7f72d0af3f404abb7426a29ed0aad1d792b90c.tar.bz2 slixmpp-fa7f72d0af3f404abb7426a29ed0aad1d792b90c.tar.xz slixmpp-fa7f72d0af3f404abb7426a29ed0aad1d792b90c.zip |
Fixed a defect where handlers for SASL authentication were being added multiple times. This caused issues when trying to reconnect. A handler for the auth mech would get added each reconnection attempt, causing digest-md5, success and failure to be called x times for each x number of retries.
Handlers for sasl authentication as well as success and failure are now added during the __init__ method.
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/__init__.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py index 894fdc74..f05e8a5f 100644 --- a/sleekxmpp/__init__.py +++ b/sleekxmpp/__init__.py @@ -7,6 +7,7 @@ See the file license.txt for copying permission. """ +from __future__ import absolute_import from . basexmpp import basexmpp from xml.etree import cElementTree as ET from . xmlstream.xmlstream import XMLStream @@ -77,6 +78,11 @@ class ClientXMPP(basexmpp, XMLStream): self.digest_auth_started = False XMLStream.registerHandler(self, Callback('Stream Features', MatchXPath('{http://etherx.jabber.org/streams}features'), self._handleStreamFeatures, thread=True)) XMLStream.registerHandler(self, Callback('Roster Update', MatchXPath('{%s}iq/{jabber:iq:roster}query' % self.default_ns), self._handleRoster, thread=True)) + #SASL Auth handlers + basexmpp.add_handler(self, "<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_digest_md5_auth, instream=True) + basexmpp.add_handler(self, "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>", self.handler_sasl_digest_md5_auth_fail, instream=True) + basexmpp.add_handler(self, "<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True) + basexmpp.add_handler(self, "<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True) #self.registerHandler(Callback('Roster Update', MatchXMLMask("<presence xmlns='%s' type='subscribe' />" % self.default_ns), self._handlePresenceSubscribe, thread=True)) self.registerFeature("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_starttls, True) self.registerFeature("<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_auth, True) @@ -211,15 +217,11 @@ class ClientXMPP(basexmpp, XMLStream): if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features: return False logging.debug("Starting SASL Auth") - self.add_handler("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True) - self.add_handler("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True) sasl_mechs = xml.findall('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism') if len(sasl_mechs): for sasl_mech in sasl_mechs: self.features.append("sasl:%s" % sasl_mech.text) if 'sasl:DIGEST-MD5' in self.features: - self.add_handler("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_digest_md5_auth, instream=True) - self.add_handler("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>", self.handler_sasl_digest_md5_auth_fail, instream=True) self.sendPriorityRaw("""<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>""") elif 'sasl:PLAIN' in self.features: if sys.version_info < (3,0): |