From fa7f72d0af3f404abb7426a29ed0aad1d792b90c Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Wed, 30 Jun 2010 14:30:18 -0400 Subject: 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. --- sleekxmpp/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sleekxmpp') 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, "", self.handler_sasl_digest_md5_auth, instream=True) + basexmpp.add_handler(self, "", self.handler_sasl_digest_md5_auth_fail, instream=True) + basexmpp.add_handler(self, "", self.handler_auth_success, instream=True) + basexmpp.add_handler(self, "", self.handler_auth_fail, instream=True) #self.registerHandler(Callback('Roster Update', MatchXMLMask("" % self.default_ns), self._handlePresenceSubscribe, thread=True)) self.registerFeature("", self.handler_starttls, True) self.registerFeature("", 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("", self.handler_auth_success, instream=True) - self.add_handler("", 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("", self.handler_sasl_digest_md5_auth, instream=True) - self.add_handler("", self.handler_sasl_digest_md5_auth_fail, instream=True) self.sendPriorityRaw("""""") elif 'sasl:PLAIN' in self.features: if sys.version_info < (3,0): -- cgit v1.2.3