Mercurial > libervia-backend
annotate src/memory/memory.py @ 1695:5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Nov 2015 16:52:14 +0100 |
parents | 3c608d660f0b |
children | 292f9c2712f2 |
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): |
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
|
322 """"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
|
323 |
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 @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
|
325 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
|
326 @param profile: %(doc_profile)s |
1694
3c608d660f0b
core (memory): profile is checked in startSession (an error is raised if it doesn't exist)
Goffi <goffi@goffi.org>
parents:
1693
diff
changeset
|
327 @raise exceptions.ProfileUnknownError if profile doesn't exists |
3c608d660f0b
core (memory): profile is checked in startSession (an error is raised if it doesn't exist)
Goffi <goffi@goffi.org>
parents:
1693
diff
changeset
|
328 @raise exceptions.PasswordError: the password does not match |
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
|
329 """ |
1694
3c608d660f0b
core (memory): profile is checked in startSession (an error is raised if it doesn't exist)
Goffi <goffi@goffi.org>
parents:
1693
diff
changeset
|
330 profile = self.getProfileName(profile) |
3c608d660f0b
core (memory): profile is checked in startSession (an error is raised if it doesn't exist)
Goffi <goffi@goffi.org>
parents:
1693
diff
changeset
|
331 |
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
|
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 |
1693
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
360 def stopSession(self, profile): |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
361 """Delete a profile session |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
362 |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
363 @param profile: %(doc_profile)s |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
364 """ |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
365 if self.host.isConnected(profile): |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
366 log.debug(u"Disconnecting profile because of session stop") |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
367 self.host.disconnect(profile) |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
368 self.auth_sessions.profileDelUnique(profile) |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
369 try: |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
370 self._entities_cache[profile] |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
371 except KeyError: |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
372 log.warning(u"Profile was not in cache") |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
373 |
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
|
374 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
|
375 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
|
376 |
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 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
|
378 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
|
379 # 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
|
380 # 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
|
381 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
|
382 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
|
383 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
|
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 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
|
386 """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
|
387 |
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 @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
|
389 @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
|
390 @return (D): a deferred None in case of success, a failure otherwise. |
1693
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
391 @raise exceptions.PasswordError: the password does not match |
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
|
392 """ |
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 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
|
394 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
|
395 # 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
|
396 # 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
|
397 # 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
|
398 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
|
399 |
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
|
400 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
|
401 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
|
402 log.warning(u'Authentication failure of profile {}'.format(profile)) |
1693
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
403 raise failure.Failure(exceptions.PasswordError(u"The provided profile password doesn't match.")) |
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
|
404 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
|
405 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
|
406 |
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
|
407 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
|
408 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
|
409 return d.addCallback(check_result) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
410 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
411 def newAuthSession(self, key, profile): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
412 """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
|
413 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
414 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
|
415 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
416 @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
|
417 @param profile: %(doc_profile)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
418 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
419 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
420 def gotPersonalKey(personal_key): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
421 """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
|
422 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
|
423 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
|
424 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
425 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
|
426 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
|
427 return d.addCallback(gotPersonalKey) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
428 |
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
|
429 def purgeProfileSession(self, profile): |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
430 """Delete cache of data of profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
431 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
432 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
|
433 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
|
434 try: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
435 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
|
436 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
|
437 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
|
438 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
439 def getProfilesList(self): |
412 | 440 return self.storage.getProfilesList() |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
441 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
442 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
|
443 """Return name of profile from keyword |
1263 | 444 |
1519
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1474
diff
changeset
|
445 @param profile_key: can be the profile name or a keyword (like @DEFAULT@) |
1263 | 446 @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
|
447 @return: requested profile name |
1460
c7fd121a6180
core: getProfileName no raise ProfileUnknownError + minor doc fixes
Goffi <goffi@goffi.org>
parents:
1447
diff
changeset
|
448 @raise exceptions.ProfileUnknownError if profile doesn't exists |
1263 | 449 """ |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
450 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
|
451 |
1595
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
452 def profileSetDefault(self, profile): |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
453 """Set default profile |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
454 |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
455 @param profile: %(doc_profile)s |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
456 """ |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
457 # we want to be sure that the profile exists |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
458 profile = self.getProfileName(profile) |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
459 |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
460 self.memory_data['Profile_default'] = profile |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
461 |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
462 def asyncCreateProfile(self, name, password): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
463 """Create a new profile |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
464 @param name (unicode): profile name |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
465 @param password (unicode): profile password |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
466 Can be empty to disable password |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
467 @return: Deferred |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
468 """ |
1263 | 469 if not name: |
470 raise ValueError("Empty profile name") | |
471 if name[0] == '@': | |
472 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
|
473 |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
474 if name in self._entities_cache: |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
475 raise exceptions.ConflictError(u"A session for this profile exists") |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
476 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
477 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
|
478 |
1652
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
479 def initPersonalKey(dummy): |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
480 # 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
|
481 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
|
482 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
|
483 |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
484 def startFakeSession(dummy): |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
485 # avoid ProfileNotConnected exception in setParam |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
486 self._entities_cache[name] = None |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
487 self.params.loadIndParams(name) |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
488 |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
489 def stopFakeSession(dummy): |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
490 del self._entities_cache[name] |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
491 self.params.purgeProfile(name) |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
492 |
1652
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
493 d.addCallback(initPersonalKey) |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
494 d.addCallback(startFakeSession) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
495 d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
496 d.addCallback(stopFakeSession) |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
497 d.addCallback(lambda dummy: self.auth_sessions.profileDelUnique(name)) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
498 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
499 |
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
|
500 def asyncDeleteProfile(self, name, force=False): |
68 | 501 """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
|
502 @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
|
503 @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
|
504 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
|
505 @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
|
506 """ |
1097
dace0ede919c
memory (memory): delete profile session on profile deletion
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
507 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
|
508 return self.params.asyncDeleteProfile(name, force) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
509 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
510 ## History ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
511 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
512 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
|
513 assert profile != C.PROF_KEY_NONE |
669
ffb716804580
core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents:
662
diff
changeset
|
514 if extra is None: |
ffb716804580
core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents:
662
diff
changeset
|
515 extra = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
516 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile) |
0 | 517 |
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
|
518 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
|
519 """Retrieve messages in history |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
520 @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
|
521 @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
|
522 @param limit (int): maximum number of messages to get: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
523 - 0 for no message (returns the empty list) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
524 - C.HISTORY_LIMIT_NONE or None for unlimited |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
525 - 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
|
526 @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
|
527 @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
|
528 @param profile (str): %(doc_profile)s |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
529 @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
|
530 """ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
531 assert profile != C.PROF_KEY_NONE |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
532 if limit == C.HISTORY_LIMIT_DEFAULT: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
533 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
|
534 elif limit == C.HISTORY_LIMIT_NONE: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
535 limit = None |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
536 if limit == 0: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
537 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
|
538 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile) |
0 | 539 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
540 ## Statuses ## |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
541 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
542 def _getPresenceStatuses(self, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
543 ret = self.getPresenceStatuses(profile_key) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
544 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
|
545 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
546 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
|
547 """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
|
548 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
549 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
550 @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
|
551 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
552 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
|
553 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
|
554 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
559 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
560 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
|
561 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
562 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
563 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
|
564 |
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
|
565 return entities_presence |
0 | 566 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
567 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
|
568 """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
|
569 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
570 @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
|
571 @param show: show status |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
572 @param priority: priority |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
573 @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
|
574 @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
|
575 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
576 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
|
577 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
|
578 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
|
579 # 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
|
580 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
581 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
|
582 except (KeyError, exceptions.UnknownEntityError): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
583 pass |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
584 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
585 ## Resources ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
586 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
587 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
|
588 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
|
589 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
|
590 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
591 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
|
592 """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
|
593 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
594 @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
|
595 @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
|
596 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
|
597 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
598 @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
|
599 @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
|
600 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
601 if entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
602 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
|
603 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
|
604 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
605 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
|
606 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
607 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
|
608 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
|
609 resources.discard(None) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
610 return resources |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
611 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
612 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
|
613 """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
|
614 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
615 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
|
616 @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
|
617 @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
|
618 return (list[unicode]): list of available resources |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
619 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
620 @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
|
621 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
622 available = [] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
623 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
|
624 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
|
625 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
626 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
627 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
|
628 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
|
629 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
|
630 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
631 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
|
632 available.append(resource) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
633 return available |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
634 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
639 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
|
640 """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
|
641 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
642 @param entity_jid: bare entity jid |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
643 @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
|
644 @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
|
645 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
646 if entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 pass |
1689
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
653 try: |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
654 resources = self.getAllResources(entity_jid, profile_key) |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
655 except exceptions.UnknownEntityError: |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
656 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
|
657 return None |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
658 priority_resources = [] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
659 for resource in resources: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
660 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
|
661 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
662 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
663 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
|
664 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
|
665 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
|
666 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
667 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
|
668 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
669 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
|
670 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
|
671 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
|
672 return None |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
673 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
674 ## Entities data ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
675 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
676 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
|
677 """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
|
678 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
679 @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
|
680 @return (dict): profile cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
681 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
682 @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
|
683 @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
|
684 """ |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
685 profile = self.getProfileName(profile_key) |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
686 if not profile: |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
687 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
|
688 try: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
689 profile_cache = self._entities_cache[profile] |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
690 except KeyError: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
691 raise exceptions.ProfileNotInCacheError |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
692 return profile_cache |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
693 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
694 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
|
695 """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
|
696 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
697 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
|
698 @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
|
699 @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
|
700 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
701 if signal: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
702 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
|
703 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
704 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
|
705 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
706 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
|
707 """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
|
708 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
709 @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
|
710 @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
|
711 @return (list[unicode]): list of jids |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
712 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
713 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
|
714 # 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
|
715 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
|
716 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
|
717 if resource is None: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
718 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
719 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
|
720 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
721 yield full_jid |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
722 |
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
|
723 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
|
724 """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
|
725 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
726 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
|
727 @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
|
728 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
|
729 @param key: key to set (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
730 @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
|
731 @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
|
732 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
733 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
734 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
|
735 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
|
736 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
|
737 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
738 entities = (entity_jid,) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
739 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
740 for jid_ in entities: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
741 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
|
742 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 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
|
747 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
748 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
|
749 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
750 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
|
751 """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
|
752 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
753 @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
|
754 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
|
755 @param key: key to delete (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
756 @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
|
757 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
758 @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
|
759 @raise KeyError: key is not in cache |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
760 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
761 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
|
762 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
|
763 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
|
764 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
765 entities = (entity_jid,) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
766 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
767 for jid_ in entities: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
768 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
769 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
|
770 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
771 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
|
772 try: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
773 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
|
774 except KeyError as e: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
775 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
|
776 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
|
777 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
778 raise e |
399 | 779 |
1314
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
780 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
|
781 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
|
782 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
|
783 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
784 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
|
785 """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
|
786 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
787 @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
|
788 @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
|
789 @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
|
790 @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
|
791 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
|
792 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
|
793 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
|
794 in resulting dict |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
795 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
796 @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
|
797 """ |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
798 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
|
799 entity_data = {} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
800 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
|
801 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
|
802 else: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
803 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
|
804 try: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
805 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
|
806 except KeyError: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
807 continue |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
808 return entity_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
809 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
810 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
|
811 ret_data = {} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
812 if entities_jids: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
813 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
|
814 try: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
815 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
|
816 except KeyError: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
817 continue |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
818 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
|
819 else: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
820 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
|
821 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
|
822 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
|
823 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
|
824 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
|
825 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
826 return ret_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
827 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
828 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
|
829 """Get a list of cached values for entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
830 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
831 @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
|
832 @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
|
833 @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
|
834 @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
|
835 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
|
836 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
|
837 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
838 @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
|
839 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
840 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
|
841 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
842 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
|
843 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
844 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
|
845 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
|
846 return entity_data |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
847 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
848 return {key: entity_data[key] for key in keys_list if key in entity_data} |
47 | 849 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
850 def getEntityDatum(self, entity_jid, key, profile_key): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
851 """Get a datum from entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
852 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
853 @param entity_jid: JID of the entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
854 @param keys: key to get |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
855 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
856 @return: requested value |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
857 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
858 @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
|
859 @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
|
860 """ |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
861 return self.getEntityData(entity_jid, (key,), profile_key)[key] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
862 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
863 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
|
864 """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
|
865 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
866 @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
|
867 @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
|
868 @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
|
869 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
870 @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
|
871 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
872 profile_cache = self._getProfileCache(profile_key) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
873 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
874 if delete_all_resources: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
875 if entity_jid.resource: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
876 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
|
877 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
878 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
|
879 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
880 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
|
881 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
882 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
883 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
|
884 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
885 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
|
886 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
887 ## Encryption ## |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
888 |
1090
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
889 def encryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
890 """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
|
891 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
|
892 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
893 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
894 @param value (str): the value to encrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
895 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
896 @return: the deferred encrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
897 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
898 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
|
899 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
|
900 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
901 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
|
902 return BlockCipher.encrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
903 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
904 def decryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
905 """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
|
906 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
|
907 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
908 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
909 @param value (str): the value to decrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
910 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
911 @return: the deferred decrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
912 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
913 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
|
914 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
|
915 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
916 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
|
917 return BlockCipher.decrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
918 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
919 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
|
920 """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
|
921 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
922 @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
|
923 @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
|
924 @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
|
925 @param profile: %(profile_doc)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
926 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
927 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
928 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
929 def gotIndMemory(data): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
930 d = BlockCipher.encrypt(crypto_key, data_value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
931 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
932 def cb(cipher): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
933 data[data_key] = cipher |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
934 return data.force(data_key) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
935 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
936 return d.addCallback(cb) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
937 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
938 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
|
939 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
|
940 {'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
|
941 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
942 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
|
943 return d.addCallback(gotIndMemory).addCallback(done) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
944 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
945 ## Subscription requests ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
946 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
947 def addWaitingSub(self, type_, entity_jid, profile_key): |
47 | 948 """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
|
949 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
950 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
951 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
|
952 self.subscriptions[profile] = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
953 self.subscriptions[profile][entity_jid] = type_ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
954 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
955 def delWaitingSub(self, entity_jid, profile_key): |
47 | 956 """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
|
957 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
958 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
959 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
|
960 del self.subscriptions[profile][entity_jid] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
961 |
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
|
962 def getWaitingSub(self, profile_key): |
47 | 963 """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
|
964 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
|
965 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
966 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
|
967 return {} |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
968 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
|
969 return {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
970 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
971 return self.subscriptions[profile] |
0 | 972 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
973 ## Parameters ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
974 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
975 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
|
976 return self.params.getStringParamA(name, category, attr, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
977 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
978 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
|
979 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
|
980 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
981 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
|
982 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
|
983 |
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
|
984 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
|
985 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
|
986 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
987 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
|
988 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
|
989 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
990 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
|
991 return self.params.getParamsUI(security_limit, app, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
992 |
0 | 993 def getParamsCategories(self): |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
994 return self.params.getParamsCategories() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
995 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
996 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
|
997 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
|
998 |
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
|
999 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
|
1000 return self.params.updateParams(xml) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1001 |
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
|
1002 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
|
1003 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
|
1004 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
1005 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
|
1006 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
|
1007 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1008 ## Misc ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1009 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1010 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
|
1011 """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
|
1012 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1013 @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
|
1014 @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
|
1015 @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
|
1016 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1017 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
|
1018 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
|
1019 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1020 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
|
1021 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
|
1022 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
|
1023 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1024 return presence_data.show != C.PRESENCE_UNAVAILABLE |