diff src/core/xmpp.py @ 2259:f51315500eb1

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.
author Goffi <goffi@goffi.org>
date Mon, 19 Jun 2017 09:36:55 +0200
parents 545a1261ac3b
children 8b37a62336c3
line wrap: on
line diff
--- a/src/core/xmpp.py	Sat Jun 03 22:24:53 2017 +0200
+++ b/src/core/xmpp.py	Mon Jun 19 09:36:55 2017 +0200
@@ -467,12 +467,26 @@
             # 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)