diff options
Diffstat (limited to 'src/connection.py')
-rw-r--r-- | src/connection.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/src/connection.py b/src/connection.py index b5b7e12e..214194f9 100644 --- a/src/connection.py +++ b/src/connection.py @@ -14,15 +14,15 @@ log = logging.getLogger(__name__) import getpass -import sleekxmpp -from sleekxmpp.plugins.xep_0184 import XEP_0184 +import slixmpp +from slixmpp.plugins.xep_0184 import XEP_0184 import common import fixes from common import safeJID from config import config, options -class Connection(sleekxmpp.ClientXMPP): +class Connection(slixmpp.ClientXMPP): """ Receives everything from Jabber and emits the appropriate signals @@ -47,7 +47,7 @@ class Connection(sleekxmpp.ClientXMPP): password = None jid = safeJID(jid) # TODO: use the system language - sleekxmpp.ClientXMPP.__init__(self, jid, password, + slixmpp.ClientXMPP.__init__(self, jid, password, lang=config.get('lang', 'en')) force_encryption = config.get('force_encryption', True) @@ -58,7 +58,6 @@ class Connection(sleekxmpp.ClientXMPP): self['feature_mechanisms'].unencrypted_scram = False self.core = None - self.auto_reconnect = config.get('auto_reconnect', False) self.reconnect_max_attempts = 0 self.auto_authorize = None # prosody defaults, lowest is AES128-SHA, it should be a minimum @@ -97,7 +96,6 @@ class Connection(sleekxmpp.ClientXMPP): self.register_plugin('xep_0191') self.register_plugin('xep_0199') - self.set_keepalive_values() if config.get('enable_user_tune', True): self.register_plugin('xep_0118') @@ -133,14 +131,18 @@ class Connection(sleekxmpp.ClientXMPP): self.register_plugin('xep_0280') self.register_plugin('xep_0297') self.register_plugin('xep_0308') + self.init_plugins() def set_keepalive_values(self, option=None, value=None): """ - Called at startup, or triggered when one of + Called after the XMPP session has been started, or triggered when one of "connection_timeout_delay" and "connection_check_interval" options - is changed. - Unload and reload the ping plugin, with the new values. + is changed. Unload and reload the ping plugin, with the new values. """ + if not self.is_connected(): + # Happens when we change the value with /set while we are not + # connected. Do nothing in that case + return ping_interval = config.get('connection_check_interval', 60) timeout_delay = config.get('connection_timeout_delay', 10) if timeout_delay <= 0: @@ -158,34 +160,27 @@ class Connection(sleekxmpp.ClientXMPP): def start(self): """ Connect and process events. - - TODO: try multiple servers with anon auth. """ custom_host = config.get('custom_host', '') custom_port = config.get('custom_port', 5222) if custom_port == -1: custom_port = 5222 if custom_host: - res = self.connect((custom_host, custom_port), reattempt=True) + self.connect((custom_host, custom_port)) elif custom_port != 5222 and custom_port != -1: - res = self.connect((self.boundjid.host, custom_port), - reattempt=True) + self.connect((self.boundjid.host, custom_port)) else: - res = self.connect(reattempt=True) - if not res: - return False - self.process(threaded=True) - return True + self.connect() - def send_raw(self, data, now=False, reconnect=None): + def send_raw(self, data): """ Overrides XMLStream.send_raw, with an event added """ if self.core: self.core.outgoing_stanza(data) - sleekxmpp.ClientXMPP.send_raw(self, data, now, reconnect) + slixmpp.ClientXMPP.send_raw(self, data) -class MatchAll(sleekxmpp.xmlstream.matcher.base.MatcherBase): +class MatchAll(slixmpp.xmlstream.matcher.base.MatcherBase): """ Callback to retrieve all the stanzas for the XML tab """ |