diff --git a/src/common/connection.py b/src/common/connection.py index e90c39e0a4ef97bddb3e00ac94849b7b60b7911e..04f3c625af1a91d627b7603c977667e2070c592f 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1134,6 +1134,10 @@ class Connection(CommonConnection, ConnectionHandlers): self._disconnectedReconnCB() def connect_to_next_type(self, retry=False): + if self.redirected: + self.disconnect(on_purpose=True) + self.connect() + return if len(self._connection_types): self._current_type = self._connection_types.pop(0) if self.last_connection: @@ -1194,6 +1198,7 @@ class Connection(CommonConnection, ConnectionHandlers): on_connect=self.on_connect_success, on_proxy_failure=self.on_proxy_failure, on_connect_failure=self.connect_to_next_type, + on_stream_error_cb=self._StreamCB, proxy=self._proxy, secure_tuple = secure_tuple) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index c34fa344f0f34c1b759ca96d83ae58a1f14ec3be..6393701992f3825510cdc9385fb5915e487ca1f4 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1257,6 +1257,7 @@ ConnectionJingle, ConnectionIBBytestream): PrivateStorageRosternotesReceivedEvent) gajim.nec.register_incoming_event(RosternotesReceivedEvent) gajim.nec.register_incoming_event(StreamConflictReceivedEvent) + gajim.nec.register_incoming_event(StreamOtherHostReceivedEvent) gajim.nec.register_incoming_event(MessageReceivedEvent) gajim.nec.register_incoming_event(ArchivingErrorReceivedEvent) gajim.nec.register_incoming_event( @@ -2018,8 +2019,6 @@ ConnectionJingle, ConnectionIBBytestream): if obj.conn.name != self.name: return self.redirected = obj.redirected - self.disconnect(on_purpose=True) - self.connect() def _StreamCB(self, con, obj): log.debug('StreamCB') diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 4706d473d56950c15faf2a7e5d9e475fbf671d11..8899d6d82f1b6789a56b7f1a54742c3a4628742a 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -680,8 +680,10 @@ class StreamOtherHostReceivedEvent(nec.NetworkIncomingEvent): base_network_events = ['stream-received'] def generate(self): - other_host = obj.getTag('see-other-host') - if other_host and self.conn.last_connection_type in ('ssl', 'tls'): + self.conn = self.base_event.conn + self.stanza = self.base_event.stanza + other_host = self.stanza.getTag('see-other-host') + if other_host and self.conn._current_type in ('ssl', 'tls'): host = other_host.getData() if ':' in host: host_l = host.split(':', 1) diff --git a/src/common/resolver.py b/src/common/resolver.py index 493d8d122d063741eda9b31e266d07fd53df8d55..898f146f4e595c8f7ecc8230150c38b15677b7ed 100644 --- a/src/common/resolver.py +++ b/src/common/resolver.py @@ -63,6 +63,7 @@ class CommonResolver(): self.handlers = {} def resolve(self, host, on_ready, type='srv'): + host = host.lower() log.debug('resolve %s type=%s' % (host, type)) assert(type in ['srv', 'txt']) if not host: @@ -88,6 +89,7 @@ class CommonResolver(): def _on_ready(self, host, type, result_list): # practically it is impossible to be the opposite, but who knows :) + host = host.lower() log.debug('Resolving result for %s: %s' % (host, result_list)) if not self.resolved_hosts.has_key(host+type): self.resolved_hosts[host+type] = result_list diff --git a/src/common/xmpp/client_nb.py b/src/common/xmpp/client_nb.py index 97d5ec567d8ff48c90bdc088be18b7b5b69aa1ff..33db829397482615e9032dae46d699bbfb5a79e2 100644 --- a/src/common/xmpp/client_nb.py +++ b/src/common/xmpp/client_nb.py @@ -67,6 +67,7 @@ class NonBlockingClient: self.on_connect_failure = None self.proxy = None self.got_features = False + self.got_see_other_host = None self.stream_started = False self.disconnecting = False self.protocol_type = 'XMPP' @@ -138,8 +139,8 @@ class NonBlockingClient: self.disconnecting = False def connect(self, on_connect, on_connect_failure, hostname=None, port=5222, - on_proxy_failure=None, proxy=None, secure_tuple=('plain', None, - None)): + on_proxy_failure=None, on_stream_error_cb=None, proxy=None, + secure_tuple=('plain', None, None)): """ Open XMPP connection (open XML streams in both directions) @@ -161,6 +162,7 @@ class NonBlockingClient: self.on_connect = on_connect self.on_connect_failure=on_connect_failure self.on_proxy_failure = on_proxy_failure + self.on_stream_error_cb = on_stream_error_cb self.desired_security, self.cacerts, self.mycerts = secure_tuple self.Connection = None self.Port = port @@ -350,7 +352,10 @@ class NonBlockingClient: # sometimes <features> are received together with document # attributes and sometimes on next receive... self.Dispatcher.ProcessNonBlocking(data) - if not self.got_features: + if self.got_see_other_host: + log.info('got see-other-host') + self.on_stream_error_cb(self, self.got_see_other_host) + elif not self.got_features: self._xmpp_connect_machine( mode='FAILURE', data='Missing <features> in 1.0 stream') diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py index 37020e5c644cfb9b41231e002977bb97761fd45d..5c4a7a1c94d0c3b0f5f48dee6ec8fc72f3342625 100644 --- a/src/common/xmpp/dispatcher_nb.py +++ b/src/common/xmpp/dispatcher_nb.py @@ -415,6 +415,9 @@ class XMPPDispatcher(PlugIn): if name == 'features': self._owner.got_features = True session.Stream.features = stanza + if name == 'error': + if stanza.getTag('see-other-host'): + self._owner.got_see_other_host = stanza xmlns = stanza.getNamespace()