From ffdc55ce2ebd94e5caa0ff0ae40b44795f26bda5 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 19 Jun 2017 09:36:55 +0200 Subject: [PATCH] core: added hosts_dict handling in general config: A way to force host was already available through hosts_dict, but for Android only in [android] section. It has now be moved in general conf as it can be useful in other cases, and improved to handle port too. This way if something like this is present in sat.conf: [DEFAULT] hosts_dict = {"example.net": {"host": "127.0.0.1", "port": 7777}} these values will be used and DNS check will be bypassed. A string can also be used for values, in this case only host is changed. --- src/core/xmpp.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/xmpp.py b/src/core/xmpp.py index a670170a..27d19dfb 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -467,12 +467,26 @@ class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient): # TODO: remove this hack and fix SRV log.info(u"FIXME: Android hack, ignoring SRV") host = user_jid.host - hosts_map = host_app.memory.getConfig("android", "hosts_dict", {}) - if host in hosts_map: - log.info(u"using {host_to_use} for host {host_ori} as requested in config".format( - host_ori = host, - host_to_use = hosts_map[host])) - host = hosts_map[host] + + hosts_map = host_app.memory.getConfig(None, "hosts_dict", {}) + if host is None and user_jid.host in hosts_map: + host_data = hosts_map[user_jid.host] + if isinstance(host_data, basestring): + host = host_data + elif isinstance(host_data, dict): + if u'host' in host_data: + host = host_data[u'host'] + if u'port' in host_data: + port = host_data[u'port'] + else: + log.warning(_(u"invalid data used for host: {data}").format(data=host_data)) + host_data = None + if host_data is not None: + log.info(u"using {host}:{port} for host {host_ori} as requested in config".format( + host_ori = user_jid.host, + host = host, + port = port)) + wokkel_client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT) SatXMPPEntity.__init__(self, host_app, profile, max_retries) self._progress_cb = {} # callback called when a progress is requested (key = progress id)