implement XEP-0156. Fixes #5795
This commit is contained in:
parent
24320c894c
commit
149edfe3ef
2 changed files with 44 additions and 3 deletions
|
@ -181,6 +181,11 @@ class CommonConnection:
|
||||||
|
|
||||||
self.get_config_values_or_default()
|
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):
|
def _compute_resource(self):
|
||||||
resource = app.config.get_per('accounts', self.name, 'resource')
|
resource = app.config.get_per('accounts', self.name, 'resource')
|
||||||
# All valid resource substitution strings should be added to this hash.
|
# All valid resource substitution strings should be added to this hash.
|
||||||
|
@ -1104,6 +1109,28 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
i['ssl_port'] = ssl_p
|
i['ssl_port'] = ssl_p
|
||||||
self._connect_to_next_host()
|
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):
|
def _connect_to_next_host(self, retry=False):
|
||||||
log.debug('Connection to next host')
|
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_success = self._on_new_account
|
||||||
self.on_connect_failure = self._on_new_account
|
self.on_connect_failure = self._on_new_account
|
||||||
self.connect(config)
|
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):
|
def _on_new_account(self, con=None, con_type=None):
|
||||||
if not con_type:
|
if not con_type:
|
||||||
|
|
|
@ -94,9 +94,8 @@ class GioResolver(CommonResolver):
|
||||||
|
|
||||||
def start_resolve(self, host, type_):
|
def start_resolve(self, host, type_):
|
||||||
if type_ == 'txt':
|
if type_ == 'txt':
|
||||||
# TXT record resolution isn't used anywhere at the moment so
|
callback = functools.partial(self._on_ready_txt, host)
|
||||||
# implementing it here isn't urgent
|
type_ = Gio.ResolverRecordType.TXT
|
||||||
raise NotImplementedError("Gio resolver does not currently implement TXT records")
|
|
||||||
else:
|
else:
|
||||||
callback = functools.partial(self._on_ready_srv, host)
|
callback = functools.partial(self._on_ready_srv, host)
|
||||||
type_ = Gio.ResolverRecordType.SRV
|
type_ = Gio.ResolverRecordType.SRV
|
||||||
|
@ -125,6 +124,19 @@ class GioResolver(CommonResolver):
|
||||||
]
|
]
|
||||||
super()._on_ready(host, 'srv', result_list)
|
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
|
# below lines is on how to use API and assist in testing
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue