From 210eb6412317e7e4387bbe4caf5231d6e7d30f0a Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 04 Feb 2008 12:29:46 +0000 Subject: try opportunistic registration if authentication fails (#6295) --- diff --git a/src/server_plugin.py b/src/server_plugin.py index 9ebc8d9..514f949 100644 --- a/src/server_plugin.py +++ b/src/server_plugin.py @@ -32,7 +32,7 @@ from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE, from telepathy.constants import (HANDLE_TYPE_CONTACT, HANDLE_TYPE_GROUP, CONNECTION_STATUS_CONNECTED, CONNECTION_STATUS_DISCONNECTED, CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES, - CONNECTION_STATUS_REASON_NAME_IN_USE) + CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED) import sugar.profile # Presence Service local modules @@ -76,7 +76,10 @@ class ServerPlugin(TelepathyPlugin): self._stop() def _get_account_info(self): - """Retrieve connection manager parameters for this account + """Retrieve connection manager parameters for this account. + We first try to connect without the register flag. If the connection + fails because of an authentification error we'll try to register + the account. """ server = self._owner.get_server() khash = psutils.pubkey_to_keyid(self._owner.props.key) @@ -85,7 +88,7 @@ class ServerPlugin(TelepathyPlugin): 'account': "%s@%s" % (khash, server), 'fallback-conference-server': "conference.%s" % server, 'password': self._owner.get_key_hash(), - 'register': not self._owner.get_registered(), + 'register': False, 'port': dbus.UInt32(5223), 'old-ssl': True, 'ignore-ssl-errors': True, @@ -234,10 +237,6 @@ class ServerPlugin(TelepathyPlugin): return ret def _connected_cb(self): - if not self._owner.get_registered(): - # we successfully register this account - self._owner.set_registered(True) - TelepathyPlugin._connected_cb(self) # request Friends group channel @@ -305,17 +304,17 @@ class ServerPlugin(TelepathyPlugin): def _handle_connection_status_change(self, status, reason): """Override TelepathyPlugin implementation to manage connection errors - due to registration problem. So, if for any reason the registered flag - was not set in the config file but the account was registered, we don't - fail to connect (see ticket #2062).""" + due to authentification problem. If the connection fails because of an + authentification error that's probably because the account isn't + registered yet on the server. So we try to register it.""" if status == self._conn_status: return if (status == CONNECTION_STATUS_DISCONNECTED and - reason == CONNECTION_STATUS_REASON_NAME_IN_USE and - self._account['register']): - _logger.debug('This account is already registered. Connect to it') - self._account['register'] = False + reason == CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED and + not self._account['register']): + _logger.debug('Authentification failed. Try to register the account') + self._account['register'] = True self._stop() self._init_connection() return -- cgit v0.9.1