# HG changeset patch # User Goffi # Date 1418232971 -3600 # Node ID cfd636203e8fab545f9d0e333877446692ef07b9 # Parent f8a8434dbac79617362bba42e84aaa2ff9e5d884 core: misc improvments: - added some constants for message types and presence - removed profile authentification specific methods in favor of a more generic "validated" key diff -r f8a8434dbac7 -r cfd636203e8f src/core/constants.py --- a/src/core/constants.py Wed Dec 10 18:32:33 2014 +0100 +++ b/src/core/constants.py Wed Dec 10 18:36:11 2014 +0100 @@ -82,6 +82,22 @@ ## Messages ## MESS_TYPE_INFO = 'info' + MESS_TYPE_CHAT = 'chat' + MESS_TYPE_ERROR = 'error' + MESS_TYPE_GROUPCHAT = 'groupchat' + MESS_TYPE_HEADLINE = 'headline' + MESS_TYPE_NORMAL = 'normal' + + ## PRESENCE ## + PRESENCE_UNAVAILABLE = 'unavailable' + PRESENCE_SHOW_AWAY = 'away' + PRESENCE_SHOW_CHAT = 'chat' + PRESENCE_SHOW_DND = 'dnd' + PRESENCE_SHOW_XA = 'xa' + PRESENCE_SHOW = 'show' + PRESENCE_STATUSES = 'statuses' + PRESENCE_PRIORITY = 'priority' + ## Configuration ## if BaseDirectory: # skipped when xdg module is not available (should not happen in backend) diff -r f8a8434dbac7 -r cfd636203e8f src/memory/memory.py --- a/src/memory/memory.py Wed Dec 10 18:32:33 2014 +0100 +++ b/src/memory/memory.py Wed Dec 10 18:36:11 2014 +0100 @@ -332,8 +332,11 @@ def getProfileName(self, profile_key, return_profile_keys=False): """Return name of profile from keyword + @param profile_key: can be the profile name or a keywork (like @DEFAULT@) - @return: profile name or None if it doesn't exist""" + @param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller + @return: requested profile name or emptry string if it doesn't exist + """ return self.params.getProfileName(profile_key, return_profile_keys) def asyncCreateProfile(self, name, password=''): @@ -342,6 +345,10 @@ @param password: profile password @return: Deferred """ + if not name: + raise ValueError("Empty profile name") + if name[0] == '@': + raise ValueError("A profile name can't start with a '@'") personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam d = self.params.asyncCreateProfile(name) @@ -579,7 +586,7 @@ try: del self._entities_cache[profile][entity] except KeyError: - log.debug("Can't delete entity [%s]: not in cache" % entity.full()) + log.warning(_("Can't delete entity [{}]: not in cache").format(entity.full())) def encryptValue(self, value, profile): """Encrypt a value for the given profile. The personal key must be loaded diff -r f8a8434dbac7 -r cfd636203e8f src/memory/params.py --- a/src/memory/params.py Wed Dec 10 18:32:33 2014 +0100 +++ b/src/memory/params.py Wed Dec 10 18:36:11 2014 +0100 @@ -179,7 +179,7 @@ return defer.fail(Failure(exceptions.ConnectedProfileError)) return self.storage.deleteProfile(profile) - def getProfileName(self, profile_key, return_profile_keys = False): + def getProfileName(self, profile_key, return_profile_keys=False): """return profile according to profile_key @param profile_key: profile name or key which can be diff -r f8a8434dbac7 -r cfd636203e8f src/stdui/ui_profile_manager.py --- a/src/stdui/ui_profile_manager.py Wed Dec 10 18:32:33 2014 +0100 +++ b/src/stdui/ui_profile_manager.py Wed Dec 10 18:36:11 2014 +0100 @@ -48,20 +48,20 @@ def gotProfileCipher(profile_cipher): if self.host.memory.auth_sessions.profileGetUnique(profile): # case 1: profile already authenticated - return {'authenticated_profile': profile, 'caller': data['caller']} + return {'validated': C.str(True)} self.profile_ciphers[profile] = profile_cipher if 'profile_password' in data: # case 2: password is provided by the caller return self._verifyPassword(data, profile) - def check_empty_password(empty_password_result): - if 'authenticated_profile' in empty_password_result: + def check_empty_password(verify_password_result): + validated = C.bool(verify_password_result['validated']) + if validated: # case 3: there's no password for this profile - return empty_password_result + return verify_password_result # case 4: prompt the user for a password def xmlui_cb(data_, profile): - data_['caller'] = data['caller'] return self._verifyPassword(data_, profile) callback_id = self.host.registerCallback(xmlui_cb, with_data=True, one_shot=True) @@ -69,11 +69,10 @@ form_ui.addPassword('profile_password', value='') return {'xmlui': form_ui.toXml()} - check_empty_data = {'profile_password': '', 'caller': data['caller']} + check_empty_data = {'profile_password': ''} d = self._verifyPassword(check_empty_data, profile) return d.addCallback(check_empty_password) - assert(data['caller']) d = self.host.memory.asyncGetStringParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) d.addCallback(gotProfileCipher) d.addErrback(self.getParamError) @@ -82,7 +81,7 @@ def getParamError(self, failure): _dialog = xml_tools.XMLUI('popup', title=D_('Error')) _dialog.addText(D_("Can't get profile parameter.")) - return {'xmlui': _dialog.toXml()} + return {'xmlui': _dialog.toXml(), 'validated': C.str(False)} @defer.inlineCallbacks def _verifyPassword(self, data, profile): @@ -93,7 +92,6 @@ @return: deferred dict """ assert(profile in self.profile_ciphers) - assert(data['caller']) try: profile_password = data[xml_tools.formEscape('profile_password')] @@ -103,10 +101,10 @@ if not verified: _dialog = xml_tools.XMLUI('popup', title=D_('Connection error')) _dialog.addText(D_("The provided profile password doesn't match.")) - defer.returnValue({'xmlui': _dialog.toXml()}) + defer.returnValue({'xmlui': _dialog.toXml(), 'validated': C.str(False)}) yield self.host.memory.newAuthSession(profile_password, profile) - defer.returnValue({'authenticated_profile': profile, 'caller': data['caller']}) + defer.returnValue({'validated': C.str(True)}) def _changeXMPPPassword(self, data, profile): session_data = self._sessions.profileGetUnique(profile)