From 2ac8607ed63d37e11c2e3d07c42bb7bdd29c0bae Mon Sep 17 00:00:00 2001 From: Yann Leboulanger <asterix@lagaule.org> Date: Sun, 15 Apr 2012 23:42:53 +0200 Subject: [PATCH] handle see-other-host stream error. Fixes #7134 --- src/common/connection.py | 18 ++++++++++++++---- src/common/connection_handlers.py | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 4359fffff5..e90c39e0a4 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -689,6 +689,7 @@ class Connection(CommonConnection, ConnectionHandlers): self.try_connecting_for_foo_secs = 45 # holds the actual hostname to which we are connected self.connected_hostname = None + self.redirected = None self.last_time_to_reconnect = None self.new_account_info = None self.new_account_form = None @@ -1039,10 +1040,17 @@ class Connection(CommonConnection, ConnectionHandlers): self.name, 'try_connecting_for_foo_secs') proxy = helpers.get_proxy_info(self.name) use_srv = gajim.config.get_per('accounts', self.name, 'use_srv') - use_custom = gajim.config.get_per('accounts', self.name, + if self.redirected: + use_custom = True + custom_h = self.redirected['host'] + custom_p = self.redirected['port'] + else: + use_custom = gajim.config.get_per('accounts', self.name, 'use_custom_host') - custom_h = gajim.config.get_per('accounts', self.name, 'custom_host') - custom_p = gajim.config.get_per('accounts', self.name, 'custom_port') + custom_h = gajim.config.get_per('accounts', self.name, + 'custom_host') + custom_p = gajim.config.get_per('accounts', self.name, + 'custom_port') # create connection if it doesn't already exist self.connected = 1 @@ -1054,8 +1062,10 @@ class Connection(CommonConnection, ConnectionHandlers): h = custom_h p = custom_p ssl_p = custom_p - use_srv = False + if not self.redirected: + use_srv = False + self.redirected = None # SRV resolver self._proxy = proxy self._hosts = [ {'host': h, 'port': p, 'ssl_port': ssl_p, 'prio': 10, diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 8a537e15e2..3228214aec 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -190,7 +190,7 @@ class ConnectionDisco: query.setAttr('node', 'http://gajim.org#' + gajim.version.split('-', 1)[ 0]) for f in (common.xmpp.NS_BYTESTREAM, common.xmpp.NS_SI, - common.xmpp.NS_FILE, common.xmpp.NS_COMMANDS, + common.xmpp.NS_FILE, common.xmpp.NS_COMMANDS, common.xmpp.NS_JINGLE_FILE_TRANSFER, common.xmpp.NS_JINGLE_XTLS, common.xmpp.NS_PUBKEY_PUBKEY, common.xmpp.NS_PUBKEY_REVOKE, common.xmpp.NS_PUBKEY_ATTEST): @@ -2014,6 +2014,21 @@ ConnectionJingle, ConnectionIBBytestream): if obj.getTag('conflict'): # disconnected because of a resource conflict self.dispatch('RESOURCE_CONFLICT', ()) + other_host = obj.getTag('see-other-host') + if other_host and self.last_connection_type in ('ssl', 'tls'): + host = other_host.getData() + if ':' in host: + host_l = host.split(':', 1) + h = host_l[0] + p = host_l[1] + else: + h = host + p = 5222 + if h.startswith('[') and h.endswith(']'): + h = h[1:-1] + self.redirected = {'host': h, 'port': p} + self.disconnect(on_purpose=True) + self.connect() def _register_handlers(self, con, con_type): # try to find another way to register handlers in each class -- GitLab