diff options
author | Lance Stout <lancestout@gmail.com> | 2012-10-15 15:00:23 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-10-15 15:00:23 -0700 |
commit | cebc798e72fcc1a53b6962d26ec6bad121a953c1 (patch) | |
tree | dca8d4d541e68c7e5d963729d6e1c824cca08e6c | |
parent | e2e8c4b5dcca3dddfda6e60850a6754018e8f60d (diff) | |
parent | 9f6decdbc1dbb791006e590906bd94021b71495f (diff) | |
download | slixmpp-cebc798e72fcc1a53b6962d26ec6bad121a953c1.tar.gz slixmpp-cebc798e72fcc1a53b6962d26ec6bad121a953c1.tar.bz2 slixmpp-cebc798e72fcc1a53b6962d26ec6bad121a953c1.tar.xz slixmpp-cebc798e72fcc1a53b6962d26ec6bad121a953c1.zip |
Merge branch 'stream_features'
-rw-r--r-- | sleekxmpp/basexmpp.py | 4 | ||||
-rw-r--r-- | sleekxmpp/clientxmpp.py | 2 | ||||
-rw-r--r-- | sleekxmpp/features/feature_mechanisms/mechanisms.py | 2 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0078/legacyauth.py | 29 |
4 files changed, 27 insertions, 10 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 55250751..a1969e34 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -212,6 +212,10 @@ class BaseXMPP(XMLStream): self.stream_version = xml.get('version', '') self.peer_default_lang = xml.get('{%s}lang' % XML_NS, None) + if not self.is_component and not self.stream_version: + log.warning('Legacy XMPP 0.9 protocol detected.') + self.event('legacy_protocol') + def process(self, *args, **kwargs): """Initialize plugins and begin processing the XML stream. diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py index 7577b7da..ec64664c 100644 --- a/sleekxmpp/clientxmpp.py +++ b/sleekxmpp/clientxmpp.py @@ -273,6 +273,8 @@ class ClientXMPP(BaseXMPP): # Don't continue if the feature requires # restarting the XML stream. return True + log.debug('Finished processing stream features.') + self.event('stream_negotiated') def _handle_roster(self, iq): """Update the roster after receiving a roster stanza. diff --git a/sleekxmpp/features/feature_mechanisms/mechanisms.py b/sleekxmpp/features/feature_mechanisms/mechanisms.py index 672f4fa6..b480d5be 100644 --- a/sleekxmpp/features/feature_mechanisms/mechanisms.py +++ b/sleekxmpp/features/feature_mechanisms/mechanisms.py @@ -44,7 +44,7 @@ class FeatureMechanisms(BasePlugin): } def plugin_init(self): - if not self.use_mech and not self.xmpp.boundjid.user: + if not self.use_mech and not self.xmpp.requested_jid.user: self.use_mech = 'ANONYMOUS' if self.sasl_callback is None: diff --git a/sleekxmpp/plugins/xep_0078/legacyauth.py b/sleekxmpp/plugins/xep_0078/legacyauth.py index 5c4045d8..be9fe3c5 100644 --- a/sleekxmpp/plugins/xep_0078/legacyauth.py +++ b/sleekxmpp/plugins/xep_0078/legacyauth.py @@ -44,16 +44,27 @@ class XEP_0078(BasePlugin): restart=False, order=self.order) + self.xmpp.add_event_handler('legacy_protocol', + self._handle_legacy_protocol) + register_stanza_plugin(Iq, stanza.IqAuth) register_stanza_plugin(StreamFeatures, stanza.AuthFeature) def plugin_end(self): + self.xmpp.del_event_handler('legacy_protocol', + self._handle_legacy_protocol) self.xmpp.unregister_feature('auth', self.order) def _handle_auth(self, features): # If we can or have already authenticated with SASL, do nothing. if 'mechanisms' in features['features']: return False + return self.authenticate() + + def _handle_legacy_protocol(self, event): + self.authenticate() + + def authenticate(self): if self.xmpp.authenticated: return False @@ -62,13 +73,13 @@ class XEP_0078(BasePlugin): # Step 1: Request the auth form iq = self.xmpp.Iq() iq['type'] = 'get' - iq['to'] = self.xmpp.boundjid.host - iq['auth']['username'] = self.xmpp.boundjid.user + iq['to'] = self.xmpp.requested_jid.host + iq['auth']['username'] = self.xmpp.requested_jid.user try: resp = iq.send(now=True) - except IqError: - log.info("Authentication failed: %s", resp['error']['condition']) + except IqError as err: + log.info("Authentication failed: %s", err.iq['error']['condition']) self.xmpp.event('failed_auth', direct=True) self.xmpp.disconnect() return True @@ -81,11 +92,11 @@ class XEP_0078(BasePlugin): # Step 2: Fill out auth form for either password or digest auth iq = self.xmpp.Iq() iq['type'] = 'set' - iq['auth']['username'] = self.xmpp.boundjid.user + iq['auth']['username'] = self.xmpp.requested_jid.user # A resource is required, so create a random one if necessary - if self.xmpp.boundjid.resource: - iq['auth']['resource'] = self.xmpp.boundjid.resource + if self.xmpp.requested_jid.resource: + iq['auth']['resource'] = self.xmpp.requested_jid.resource else: iq['auth']['resource'] = '%s' % random.random() @@ -109,12 +120,12 @@ class XEP_0078(BasePlugin): result = iq.send(now=True) except IqError as err: log.info("Authentication failed") - self.xmpp.disconnect() self.xmpp.event("failed_auth", direct=True) + self.xmpp.disconnect() except IqTimeout: log.info("Authentication failed") - self.xmpp.disconnect() self.xmpp.event("failed_auth", direct=True) + self.xmpp.disconnect() self.xmpp.features.add('auth') |