Mercurial > libervia-backend
annotate src/memory/memory.py @ 1689:a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Nov 2015 17:00:18 +0100 |
parents | 373ce871b0f3 |
children | 35426d58471c |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
4 # SAT: a jabber client |
1396 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
771 | 20 from sat.core.i18n import _ |
0 | 21 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
22 from sat.core.log import getLogger |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
23 log = getLogger(__name__) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
24 |
0 | 25 import os.path |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
26 import copy |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
27 from collections import namedtuple |
364 | 28 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
29 from uuid import uuid4 |
1447 | 30 from twisted.python import failure |
31 from twisted.internet import defer, reactor, error | |
47 | 32 from twisted.words.protocols.jabber import jid |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
33 from sat.core import exceptions |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
34 from sat.core.constants import Const as C |
432
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
35 from sat.memory.sqlite import SqliteStorage |
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
36 from sat.memory.persistent import PersistentDict |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
37 from sat.memory.params import Params |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
38 from sat.memory.disco import Discovery |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
39 from sat.memory.crypto import BlockCipher |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
40 from sat.memory.crypto import PasswordHasher |
1064
7ee9d9db67b9
memory, tools (config): move special config retrieval from memory to tools
souliane <souliane@mailoo.org>
parents:
1046
diff
changeset
|
41 from sat.tools import config as tools_config |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
42 |
679
59c9a7ff903d
wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
677
diff
changeset
|
43 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
44 PresenceTuple = namedtuple("PresenceTuple", ('show', 'priority', 'statuses')) |
1447 | 45 MSG_NO_SESSION = "Session id doesn't exist or is finished" |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
46 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
47 class Sessions(object): |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
48 """Sessions are data associated to key used for a temporary moment, with optional profile checking.""" |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
49 DEFAULT_TIMEOUT = 600 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
50 |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
51 def __init__(self, timeout=None, resettable_timeout=True): |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
52 """ |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
53 @param timeout (int): nb of seconds before session destruction |
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
54 @param resettable_timeout (bool): if True, the timeout is reset on each access |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
55 """ |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
56 self._sessions = dict() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
57 self.timeout = timeout or Sessions.DEFAULT_TIMEOUT |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
58 self.resettable_timeout = resettable_timeout |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
59 |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
60 def newSession(self, session_data=None, session_id=None, profile=None): |
1447 | 61 """Create a new session |
62 | |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
63 @param session_data: mutable data to use, default to a dict |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
64 @param session_id (str): force the session_id to the given string |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
65 @param profile: if set, the session is owned by the profile, |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
66 and profileGet must be used instead of __getitem__ |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
67 @return: session_id, session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
68 """ |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
69 if session_id is None: |
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
70 session_id = str(uuid4()) |
1213
b5928601d7aa
memory: handle the case where an existing session ID is re-used for creating a new session
souliane <souliane@mailoo.org>
parents:
1212
diff
changeset
|
71 elif session_id in self._sessions: |
1447 | 72 raise exceptions.ConflictError(u"Session id {} is already used".format(session_id)) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
73 timer = reactor.callLater(self.timeout, self._purgeSession, session_id) |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
74 if session_data is None: |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
75 session_data = {} |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
76 self._sessions[session_id] = (timer, session_data) if profile is None else (timer, session_data, profile) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
77 return session_id, session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
78 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
79 def _purgeSession(self, session_id): |
1447 | 80 try: |
81 timer, session_data, profile = self._sessions[session_id] | |
82 except ValueError: | |
83 timer, session_data = self._sessions[session_id] | |
84 profile = None | |
85 try: | |
86 timer.cancel() | |
87 except error.AlreadyCalled: | |
88 # if the session is time-outed, the timer has been called | |
89 pass | |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
90 del self._sessions[session_id] |
1447 | 91 log.debug(u"Session {} purged{}".format(session_id, u' (profile {})'.format(profile) if profile is not None else u'')) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
92 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
93 def __len__(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
94 return len(self._sessions) |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
95 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
96 def __contains__(self, session_id): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
97 return session_id in self._sessions |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
98 |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
99 def profileGet(self, session_id, profile): |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
100 try: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
101 timer, session_data, profile_set = self._sessions[session_id] |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
102 except ValueError: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
103 raise exceptions.InternalError("You need to use __getitem__ when profile is not set") |
1447 | 104 except KeyError: |
105 raise failure.Failure(KeyError(MSG_NO_SESSION)) | |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
106 if profile_set != profile: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
107 raise exceptions.InternalError("current profile differ from set profile !") |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
108 if self.resettable_timeout: |
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
109 timer.reset(self.timeout) |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
110 return session_data |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
111 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
112 def __getitem__(self, session_id): |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
113 try: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
114 timer, session_data = self._sessions[session_id] |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
115 except ValueError: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
116 raise exceptions.InternalError("You need to use profileGet instead of __getitem__ when profile is set") |
1447 | 117 except KeyError: |
118 raise failure.Failure(KeyError(MSG_NO_SESSION)) | |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
119 if self.resettable_timeout: |
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
120 timer.reset(self.timeout) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
121 return session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
122 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
123 def __setitem__(self, key, value): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
124 raise NotImplementedError("You need do use newSession to create a session") |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
125 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
126 def __delitem__(self, session_id): |
1474
c2a498dce4b4
core (memory): fixed a double timer.cancel in Sessions
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
127 """ delete the session data """ |
1447 | 128 self._purgeSession(session_id) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
129 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
130 def keys(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
131 return self._sessions.keys() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
132 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
133 def iterkeys(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
134 return self._sessions.iterkeys() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
135 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
136 |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
137 class ProfileSessions(Sessions): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
138 """ProfileSessions extends the Sessions class, but here the profile can be |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
139 used as the key to retrieve data or delete a session (instead of session id). |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
140 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
141 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
142 def _profileGetAllIds(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
143 """Return a list of the sessions ids that are associated to the given profile. |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
144 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
145 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
146 @return: a list containing the sessions ids |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
147 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
148 ret = [] |
1447 | 149 for session_id in self._sessions.iterkeys(): |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
150 try: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
151 timer, session_data, profile_set = self._sessions[session_id] |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
152 except ValueError: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
153 continue |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
154 if profile == profile_set: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
155 ret.append(session_id) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
156 return ret |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
157 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
158 def profileGetUnique(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
159 """Return the data of the unique session that is associated to the given profile. |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
160 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
161 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
162 @return: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
163 - mutable data (default: dict) of the unique session |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
164 - None if no session is associated to the profile |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
165 - raise an error if more than one session are found |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
166 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
167 ids = self._profileGetAllIds(profile) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
168 if len(ids) > 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
169 raise exceptions.InternalError('profileGetUnique has been used but more than one session has been found!') |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
170 return self.profileGet(ids[0], profile) if len(ids) == 1 else None # XXX: timeout might be reset |
1214
ed3b01ed70d7
memory: profileSessions.profileGetUnique was not resetting the timer
souliane <souliane@mailoo.org>
parents:
1213
diff
changeset
|
171 |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
172 def profileDelUnique(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
173 """Delete the unique session that is associated to the given profile. |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
174 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
175 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
176 @return: None, but raise an error if more than one session are found |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
177 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
178 ids = self._profileGetAllIds(profile) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
179 if len(ids) > 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
180 raise exceptions.InternalError('profileDelUnique has been used but more than one session has been found!') |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
181 if len(ids) == 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
182 del self._sessions[ids[0]] |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
183 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
184 |
1247
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
185 class PasswordSessions(ProfileSessions): |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
186 |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
187 # FIXME: temporary hack for the user personal key not to be lost. The session |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
188 # must actually be purged and later, when the personal key is needed, the |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
189 # profile password should be asked again in order to decrypt it. |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
190 def __init__(self, timeout=None): |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
191 ProfileSessions.__init__(self, timeout, resettable_timeout=False) |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
192 |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
193 def _purgeSession(self, session_id): |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
194 log.debug("FIXME: PasswordSessions should ask for the profile password after the session expired") |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
195 |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
196 |
1003
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
197 # XXX: tmp update code, will be removed in the future |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
198 # When you remove this, please add the default value for |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
199 # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
200 def fixLocalDir(silent=True): |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
201 """Retro-compatibility with the previous local_dir default value. |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
202 |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
203 @param silent (boolean): toggle logging output (must be True when called from sat.sh) |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
204 """ |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
205 user_config = SafeConfigParser() |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
206 try: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
207 user_config.read(C.CONFIG_FILES) |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
208 except: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
209 pass # file is readable but its structure if wrong |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
210 try: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
211 current_value = user_config.get('DEFAULT', 'local_dir') |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
212 except (NoOptionError, NoSectionError): |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
213 current_value = '' |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
214 if current_value: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
215 return # nothing to do |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
216 old_default = '~/.sat' |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
217 if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE): |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
218 if not silent: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
219 log.warning(_(u"A database has been found in the default local_dir for previous versions (< 0.5)")) |
1064
7ee9d9db67b9
memory, tools (config): move special config retrieval from memory to tools
souliane <souliane@mailoo.org>
parents:
1046
diff
changeset
|
220 tools_config.fixConfigOption('', 'local_dir', old_default, silent) |
1003
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
221 |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
222 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
223 class Memory(object): |
1199 | 224 """This class manage all the persistent information""" |
0 | 225 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
226 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
227 log.info(_("Memory manager init")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
228 self.initialized = defer.Deferred() |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
229 self.host = host |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
230 self._entities_cache = {} # XXX: keep presence/last resource/other data in cache |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
231 # /!\ an entity is not necessarily in roster |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
232 # main key is bare jid, value is a dict |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
233 # where main key is resource, or None for bare jid |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
234 self._key_signals = set() # key which need a signal to frontends when updated |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
235 self.subscriptions = {} |
1247
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
236 self.auth_sessions = PasswordSessions() # remember the authenticated profiles |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
237 self.disco = Discovery(host) |
1003
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
238 fixLocalDir(False) # XXX: tmp update code, will be removed in the future |
364 | 239 self.config = self.parseMainConf() |
923 | 240 database_file = os.path.expanduser(os.path.join(self.getConfig('', 'local_dir'), C.SAVEFILE_DATABASE)) |
1375
3a20312d4012
core: if we are in dev version and it's possible, repository data are now checked and added to SàT version
Goffi <goffi@goffi.org>
parents:
1315
diff
changeset
|
241 self.storage = SqliteStorage(database_file, host.version) |
432
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
242 PersistentDict.storage = self.storage |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
243 self.params = Params(host, self.storage) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
244 log.info(_("Loading default params template")) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
245 self.params.load_default_params() |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
246 d = self.storage.initialized.addCallback(lambda ignore: self.load()) |
443
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
247 self.memory_data = PersistentDict("memory") |
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
248 d.addCallback(lambda ignore: self.memory_data.load()) |
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1682
diff
changeset
|
249 d.addCallback(lambda ignore: self.disco.load()) |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
250 d.chainDeferred(self.initialized) |
0 | 251 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
252 ## Configuration ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
253 |
364 | 254 def parseMainConf(self): |
255 """look for main .ini configuration file, and parse it""" | |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
923
diff
changeset
|
256 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
257 try: |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
923
diff
changeset
|
258 config.read(C.CONFIG_FILES) |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
259 except: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
260 log.error(_("Can't read main config !")) |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
923
diff
changeset
|
261 return config |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
262 |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
263 def getConfig(self, section, name, default=None): |
364 | 264 """Get the main configuration option |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
265 |
364 | 266 @param section: section of the config file (None or '' for DEFAULT) |
267 @param name: name of the option | |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
268 @param default: value to use if not found |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
269 @return: str, list or dict |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
270 """ |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
271 return tools_config.getConfig(self.config, section, name, default) |
364 | 272 |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
273 def load_xml(self, filename): |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
274 """Load parameters template from xml file |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
275 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
276 @param filename (str): input file |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
277 @return: bool: True in case of success |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
278 """ |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
279 if not filename: |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
280 return False |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
281 filename = os.path.expanduser(filename) |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
282 if os.path.exists(filename): |
0 | 283 try: |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
284 self.params.load_xml(filename) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
285 log.debug(_(u"Parameters loaded from file: %s") % filename) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
286 return True |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
287 except Exception as e: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
288 log.error(_(u"Can't load parameters from file: %s") % e) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
289 return False |
0 | 290 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
291 def save_xml(self, filename): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
292 """Save parameters template to xml file |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
293 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
294 @param filename (str): output file |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
295 @return: bool: True in case of success |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
296 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
297 if not filename: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
298 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
299 #TODO: need to encrypt files (at least passwords !) and set permissions |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
300 filename = os.path.expanduser(filename) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
301 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
302 self.params.save_xml(filename) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
303 log.debug(_(u"Parameters saved to file: %s") % filename) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
304 return True |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
305 except Exception as e: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
306 log.error(_(u"Can't save parameters to file: %s") % e) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
307 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
308 |
443
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
309 def load(self): |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
310 """Load parameters and all memory things from db""" |
412 | 311 #parameters data |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
312 return self.params.loadGenParams() |
412 | 313 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
314 def loadIndividualParams(self, profile): |
412 | 315 """Load individual parameters for a profile |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
316 @param profile: %(doc_profile)s""" |
412 | 317 return self.params.loadIndParams(profile) |
318 | |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
319 ## Profiles/Sessions management ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
320 |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
321 def _startSession(self, password, profile_key): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
322 profile = self.getProfileName(profile_key) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
323 return self.startSession(password, profile) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
324 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
325 def startSession(self, password, profile): |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
326 """"Iniatialise session for a profile |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
327 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
328 @param password(unicode): profile session password |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
329 or empty string is no password is set |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
330 @param profile: %(doc_profile)s |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
331 """ |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
332 def createSession(dummy): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
333 """Called once params are loaded.""" |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
334 self._entities_cache[profile] = {} |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
335 log.info(u"[{}] Profile session started".format(profile)) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
336 return False |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
337 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
338 def backendInitialised(dummy): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
339 def doStartSession(dummy=None): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
340 if self.isSessionStarted(profile): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
341 log.info("Session already started!") |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
342 return True |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
343 try: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
344 # if there is a value at this point in self._entities_cache, |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
345 # it is the loadIndividualParams Deferred, the session is starting |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
346 session_d = self._entities_cache[profile] |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
347 except KeyError: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
348 # else we do request the params |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
349 session_d = self._entities_cache[profile] = self.loadIndividualParams(profile) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
350 session_d.addCallback(createSession) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
351 finally: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
352 return session_d |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
353 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
354 auth_d = self.profileAuthenticate(password, profile) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
355 auth_d.addCallback(doStartSession) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
356 return auth_d |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
357 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
358 return self.host.initialised.addCallback(backendInitialised) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
359 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
360 def _isSessionStarted(self, profile_key): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
361 return self.isSessionStarted(self.getProfileName(profile_key)) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
362 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
363 def isSessionStarted(self, profile): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
364 try: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
365 # XXX: if the value in self._entities_cache is a Deferred, |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
366 # the session is starting but not started yet |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
367 return not isinstance(self._entities_cache[profile], defer.Deferred) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
368 except KeyError: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
369 return False |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
370 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
371 def profileAuthenticate(self, password, profile): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
372 """Authenticate the profile. |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
373 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
374 @param password (unicode): the SàT profile password |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
375 @param profile: %(doc_profile)s |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
376 @return (D): a deferred None in case of success, a failure otherwise. |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
377 """ |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
378 session_data = self.auth_sessions.profileGetUnique(profile) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
379 if not password and session_data: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
380 # XXX: this allows any frontend to connect with the empty password as soon as |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
381 # the profile has been authenticated at least once before. It is OK as long as |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
382 # submitting a form with empty passwords is restricted to local frontends. |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
383 return defer.succeed(None) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
384 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
385 def check_result(result): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
386 if not result: |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
387 log.warning(u'Authentication failure of profile {}'.format(profile)) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
388 raise exceptions.PasswordError(u"The provided profile password doesn't match.") |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
389 if not session_data: # avoid to create two profile sessions when password if specified |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
390 return self.newAuthSession(password, profile) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
391 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
392 d = self.asyncGetParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
393 d.addCallback(lambda sat_cipher: PasswordHasher.verify(password, sat_cipher)) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
394 return d.addCallback(check_result) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
395 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
396 def newAuthSession(self, key, profile): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
397 """Start a new session for the authenticated profile. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
398 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
399 The personal key is loaded encrypted from a PersistentDict before being decrypted. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
400 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
401 @param key: the key to decrypt the personal key |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
402 @param profile: %(doc_profile)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
403 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
404 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
405 def gotPersonalKey(personal_key): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
406 """Create the session for this profile and store the personal key""" |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
407 self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=profile) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
408 log.debug(u'auth session created for profile %s' % profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
409 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
410 d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load() |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
411 d.addCallback(lambda data: BlockCipher.decrypt(key, data[C.MEMORY_CRYPTO_KEY])) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
412 return d.addCallback(gotPersonalKey) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
413 |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
414 def purgeProfileSession(self, profile): |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
415 """Delete cache of data of profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
416 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
417 log.info(_("[%s] Profile session purge" % profile)) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
418 self.params.purgeProfile(profile) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
419 try: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
420 del self._entities_cache[profile] |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
421 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
422 log.error(_(u"Trying to purge roster status cache for a profile not in memory: [%s]") % profile) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
423 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
424 def getProfilesList(self): |
412 | 425 return self.storage.getProfilesList() |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
426 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
427 def getProfileName(self, profile_key, return_profile_keys=False): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
428 """Return name of profile from keyword |
1263 | 429 |
1519
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1474
diff
changeset
|
430 @param profile_key: can be the profile name or a keyword (like @DEFAULT@) |
1263 | 431 @param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller |
1519
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1474
diff
changeset
|
432 @return: requested profile name |
1460
c7fd121a6180
core: getProfileName no raise ProfileUnknownError + minor doc fixes
Goffi <goffi@goffi.org>
parents:
1447
diff
changeset
|
433 @raise exceptions.ProfileUnknownError if profile doesn't exists |
1263 | 434 """ |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
435 return self.params.getProfileName(profile_key, return_profile_keys) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
436 |
1595
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
437 def profileSetDefault(self, profile): |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
438 """Set default profile |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
439 |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
440 @param profile: %(doc_profile)s |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
441 """ |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
442 # we want to be sure that the profile exists |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
443 profile = self.getProfileName(profile) |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
444 |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
445 self.memory_data['Profile_default'] = profile |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
446 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
447 def asyncCreateProfile(self, name, password=''): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
448 """Create a new profile |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
449 @param name: profile name |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
450 @param password: profile password |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
451 @return: Deferred |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
452 """ |
1263 | 453 if not name: |
454 raise ValueError("Empty profile name") | |
455 if name[0] == '@': | |
456 raise ValueError("A profile name can't start with a '@'") | |
1682
61391d863709
plugin XEP-0054: fixed vcard-update callback which was updating avatar when hash was empty, resulting in a really slow start
Goffi <goffi@goffi.org>
parents:
1652
diff
changeset
|
457 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
458 d = self.params.asyncCreateProfile(name) |
1682
61391d863709
plugin XEP-0054: fixed vcard-update callback which was updating avatar when hash was empty, resulting in a really slow start
Goffi <goffi@goffi.org>
parents:
1652
diff
changeset
|
459 |
1652
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
460 def initPersonalKey(dummy): |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
461 # be sure to call this after checking that the profile doesn't exist yet |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
462 personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
463 self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
464 |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
465 d.addCallback(initPersonalKey) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
466 d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
467 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
468 |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
469 def asyncDeleteProfile(self, name, force=False): |
68 | 470 """Delete an existing profile |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
471 @param name: Name of the profile |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
472 @param force: force the deletion even if the profile is connected. |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
473 To be used for direct calls only (not through the bridge). |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
474 @return: a Deferred instance |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
475 """ |
1097
dace0ede919c
memory (memory): delete profile session on profile deletion
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
476 self.auth_sessions.profileDelUnique(name) |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
477 return self.params.asyncDeleteProfile(name, force) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
478 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
479 ## History ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
480 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
481 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile=C.PROF_KEY_NONE): |
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
482 assert profile != C.PROF_KEY_NONE |
669
ffb716804580
core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents:
662
diff
changeset
|
483 if extra is None: |
ffb716804580
core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents:
662
diff
changeset
|
484 extra = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
485 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile) |
0 | 486 |
1224
f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
487 def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, search=None, profile=C.PROF_KEY_NONE): |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
488 """Retrieve messages in history |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
489 @param from_jid (JID): source JID (full, or bare for catchall) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
490 @param to_jid (JID): dest JID (full, or bare for catchall) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
491 @param limit (int): maximum number of messages to get: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
492 - 0 for no message (returns the empty list) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
493 - C.HISTORY_LIMIT_NONE or None for unlimited |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
494 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
495 @param between (bool): confound source and dest (ignore the direction) |
1224
f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
496 @param search (str): pattern to filter the history results |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
497 @param profile (str): %(doc_profile)s |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
498 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
499 """ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
500 assert profile != C.PROF_KEY_NONE |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
501 if limit == C.HISTORY_LIMIT_DEFAULT: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
502 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile)) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
503 elif limit == C.HISTORY_LIMIT_NONE: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
504 limit = None |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
505 if limit == 0: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
506 return defer.succeed([]) |
1224
f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
507 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile) |
0 | 508 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
509 ## Statuses ## |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
510 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
511 def _getPresenceStatuses(self, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
512 ret = self.getPresenceStatuses(profile_key) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
513 return {entity.full():data for entity, data in ret.iteritems()} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
514 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
515 def getPresenceStatuses(self, profile_key): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
516 """Get all the presence statuses of a profile |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
517 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
518 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
519 @return: presence data: key=entity JID, value=presence data for this entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
520 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
521 profile_cache = self._getProfileCache(profile_key) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
522 entities_presence = {} |
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
523 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
524 for entity_jid, entity_data in profile_cache.iteritems(): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
525 for resource, resource_data in entity_data.iteritems(): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
526 full_jid = copy.copy(entity_jid) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
527 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
528 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
529 presence_data = self.getEntityDatum(full_jid, "presence", profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
530 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
531 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
532 entities_presence.setdefault(entity_jid, {})[resource or ''] = presence_data |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
533 |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
534 return entities_presence |
0 | 535 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
536 def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
537 """Change the presence status of an entity |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
538 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
539 @param entity_jid: jid.JID of the entity |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
540 @param show: show status |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
541 @param priority: priority |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
542 @param statuses: dictionary of statuses |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
543 @param profile_key: %(doc_profile_key)s |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
544 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
545 presence_data = PresenceTuple(show, priority, statuses) |
1315
be3a301540c0
core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
Goffi <goffi@goffi.org>
parents:
1314
diff
changeset
|
546 self.updateEntityData(entity_jid, "presence", presence_data, profile_key=profile_key) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
547 if entity_jid.resource and show != C.PRESENCE_UNAVAILABLE: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
548 # If a resource is available, bare jid should not have presence information |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
549 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
550 self.delEntityDatum(entity_jid.userhostJID(), "presence", profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
551 except (KeyError, exceptions.UnknownEntityError): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
552 pass |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
553 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
554 ## Resources ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
555 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
556 def _getAllResource(self, jid_s, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
557 jid_ = jid.JID(jid_s) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
558 return self.getAllResources(jid_, profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
559 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
560 def getAllResources(self, entity_jid, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
561 """Return all resource from jid for which we have had data in this session |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
562 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
563 @param entity_jid: bare jid of the entit |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
564 @param profile_key: %(doc_profile_key)s |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
565 return (list[unicode]): list of resources |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
566 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
567 @raise exceptions.UnknownEntityError: if entity is not in cache |
1689
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
568 @raise ValueError: entity_jid has a resource |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
569 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
570 if entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
571 raise ValueError("getAllResources must be used with a bare jid (got {})".format(entity_jid)) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
572 profile_cache = self._getProfileCache(profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
573 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
574 entity_data = profile_cache[entity_jid.userhostJID()] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
575 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
576 raise exceptions.UnknownEntityError(u"Entity {} not in cache".format(entity_jid)) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
577 resources= set(entity_data.keys()) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
578 resources.discard(None) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
579 return resources |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
580 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
581 def getAvailableResources(self, entity_jid, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
582 """Return available resource for entity_jid |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
583 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
584 This method differs from getAllResources by returning only available resources |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
585 @param entity_jid: bare jid of the entit |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
586 @param profile_key: %(doc_profile_key)s |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
587 return (list[unicode]): list of available resources |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
588 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
589 @raise exceptions.UnknownEntityError: if entity is not in cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
590 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
591 available = [] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
592 for resource in self.getAllResources(entity_jid, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
593 full_jid = copy.copy(entity_jid) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
594 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
595 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
596 presence_data = self.getEntityDatum(full_jid, "presence", profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
597 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
598 log.debug(u"Can't get presence data for {}".format(full_jid)) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
599 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
600 if presence_data.show != C.PRESENCE_UNAVAILABLE: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
601 available.append(resource) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
602 return available |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
603 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
604 def _getMainResource(self, jid_s, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
605 jid_ = jid.JID(jid_s) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
606 return self.getMainResource(jid_, profile_key) or "" |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
607 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
608 def getMainResource(self, entity_jid, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
609 """Return the main resource used by an entity |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
610 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
611 @param entity_jid: bare entity jid |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
612 @param profile_key: %(doc_profile_key)s |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
613 @return (unicode): main resource or None |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
614 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
615 if entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
616 raise ValueError("getMainResource must be used with a bare jid (got {})".format(entity_jid)) |
1392
c7082457d03f
memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents:
1375
diff
changeset
|
617 try: |
c7082457d03f
memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents:
1375
diff
changeset
|
618 if self.host.plugins["XEP-0045"].isRoom(entity_jid, profile_key): |
c7082457d03f
memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents:
1375
diff
changeset
|
619 return None # MUC rooms have no main resource |
c7082457d03f
memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents:
1375
diff
changeset
|
620 except KeyError: # plugin not found |
c7082457d03f
memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents:
1375
diff
changeset
|
621 pass |
1689
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
622 try: |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
623 resources = self.getAllResources(entity_jid, profile_key) |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
624 except exceptions.UnknownEntityError: |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
625 log.warning(u"Entity is not in cache, we can't find any resource") |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
626 return None |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
627 priority_resources = [] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
628 for resource in resources: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
629 full_jid = copy.copy(entity_jid) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
630 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
631 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
632 presence_data = self.getEntityDatum(full_jid, "presence", profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
633 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
634 log.debug(u"No presence information for {}".format(full_jid)) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
635 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
636 priority_resources.append((resource, presence_data.priority)) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
637 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
638 return max(priority_resources, key=lambda res_tuple: res_tuple[1])[0] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
639 except ValueError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
640 log.warning(u"No resource found at all for {}".format(entity_jid)) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
641 return None |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
642 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
643 ## Entities data ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
644 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
645 def _getProfileCache(self, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
646 """Check profile validity and return its cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
647 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
648 @param profile: %(doc_profile_key)_s |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
649 @return (dict): profile cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
650 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
651 @raise exceptions.ProfileUnknownError: if profile doesn't exist |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
652 @raise exceptions.ProfileNotInCacheError: if there is no cache for this profile |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
653 """ |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
654 profile = self.getProfileName(profile_key) |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
655 if not profile: |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
656 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
657 try: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
658 profile_cache = self._entities_cache[profile] |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
659 except KeyError: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
660 raise exceptions.ProfileNotInCacheError |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
661 return profile_cache |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
662 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
663 def setSignalOnUpdate(self, key, signal=True): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
664 """Set a signal flag on the key |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
665 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
666 When the key will be updated, a signal will be sent to frontends |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
667 @param key: key to signal |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
668 @param signal(boolean): if True, do the signal |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
669 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
670 if signal: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
671 self._key_signals.add(key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
672 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
673 self._key_signals.discard(key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
674 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
675 def getAllEntitiesIter(self, with_bare=False, profile_key=C.PROF_KEY_NONE): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
676 """Return an iterator of full jids of all entities in cache |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
677 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
678 @param with_bare: if True, include bare jids |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
679 @param profile_key: %(doc_profile_key)s |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
680 @return (list[unicode]): list of jids |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
681 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
682 profile_cache = self._getProfileCache(profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
683 # we construct a list of all known full jids (bare jid of entities x resources) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
684 for bare_jid, entity_data in profile_cache.iteritems(): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
685 for resource in entity_data.iterkeys(): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
686 if resource is None: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
687 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
688 full_jid = copy.copy(bare_jid) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
689 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
690 yield full_jid |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
691 |
1315
be3a301540c0
core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
Goffi <goffi@goffi.org>
parents:
1314
diff
changeset
|
692 def updateEntityData(self, entity_jid, key, value, silent=False, profile_key=C.PROF_KEY_NONE): |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
693 """Set a misc data for an entity |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
694 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
695 If key was registered with setSignalOnUpdate, a signal will be sent to frontends |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
696 @param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of all entities, |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
697 C.ENTITY_ALL for all entities (all resources + bare jids) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
698 @param key: key to set (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
699 @param value: value for this key (eg: "chatroom") |
1682
61391d863709
plugin XEP-0054: fixed vcard-update callback which was updating avatar when hash was empty, resulting in a really slow start
Goffi <goffi@goffi.org>
parents:
1652
diff
changeset
|
700 @param silent(bool): if True, doesn't send signal to frontend, even if there is a signal flag (see setSignalOnUpdate) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
701 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
702 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
703 profile_cache = self._getProfileCache(profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
704 if entity_jid in (C.ENTITY_ALL_RESOURCES, C.ENTITY_ALL): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
705 entities = self.getAllEntitiesIter(entity_jid==C.ENTITY_ALL, profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
706 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
707 entities = (entity_jid,) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
708 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
709 for jid_ in entities: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
710 entity_data = profile_cache.setdefault(jid_.userhostJID(),{}).setdefault(jid_.resource, {}) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
711 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
712 entity_data[key] = value |
1315
be3a301540c0
core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
Goffi <goffi@goffi.org>
parents:
1314
diff
changeset
|
713 if key in self._key_signals and not silent: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
714 if not isinstance(value, basestring): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
715 log.error(u"Setting a non string value ({}) for a key ({}) which has a signal flag".format(value, key)) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
716 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
717 self.host.bridge.entityDataUpdated(jid_.full(), key, value, self.getProfileName(profile_key)) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
718 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
719 def delEntityDatum(self, entity_jid, key, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
720 """Delete a data for an entity |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
721 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
722 @param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of all entities, |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
723 C.ENTITY_ALL for all entities (all resources + bare jids) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
724 @param key: key to delete (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
725 @param profile_key: %(doc_profile_key)s |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
726 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
727 @raise exceptions.UnknownEntityError: if entity is not in cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
728 @raise KeyError: key is not in cache |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
729 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
730 profile_cache = self._getProfileCache(profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
731 if entity_jid in (C.ENTITY_ALL_RESOURCES, C.ENTITY_ALL): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
732 entities = self.getAllEntitiesIter(entity_jid==C.ENTITY_ALL, profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
733 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
734 entities = (entity_jid,) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
735 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
736 for jid_ in entities: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
737 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
738 entity_data = profile_cache[jid_.userhostJID()][jid_.resource] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
739 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
740 raise exceptions.UnknownEntityError(u"Entity {} not in cache".format(jid_)) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
741 try: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
742 del entity_data[key] |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
743 except KeyError as e: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
744 if entity_jid in (C.ENTITY_ALL_RESOURCES, C.ENTITY_ALL): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
745 continue # we ignore KeyError when deleting keys from several entities |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
746 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
747 raise e |
399 | 748 |
1314
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
749 def _getEntitiesData(self, entities_jids, keys_list, profile_key): |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
750 ret = self.getEntitiesData([jid.JID(jid_) for jid_ in entities_jids], keys_list, profile_key) |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
751 return {jid_.full(): data for jid_, data in ret.iteritems()} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
752 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
753 def getEntitiesData(self, entities_jids, keys_list=None, profile_key=C.PROF_KEY_NONE): |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
754 """Get a list of cached values for several entities at once |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
755 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
756 @param entities_jids: jids of the entities, or empty list for all entities in cache |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
757 @param keys_list (iterable,None): list of keys to get, None for everything |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
758 @param profile_key: %(doc_profile_key)s |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
759 @return: dict withs values for each key in keys_list. |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
760 if there is no value of a given key, resulting dict will |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
761 have nothing with that key nether |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
762 if an entity doesn't exist in cache, it will not appear |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
763 in resulting dict |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
764 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
765 @raise exceptions.UnknownEntityError: if entity is not in cache |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
766 """ |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
767 def fillEntityData(entity_cache_data): |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
768 entity_data = {} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
769 if keys_list is None: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
770 entity_data = entity_cache_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
771 else: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
772 for key in keys_list: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
773 try: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
774 entity_data[key] = entity_cache_data[key] |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
775 except KeyError: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
776 continue |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
777 return entity_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
778 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
779 profile_cache = self._getProfileCache(profile_key) |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
780 ret_data = {} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
781 if entities_jids: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
782 for entity in entities_jids: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
783 try: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
784 entity_cache_data = profile_cache[entity.userhostJID()][entity.resource] |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
785 except KeyError: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
786 continue |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
787 ret_data[entity.full()] = fillEntityData(entity_cache_data, keys_list) |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
788 else: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
789 for bare_jid, data in profile_cache.iteritems(): |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
790 for resource, entity_cache_data in data.iteritems(): |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
791 full_jid = copy.copy(bare_jid) |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
792 full_jid.resource = resource |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
793 ret_data[full_jid] = fillEntityData(entity_cache_data) |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
794 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
795 return ret_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
796 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
797 def getEntityData(self, entity_jid, keys_list=None, profile_key=C.PROF_KEY_NONE): |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
798 """Get a list of cached values for entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
799 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
800 @param entity_jid: JID of the entity |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
801 @param keys_list (iterable,None): list of keys to get, None for everything |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
802 @param profile_key: %(doc_profile_key)s |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
803 @return: dict withs values for each key in keys_list. |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
494
diff
changeset
|
804 if there is no value of a given key, resulting dict will |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
805 have nothing with that key nether |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
806 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
807 @raise exceptions.UnknownEntityError: if entity is not in cache |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
808 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
809 profile_cache = self._getProfileCache(profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
810 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
811 entity_data = profile_cache[entity_jid.userhostJID()][entity_jid.resource] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
812 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
813 raise exceptions.UnknownEntityError(u"Entity {} not in cache (was requesting {})".format(entity_jid, keys_list)) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
814 if keys_list is None: |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
815 return entity_data |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
816 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
817 return {key: entity_data[key] for key in keys_list if key in entity_data} |
47 | 818 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
819 def getEntityDatum(self, entity_jid, key, profile_key): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
820 """Get a datum from entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
821 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
822 @param entity_jid: JID of the entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
823 @param keys: key to get |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
824 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
825 @return: requested value |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
826 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
827 @raise exceptions.UnknownEntityError: if entity is not in cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
828 @raise KeyError: if there is no value for this key and this entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
829 """ |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
830 return self.getEntityData(entity_jid, (key,), profile_key)[key] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
831 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
832 def delEntityCache(self, entity_jid, delete_all_resources=True, profile_key=C.PROF_KEY_NONE): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
833 """Remove all cached data for entity |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
834 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
835 @param entity_jid: JID of the entity to delete |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
836 @param delete_all_resources: if True also delete all known resources from cache (a bare jid must be given in this case) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
837 @param profile_key: %(doc_profile_key)s |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
838 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
839 @raise exceptions.UnknownEntityError: if entity is not in cache |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
840 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
841 profile_cache = self._getProfileCache(profile_key) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
842 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
843 if delete_all_resources: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
844 if entity_jid.resource: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
845 raise ValueError(_("Need a bare jid to delete all resources")) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
846 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
847 del profile_cache[entity_jid] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
848 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
849 raise exceptions.UnknownEntityError(u"Entity {} not in cache".format(entity_jid)) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
850 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
851 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
852 del profile_cache[entity_jid.userhostJID()][entity_jid.resource] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
853 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
854 raise exceptions.UnknownEntityError(u"Entity {} not in cache".format(entity_jid)) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
855 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
856 ## Encryption ## |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
857 |
1090
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
858 def encryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
859 """Encrypt a value for the given profile. The personal key must be loaded |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
860 already in the profile session, that should be the case if the profile is |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
861 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
862 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
863 @param value (str): the value to encrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
864 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
865 @return: the deferred encrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
866 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
867 try: |
1247
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
868 personal_key = self.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
1090
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
869 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
870 raise exceptions.InternalError(_('Trying to encrypt a value for %s while the personal key is undefined!') % profile) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
871 return BlockCipher.encrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
872 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
873 def decryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
874 """Decrypt a value for the given profile. The personal key must be loaded |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
875 already in the profile session, that should be the case if the profile is |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
876 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
877 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
878 @param value (str): the value to decrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
879 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
880 @return: the deferred decrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
881 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
882 try: |
1247
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
883 personal_key = self.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
1090
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
884 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
885 raise exceptions.InternalError(_('Trying to decrypt a value for %s while the personal key is undefined!') % profile) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
886 return BlockCipher.decrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
887 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
888 def encryptPersonalData(self, data_key, data_value, crypto_key, profile): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
889 """Re-encrypt a personal data (saved to a PersistentDict). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
890 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
891 @param data_key: key for the individual PersistentDict instance |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
892 @param data_value: the value to be encrypted |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
893 @param crypto_key: the key to encrypt the value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
894 @param profile: %(profile_doc)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
895 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
896 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
897 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
898 def gotIndMemory(data): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
899 d = BlockCipher.encrypt(crypto_key, data_value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
900 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
901 def cb(cipher): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
902 data[data_key] = cipher |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
903 return data.force(data_key) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
904 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
905 return d.addCallback(cb) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
906 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
907 def done(dummy): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
908 log.debug(_(u'Personal data (%(ns)s, %(key)s) has been successfuly encrypted') % |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
909 {'ns': C.MEMORY_CRYPTO_NAMESPACE, 'key': data_key}) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
910 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
911 d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load() |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
912 return d.addCallback(gotIndMemory).addCallback(done) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
913 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
914 ## Subscription requests ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
915 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
916 def addWaitingSub(self, type_, entity_jid, profile_key): |
47 | 917 """Called when a subcription request is received""" |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
918 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
919 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
920 if profile not in self.subscriptions: |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
921 self.subscriptions[profile] = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
922 self.subscriptions[profile][entity_jid] = type_ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
923 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
924 def delWaitingSub(self, entity_jid, profile_key): |
47 | 925 """Called when a subcription request is finished""" |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
926 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
927 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
928 if profile in self.subscriptions and entity_jid in self.subscriptions[profile]: |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
929 del self.subscriptions[profile][entity_jid] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
930 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
327
diff
changeset
|
931 def getWaitingSub(self, profile_key): |
47 | 932 """Called to get a list of currently waiting subscription requests""" |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
933 profile = self.getProfileName(profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
934 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
935 log.error(_('Asking waiting subscriptions for a non-existant profile')) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
936 return {} |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
937 if profile not in self.subscriptions: |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
938 return {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
939 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
940 return self.subscriptions[profile] |
0 | 941 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
942 ## Parameters ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
943 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
944 def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
945 return self.params.getStringParamA(name, category, attr, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
946 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
947 def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
948 return self.params.getParamA(name, category, attr, profile_key=profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
949 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
950 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
951 return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
952 |
1587
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
953 def asyncGetParamsValuesFromCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
954 return self.params.asyncGetParamsValuesFromCategory(category, security_limit, profile_key) |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
955 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
956 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
957 return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
958 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
959 def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
960 return self.params.getParamsUI(security_limit, app, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
961 |
0 | 962 def getParamsCategories(self): |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
963 return self.params.getParamsCategories() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
964 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
965 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
639
diff
changeset
|
966 return self.params.setParam(name, value, category, security_limit, profile_key) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
967 |
662
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
968 def updateParams(self, xml): |
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
969 return self.params.updateParams(xml) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
970 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
971 def paramsRegisterApp(self, xml, security_limit=C.NO_SECURITY_LIMIT, app=''): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
972 return self.params.paramsRegisterApp(xml, security_limit, app) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
973 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
974 def setDefault(self, name, category, callback, errback=None): |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
975 return self.params.setDefault(name, category, callback, errback) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
976 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
977 ## Misc ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
978 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
979 def isEntityAvailable(self, entity_jid, profile_key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
980 """Tell from the presence information if the given entity is available. |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
981 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
982 @param entity_jid (JID): the entity to check (if bare jid is used, all resources are tested) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
983 @param profile_key: %(doc_profile_key)s |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
984 @return (bool): True if entity is available |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
985 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
986 if not entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
987 return bool(self.getAvailableResources) # is any resource is available, entity is available |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
988 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
989 presence_data = self.getEntityDatum(entity_jid, "presence", profile_key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
990 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
991 log.debug(u"No presence information for {}".format(entity_jid)) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
992 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
993 return presence_data.show != C.PRESENCE_UNAVAILABLE |