Yann Leboulanger pushed to branch master at gajim / gajim
Commits:
149edfe3 by Yann Leboulanger at 2017-11-20T21:31:29+01:00
implement XEP-0156. Fixes #5795
- - - - -
46711e11 by Yann Leboulanger at 2017-11-29T14:25:49+01:00
Merge branch 'XEP-156' into 'master'
implement XEP-0156
Closes #5795
See merge request gajim/gajim!154
- - - - -
2 changed files:
- gajim/common/connection.py
- gajim/common/resolver.py
Changes:
=====================================
gajim/common/connection.py
=====================================
--- a/gajim/common/connection.py
+++ b/gajim/common/connection.py
@@ -182,6 +182,11 @@ class CommonConnection:
self.get_config_values_or_default()
+ h = app.config.get_per('accounts', self.name, 'hostname')
+ if h:
+ app.resolver.resolve('_xmppconnect.' + helpers.idn_to_ascii(h),
+ self._on_resolve_txt, type_='txt')
+
def _compute_resource(self):
resource = app.config.get_per('accounts', self.name, 'resource')
# All valid resource substitution strings should be added to this hash.
@@ -1106,6 +1111,28 @@ class Connection(CommonConnection, ConnectionHandlers):
i['ssl_port'] = ssl_p
self._connect_to_next_host()
+ def _on_resolve_txt(self, host, result_array):
+ for res in result_array:
+ if res.startswith('_xmpp-client-xbosh='):
+ url = res[19:]
+ found = False
+ proxies = app.config.get_per('proxies')
+ for p in proxies:
+ if app.config.get_per('proxies', p, 'type') == 'bosh' \
+ and app.config.get_per('proxies', p, 'bosh_uri') == url:
+ found = True
+ break
+ if not found:
+ h = app.config.get_per('accounts', self.name, 'hostname')
+ p = 'bosh_' + h
+ i = 0
+ while p in proxies:
+ i += 1
+ p = 'bosh_' + h + str(i)
+ app.config.add_per('proxies', p)
+ app.config.set_per('proxies', p, 'type', 'bosh')
+ app.config.set_per('proxies', p, 'bosh_uri', url)
+
def _connect_to_next_host(self, retry=False):
log.debug('Connection to next host')
@@ -2212,6 +2239,8 @@ class Connection(CommonConnection, ConnectionHandlers):
self.on_connect_success = self._on_new_account
self.on_connect_failure = self._on_new_account
self.connect(config)
+ app.resolver.resolve('_xmppconnect.' + helpers.idn_to_ascii(
+ self._hostname), self._on_resolve_txt, type_='txt')
def _on_new_account(self, con=None, con_type=None):
if not con_type:
=====================================
gajim/common/resolver.py
=====================================
--- a/gajim/common/resolver.py
+++ b/gajim/common/resolver.py
@@ -94,9 +94,8 @@ class GioResolver(CommonResolver):
def start_resolve(self, host, type_):
if type_ == 'txt':
- # TXT record resolution isn't used anywhere at the moment so
- # implementing it here isn't urgent
- raise NotImplementedError("Gio resolver does not currently
implement TXT records")
+ callback = functools.partial(self._on_ready_txt, host)
+ type_ = Gio.ResolverRecordType.TXT
else:
callback = functools.partial(self._on_ready_srv, host)
type_ = Gio.ResolverRecordType.SRV
@@ -125,6 +124,19 @@ class GioResolver(CommonResolver):
]
super()._on_ready(host, 'srv', result_list)
+ def _on_ready_txt(self, host, source_object, result):
+ try:
+ variant_results = source_object.lookup_records_finish(result)
+ except GLib.Error as e:
+ if e.domain == 'g-resolver-error-quark':
+ result_list = []
+ log.warning("Could not resolve host: %s", e.message)
+ else:
+ raise
+ else:
+ result_list = [res[0][0] for res in variant_results]
+ super()._on_ready(host, 'txt', result_list)
+
# below lines is on how to use API and assist in testing
if __name__ == '__main__':
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/b3ef0d61962d310a95424c12d4eacf41149da4ae...46711e1107361e9b6d2e991d1b21341a7451196b
---
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/b3ef0d61962d310a95424c12d4eacf41149da4ae...46711e1107361e9b6d2e991d1b21341a7451196b
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits