Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
2258:074c2f157dc9 | 2259:f51315500eb1 |
---|---|
465 if sys.platform == "android": | 465 if sys.platform == "android": |
466 # FIXME: temporary hack as SRV is not working on android | 466 # FIXME: temporary hack as SRV is not working on android |
467 # TODO: remove this hack and fix SRV | 467 # TODO: remove this hack and fix SRV |
468 log.info(u"FIXME: Android hack, ignoring SRV") | 468 log.info(u"FIXME: Android hack, ignoring SRV") |
469 host = user_jid.host | 469 host = user_jid.host |
470 hosts_map = host_app.memory.getConfig("android", "hosts_dict", {}) | 470 |
471 if host in hosts_map: | 471 hosts_map = host_app.memory.getConfig(None, "hosts_dict", {}) |
472 log.info(u"using {host_to_use} for host {host_ori} as requested in config".format( | 472 if host is None and user_jid.host in hosts_map: |
473 host_ori = host, | 473 host_data = hosts_map[user_jid.host] |
474 host_to_use = hosts_map[host])) | 474 if isinstance(host_data, basestring): |
475 host = hosts_map[host] | 475 host = host_data |
476 elif isinstance(host_data, dict): | |
477 if u'host' in host_data: | |
478 host = host_data[u'host'] | |
479 if u'port' in host_data: | |
480 port = host_data[u'port'] | |
481 else: | |
482 log.warning(_(u"invalid data used for host: {data}").format(data=host_data)) | |
483 host_data = None | |
484 if host_data is not None: | |
485 log.info(u"using {host}:{port} for host {host_ori} as requested in config".format( | |
486 host_ori = user_jid.host, | |
487 host = host, | |
488 port = port)) | |
489 | |
476 wokkel_client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT) | 490 wokkel_client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT) |
477 SatXMPPEntity.__init__(self, host_app, profile, max_retries) | 491 SatXMPPEntity.__init__(self, host_app, profile, max_retries) |
478 self._progress_cb = {} # callback called when a progress is requested (key = progress id) | 492 self._progress_cb = {} # callback called when a progress is requested (key = progress id) |
479 self.actions = {} # used to keep track of actions for retrieval (key = action_id) | 493 self.actions = {} # used to keep track of actions for retrieval (key = action_id) |
480 | 494 |