poezio/connection: Prepare for global config removal
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
e74ff9c33c
commit
76b3f30dd4
1 changed files with 29 additions and 27 deletions
|
@ -39,24 +39,26 @@ class Connection(slixmpp.ClientXMPP):
|
|||
__init = False
|
||||
|
||||
def __init__(self, custom_version=''):
|
||||
keyfile = config.getstr('keyfile')
|
||||
certfile = config.getstr('certfile')
|
||||
self.config = config
|
||||
|
||||
device_id = config.getstr('device_id')
|
||||
keyfile = self.config.getstr('keyfile')
|
||||
certfile = self.config.getstr('certfile')
|
||||
|
||||
device_id = self.config.getstr('device_id')
|
||||
if not device_id:
|
||||
rng = random.SystemRandom()
|
||||
device_id = base64.urlsafe_b64encode(
|
||||
rng.getrandbits(24).to_bytes(3, 'little')).decode('ascii')
|
||||
config.set_and_save('device_id', device_id)
|
||||
self.config.set_and_save('device_id', device_id)
|
||||
|
||||
if config.getstr('jid'):
|
||||
if self.config.getstr('jid'):
|
||||
# Field used to know if we are anonymous or not.
|
||||
# many features will be handled differently
|
||||
# depending on this setting
|
||||
self.anon = False
|
||||
jid = config.getstr('jid')
|
||||
password = config.getstr('password')
|
||||
eval_password = config.getstr('eval_password')
|
||||
jid = self.config.getstr('jid')
|
||||
password = self.config.getstr('password')
|
||||
eval_password = self.config.getstr('eval_password')
|
||||
if not password and not eval_password and not (keyfile
|
||||
and certfile):
|
||||
password = getpass.getpass()
|
||||
|
@ -80,7 +82,7 @@ class Connection(slixmpp.ClientXMPP):
|
|||
'\n')
|
||||
else: # anonymous auth
|
||||
self.anon = True
|
||||
jid = config.getstr('server')
|
||||
jid = self.config.getstr('server')
|
||||
password = None
|
||||
try:
|
||||
jid = JID(jid)
|
||||
|
@ -92,9 +94,9 @@ class Connection(slixmpp.ClientXMPP):
|
|||
device_id) if jid.resource else 'poezio-%s' % device_id
|
||||
# TODO: use the system language
|
||||
slixmpp.ClientXMPP.__init__(
|
||||
self, jid, password, lang=config.getstr('lang'))
|
||||
self, jid, password, lang=self.config.getstr('lang'))
|
||||
|
||||
force_encryption = config.getbool('force_encryption')
|
||||
force_encryption = self.config.getbool('force_encryption')
|
||||
if force_encryption:
|
||||
self['feature_mechanisms'].unencrypted_plain = False
|
||||
self['feature_mechanisms'].unencrypted_digest = False
|
||||
|
@ -111,18 +113,18 @@ class Connection(slixmpp.ClientXMPP):
|
|||
'certfile is present in configuration file without keyfile')
|
||||
|
||||
self.core = None
|
||||
self.auto_reconnect = config.getbool('auto_reconnect')
|
||||
self.auto_reconnect = self.config.getbool('auto_reconnect')
|
||||
self.auto_authorize = None
|
||||
# prosody defaults, lowest is AES128-SHA, it should be a minimum
|
||||
# for anything that came out after 2002
|
||||
self.ciphers = config.getstr(
|
||||
self.ciphers = self.config.getstr(
|
||||
'ciphers', 'HIGH+kEDH:HIGH+kEECDH:HIGH:!PSK'
|
||||
':!SRP:!3DES:!aNULL')
|
||||
self.ca_certs = None
|
||||
ca_certs = config.getlist('ca_cert_path')
|
||||
ca_certs = self.config.getlist('ca_cert_path')
|
||||
if ca_certs and ca_certs != ['']:
|
||||
self.ca_certs = list(map(Path, config.getlist('ca_cert_path')))
|
||||
interval = config.getint('whitespace_interval')
|
||||
self.ca_certs = list(map(Path, self.config.getlist('ca_cert_path')))
|
||||
interval = self.config.getint('whitespace_interval')
|
||||
if int(interval) > 0:
|
||||
self.whitespace_keepalive_interval = int(interval)
|
||||
else:
|
||||
|
@ -160,21 +162,21 @@ class Connection(slixmpp.ClientXMPP):
|
|||
# without a body
|
||||
XEP_0184._filter_add_receipt_request = fixes._filter_add_receipt_request
|
||||
self.register_plugin('xep_0184')
|
||||
self.plugin['xep_0184'].auto_ack = config.getbool('ack_message_receipts')
|
||||
self.plugin['xep_0184'].auto_request = config.getbool(
|
||||
self.plugin['xep_0184'].auto_ack = self.config.getbool('ack_message_receipts')
|
||||
self.plugin['xep_0184'].auto_request = self.config.getbool(
|
||||
'request_message_receipts')
|
||||
|
||||
self.register_plugin('xep_0191')
|
||||
if config.getbool('enable_smacks'):
|
||||
if self.config.getbool('enable_smacks'):
|
||||
self.register_plugin('xep_0198')
|
||||
self.register_plugin('xep_0199')
|
||||
|
||||
if config.getbool('enable_user_nick'):
|
||||
if self.config.getbool('enable_user_nick'):
|
||||
self.register_plugin('xep_0172')
|
||||
|
||||
if config.getbool('send_poezio_info'):
|
||||
if self.config.getbool('send_poezio_info'):
|
||||
info = {'name': 'poezio', 'version': custom_version}
|
||||
if config.getbool('send_os_info'):
|
||||
if self.config.getbool('send_os_info'):
|
||||
info['os'] = common.get_os_info()
|
||||
self.plugin['xep_0030'].set_identities(identities={('client',
|
||||
'console',
|
||||
|
@ -186,7 +188,7 @@ class Connection(slixmpp.ClientXMPP):
|
|||
'console',
|
||||
None, '')})
|
||||
self.register_plugin('xep_0092', pconfig=info)
|
||||
if config.getbool('send_time'):
|
||||
if self.config.getbool('send_time'):
|
||||
self.register_plugin('xep_0202')
|
||||
self.register_plugin('xep_0224')
|
||||
self.register_plugin('xep_0231')
|
||||
|
@ -221,8 +223,8 @@ class Connection(slixmpp.ClientXMPP):
|
|||
# Happens when we change the value with /set while we are not
|
||||
# connected. Do nothing in that case
|
||||
return
|
||||
ping_interval = config.getint('connection_check_interval')
|
||||
timeout_delay = config.getint('connection_timeout_delay')
|
||||
ping_interval = self.config.getint('connection_check_interval')
|
||||
timeout_delay = self.config.getint('connection_timeout_delay')
|
||||
if timeout_delay <= 0:
|
||||
# We help the stupid user (with a delay of 0, poezio will try to
|
||||
# reconnect immediately because the timeout is immediately
|
||||
|
@ -239,8 +241,8 @@ class Connection(slixmpp.ClientXMPP):
|
|||
"""
|
||||
Connect and process events.
|
||||
"""
|
||||
custom_host = config.getstr('custom_host')
|
||||
custom_port = config.get('custom_port', 5222)
|
||||
custom_host = self.config.getstr('custom_host')
|
||||
custom_port = self.config.get('custom_port', 5222)
|
||||
if custom_port == -1:
|
||||
custom_port = 5222
|
||||
if custom_host:
|
||||
|
|
Loading…
Reference in a new issue