Mercurial > libervia-backend
annotate src/memory/memory.py @ 2520:25e16729413b
plugin XEP-0329: fixed extra key serialisation before sending to bridge
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 14 Mar 2018 08:10:31 +0100 |
parents | e4de2f16a284 |
children | 35d591086974 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1859
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 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 |
2483 | 5 # Copyright (C) 2009-2018 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 |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
42 import shortuuid |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
43 import mimetypes |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
44 import time |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
45 |
679
59c9a7ff903d
wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
677
diff
changeset
|
46 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
47 PresenceTuple = namedtuple("PresenceTuple", ('show', 'priority', 'statuses')) |
1447 | 48 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
|
49 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
50 class Sessions(object): |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
51 """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
|
52 DEFAULT_TIMEOUT = 600 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
53 |
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
|
54 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
|
55 """ |
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
|
56 @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
|
57 @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
|
58 """ |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
59 self._sessions = dict() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
60 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
|
61 self.resettable_timeout = resettable_timeout |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
62 |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
63 def newSession(self, session_data=None, session_id=None, profile=None): |
1447 | 64 """Create a new session |
65 | |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
66 @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
|
67 @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
|
68 @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
|
69 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
|
70 @return: session_id, session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
71 """ |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
72 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
|
73 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
|
74 elif session_id in self._sessions: |
1447 | 75 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
|
76 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
|
77 if session_data is None: |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
78 session_data = {} |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
79 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
|
80 return session_id, session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
81 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
82 def _purgeSession(self, session_id): |
1447 | 83 try: |
84 timer, session_data, profile = self._sessions[session_id] | |
85 except ValueError: | |
86 timer, session_data = self._sessions[session_id] | |
87 profile = None | |
88 try: | |
89 timer.cancel() | |
90 except error.AlreadyCalled: | |
91 # if the session is time-outed, the timer has been called | |
92 pass | |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
93 del self._sessions[session_id] |
1447 | 94 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
|
95 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
96 def __len__(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
97 return len(self._sessions) |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
98 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
99 def __contains__(self, session_id): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
100 return session_id in self._sessions |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
101 |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
102 def profileGet(self, session_id, profile): |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
103 try: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
104 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
|
105 except ValueError: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
106 raise exceptions.InternalError("You need to use __getitem__ when profile is not set") |
1447 | 107 except KeyError: |
108 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
|
109 if profile_set != profile: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
110 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
|
111 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
|
112 timer.reset(self.timeout) |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
113 return session_data |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
114 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
115 def __getitem__(self, session_id): |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
116 try: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
117 timer, session_data = self._sessions[session_id] |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
118 except ValueError: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
119 raise exceptions.InternalError("You need to use profileGet instead of __getitem__ when profile is set") |
1447 | 120 except KeyError: |
121 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
|
122 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
|
123 timer.reset(self.timeout) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
124 return session_data |
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 __setitem__(self, key, value): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
127 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
|
128 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
129 def __delitem__(self, session_id): |
1474
c2a498dce4b4
core (memory): fixed a double timer.cancel in Sessions
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
130 """ delete the session data """ |
1447 | 131 self._purgeSession(session_id) |
756
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 keys(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
134 return self._sessions.keys() |
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 def iterkeys(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
137 return self._sessions.iterkeys() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
138 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
139 |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
140 class ProfileSessions(Sessions): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
141 """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
|
142 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
|
143 """ |
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 def _profileGetAllIds(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
146 """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
|
147 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
148 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
149 @return: a list containing the sessions ids |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
150 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
151 ret = [] |
1447 | 152 for session_id in self._sessions.iterkeys(): |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
153 try: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
154 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
|
155 except ValueError: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
156 continue |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
157 if profile == profile_set: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
158 ret.append(session_id) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
159 return ret |
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 def profileGetUnique(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
162 """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
|
163 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
164 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
165 @return: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
166 - mutable data (default: dict) of the unique session |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
167 - 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
|
168 - 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
|
169 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
170 ids = self._profileGetAllIds(profile) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
171 if len(ids) > 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
172 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
|
173 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
|
174 |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
175 def profileDelUnique(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
176 """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
|
177 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
178 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
179 @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
|
180 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
181 ids = self._profileGetAllIds(profile) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
182 if len(ids) > 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
183 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
|
184 if len(ids) == 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
185 del self._sessions[ids[0]] |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
186 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
187 |
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
|
188 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
|
189 |
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 # 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
|
191 # 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
|
192 # 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
|
193 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
|
194 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
|
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 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
|
197 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
|
198 |
c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
souliane <souliane@mailoo.org>
parents:
1240
diff
changeset
|
199 |
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
|
200 # 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
|
201 # 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
|
202 # '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
|
203 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
|
204 """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
|
205 |
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 @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
|
207 """ |
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 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 |
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
|
225 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
226 class Memory(object): |
1199 | 227 """This class manage all the persistent information""" |
0 | 228 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
229 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
230 log.info(_("Memory manager init")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
231 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
|
232 self.host = host |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
233 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
|
234 # /!\ 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
|
235 # 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
|
236 # 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
|
237 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
|
238 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
|
239 self.auth_sessions = PasswordSessions() # remember the authenticated profiles |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
240 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
|
241 fixLocalDir(False) # XXX: tmp update code, will be removed in the future |
1859
ac2ac7fe8a9b
core (memory, config): moved parseMainConf to tools/config so it can be used by frontends too
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
242 self.config = tools_config.parseMainConf() |
923 | 243 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
|
244 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
|
245 PersistentDict.storage = self.storage |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
246 self.params = Params(host, self.storage) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
247 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
|
248 self.params.load_default_params() |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 d.addCallback(lambda ignore: self.disco.load()) |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
253 d.chainDeferred(self.initialized) |
0 | 254 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
255 ## Configuration ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
256 |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
257 def getConfig(self, section, name, default=None): |
364 | 258 """Get the main configuration option |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
259 |
364 | 260 @param section: section of the config file (None or '' for DEFAULT) |
261 @param name: name of the option | |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
262 @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
|
263 @return: str, list or dict |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
264 """ |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
265 return tools_config.getConfig(self.config, section, name, default) |
364 | 266 |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
267 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
|
268 """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
|
269 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
270 @param filename (str): input file |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
271 @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
|
272 """ |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
273 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
|
274 return False |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
275 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
|
276 if os.path.exists(filename): |
0 | 277 try: |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 return False |
0 | 284 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
285 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
|
286 """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
|
287 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
288 @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
|
289 @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
|
290 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
291 if not filename: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
292 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
293 #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
|
294 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
|
295 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
296 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
|
297 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
|
298 return True |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
299 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
|
300 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
|
301 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
302 |
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
|
303 def load(self): |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
304 """Load parameters and all memory things from db""" |
412 | 305 #parameters data |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
306 return self.params.loadGenParams() |
412 | 307 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
308 def loadIndividualParams(self, profile): |
412 | 309 """Load individual parameters for a profile |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
310 @param profile: %(doc_profile)s""" |
412 | 311 return self.params.loadIndParams(profile) |
312 | |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
313 ## Profiles/Sessions management ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
314 |
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
|
315 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
|
316 """"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
|
317 |
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
|
318 @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
|
319 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
|
320 @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
|
321 @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
|
322 @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
|
323 """ |
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
|
324 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
|
325 |
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
|
326 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
|
327 """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
|
328 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
|
329 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
|
330 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
|
331 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
332 def 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 # 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
|
339 # 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
|
340 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
|
341 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
|
342 # 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 |
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 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
|
349 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
|
350 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
|
351 |
1723
5632c5350296
core: avoid initialisation blocking when a long callback is added to backend.initialised (could prevent sessions starting)
Goffi <goffi@goffi.org>
parents:
1704
diff
changeset
|
352 if self.host.initialised.called: |
5632c5350296
core: avoid initialisation blocking when a long callback is added to backend.initialised (could prevent sessions starting)
Goffi <goffi@goffi.org>
parents:
1704
diff
changeset
|
353 return defer.succeed(None).addCallback(backendInitialised) |
5632c5350296
core: avoid initialisation blocking when a long callback is added to backend.initialised (could prevent sessions starting)
Goffi <goffi@goffi.org>
parents:
1704
diff
changeset
|
354 else: |
5632c5350296
core: avoid initialisation blocking when a long callback is added to backend.initialised (could prevent sessions starting)
Goffi <goffi@goffi.org>
parents:
1704
diff
changeset
|
355 return self.host.initialised.addCallback(backendInitialised) |
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
|
356 |
1693
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
357 def stopSession(self, profile): |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
358 """Delete a profile session |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
359 |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
360 @param profile: %(doc_profile)s |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
361 """ |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
362 if self.host.isConnected(profile): |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
363 log.debug(u"Disconnecting profile because of session stop") |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
364 self.host.disconnect(profile) |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
365 self.auth_sessions.profileDelUnique(profile) |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
366 try: |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
367 self._entities_cache[profile] |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
368 except KeyError: |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
369 log.warning(u"Profile was not in cache") |
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
370 |
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
|
371 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
|
372 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
|
373 |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
374 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
|
375 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
|
376 # 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
|
377 # 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
|
378 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
|
379 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
|
380 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
|
381 |
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 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
|
383 """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
|
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 @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
|
386 @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
|
387 @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
|
388 @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
|
389 """ |
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 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
|
391 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
|
392 # 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
|
393 # 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
|
394 # 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
|
395 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
|
396 |
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 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
|
398 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
|
399 log.warning(u'Authentication failure of profile {}'.format(profile)) |
1693
35426d58471c
core (memory): stopSession implementation
Goffi <goffi@goffi.org>
parents:
1689
diff
changeset
|
400 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
|
401 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
|
402 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
|
403 |
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 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
|
405 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
|
406 return d.addCallback(check_result) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
407 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
408 def newAuthSession(self, key, profile): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
409 """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
|
410 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
411 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
|
412 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
413 @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
|
414 @param profile: %(doc_profile)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
415 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
416 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
417 def gotPersonalKey(personal_key): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
418 """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
|
419 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
|
420 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
|
421 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
422 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
|
423 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
|
424 return d.addCallback(gotPersonalKey) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
425 |
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
|
426 def purgeProfileSession(self, profile): |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
427 """Delete cache of data of profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
428 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
429 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
|
430 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
|
431 try: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 |
2146
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
436 def getProfilesList(self, clients=True, components=False): |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
437 """retrieve profiles list |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
438 |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
439 @param clients(bool): if True return clients profiles |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
440 @param components(bool): if True return components profiles |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
441 @return (list[unicode]): selected profiles |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
442 """ |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
443 if not clients and not components: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
444 log.warning(_(u"requesting no profiles at all")) |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
445 return [] |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
446 profiles = self.storage.getProfilesList() |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
447 if clients and components: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
448 return sorted(profiles) |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
449 isComponent = self.storage.profileIsComponent |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
450 if clients: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
451 p_filter = lambda p: not isComponent(p) |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
452 else: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
453 p_filter = lambda p: isComponent(p) |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
454 |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
455 return sorted(p for p in profiles if p_filter(p)) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
456 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
457 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
|
458 """Return name of profile from keyword |
1263 | 459 |
1519
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1474
diff
changeset
|
460 @param profile_key: can be the profile name or a keyword (like @DEFAULT@) |
1263 | 461 @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
|
462 @return: requested profile name |
1460
c7fd121a6180
core: getProfileName no raise ProfileUnknownError + minor doc fixes
Goffi <goffi@goffi.org>
parents:
1447
diff
changeset
|
463 @raise exceptions.ProfileUnknownError if profile doesn't exists |
1263 | 464 """ |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
465 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
|
466 |
1595
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
467 def profileSetDefault(self, profile): |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
468 """Set default profile |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
469 |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
470 @param profile: %(doc_profile)s |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
471 """ |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
472 # we want to be sure that the profile exists |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
473 profile = self.getProfileName(profile) |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
474 |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
475 self.memory_data['Profile_default'] = profile |
a3d0cfa5b7a6
core, bridge: added a profileSetDefault method
Goffi <goffi@goffi.org>
parents:
1591
diff
changeset
|
476 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
477 def createProfile(self, name, password, component=None): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
478 """Create a new profile |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
479 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
480 @param name(unicode): profile name |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
481 @param password(unicode): profile password |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
482 Can be empty to disable password |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
483 @param component(None, unicode): set to entry point if this is a component |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
484 @return: Deferred |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
485 @raise exceptions.NotFound: component is not a known plugin import name |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
486 """ |
1263 | 487 if not name: |
2052
d44efd32bc2f
core: line feed (\n) are now forbidden in profile names
Goffi <goffi@goffi.org>
parents:
2013
diff
changeset
|
488 raise ValueError(u"Empty profile name") |
1263 | 489 if name[0] == '@': |
2052
d44efd32bc2f
core: line feed (\n) are now forbidden in profile names
Goffi <goffi@goffi.org>
parents:
2013
diff
changeset
|
490 raise ValueError(u"A profile name can't start with a '@'") |
d44efd32bc2f
core: line feed (\n) are now forbidden in profile names
Goffi <goffi@goffi.org>
parents:
2013
diff
changeset
|
491 if '\n' in name: |
d44efd32bc2f
core: line feed (\n) are now forbidden in profile names
Goffi <goffi@goffi.org>
parents:
2013
diff
changeset
|
492 raise ValueError(u"A profile name can't contain line feed ('\\n')") |
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
|
493 |
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 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
|
495 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
|
496 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
497 if component: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
498 if not component in self.host.plugins: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
499 raise exceptions.NotFound(_(u"Can't find component {component} entry point".format( |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
500 component = component))) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
501 # FIXME: PLUGIN_INFO is not currently accessible after import, but type shoul be tested here |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
502 # if self.host.plugins[component].PLUGIN_INFO[u"type"] != C.PLUG_TYPE_ENTRY_POINT: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
503 # raise ValueError(_(u"Plugin {component} is not an entry point !".format( |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
504 # component = component))) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
505 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
506 d = self.params.createProfile(name, component) |
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
|
507 |
1652
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
508 def initPersonalKey(dummy): |
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
509 # 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
|
510 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
|
511 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
|
512 |
1695
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
513 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
|
514 # 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
|
515 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
|
516 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
|
517 |
5a93f13c1e76
core (memory): asyncCreateProfile fix: a fake session is created to set general password param
Goffi <goffi@goffi.org>
parents:
1694
diff
changeset
|
518 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
|
519 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
|
520 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
|
521 |
1652
fd7f41d8cbdf
memory: fixes asyncCreateProfile to not overwrite the personal key
souliane <souliane@mailoo.org>
parents:
1595
diff
changeset
|
522 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
|
523 d.addCallback(startFakeSession) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
524 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
|
525 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
|
526 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
|
527 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
528 |
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
|
529 def asyncDeleteProfile(self, name, force=False): |
68 | 530 """Delete an existing profile |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
531 |
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
|
532 @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
|
533 @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
|
534 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
|
535 @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
|
536 """ |
1704
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
537 def cleanMemory(dummy): |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
538 self.auth_sessions.profileDelUnique(name) |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
539 try: |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
540 del self._entities_cache[name] |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
541 except KeyError: |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
542 pass |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
543 d = self.params.asyncDeleteProfile(name, force) |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
544 d.addCallback(cleanMemory) |
292f9c2712f2
core (memory): fixed bad memory cleaning on asyncDeleteProfile
Goffi <goffi@goffi.org>
parents:
1695
diff
changeset
|
545 return d |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
546 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
547 def isComponent(self, profile_name): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
548 """Tell if a profile is a component |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
549 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
550 @param profile_name(unicode): name of the profile |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
551 @return (bool): True if profile is a component |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
552 @raise exceptions.NotFound: profile doesn't exist |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
553 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
554 return self.storage.profileIsComponent(profile_name) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
555 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
556 def getEntryPoint(self, profile_name): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
557 """Get a component entry point |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
558 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
559 @param profile_name(unicode): name of the profile |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
560 @return (bool): True if profile is a component |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
561 @raise exceptions.NotFound: profile doesn't exist |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
562 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
563 return self.storage.getEntryPoint(profile_name) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2052
diff
changeset
|
564 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
565 ## History ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
566 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
567 def addToHistory(self, client, data): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
568 return self.storage.addToHistory(data, client.profile) |
0 | 569 |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
570 def _historyGet(self, from_jid_s, to_jid_s, limit=C.HISTORY_LIMIT_NONE, between=True, filters=None, profile=C.PROF_KEY_NONE): |
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
571 return self.historyGet(jid.JID(from_jid_s), jid.JID(to_jid_s), limit, between, filters, profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
572 |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
573 def historyGet(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, filters=None, profile=C.PROF_KEY_NONE): |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
574 """Retrieve messages in history |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
575 |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
576 @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
|
577 @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
|
578 @param limit (int): maximum number of messages to get: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
579 - 0 for no message (returns the empty list) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
580 - C.HISTORY_LIMIT_NONE or None for unlimited |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
581 - 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
|
582 @param between (bool): confound source and dest (ignore the direction) |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
583 @param filters (str): pattern to filter the history results (see bridge API for details) |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
584 @param profile (str): %(doc_profile)s |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
585 @return (D(list)): list of message data as in [messageNew] |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
586 """ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
587 assert profile != C.PROF_KEY_NONE |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
588 if limit == C.HISTORY_LIMIT_DEFAULT: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
589 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
|
590 elif limit == C.HISTORY_LIMIT_NONE: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
591 limit = None |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
592 if limit == 0: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
593 return defer.succeed([]) |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
594 return self.storage.historyGet(from_jid, to_jid, limit, between, filters, profile) |
0 | 595 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
596 ## Statuses ## |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
597 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
598 def _getPresenceStatuses(self, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
599 ret = self.getPresenceStatuses(profile_key) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
600 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
|
601 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
602 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
|
603 """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
|
604 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
605 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
606 @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
|
607 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
608 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
|
609 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
|
610 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
611 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
|
612 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
|
613 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
|
614 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
615 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
616 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
|
617 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
618 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
619 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
|
620 |
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
|
621 return entities_presence |
0 | 622 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
623 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
|
624 """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
|
625 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
626 @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
|
627 @param show: show status |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
628 @param priority: priority |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
629 @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
|
630 @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
|
631 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
632 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
|
633 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
|
634 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
|
635 # 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
|
636 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
637 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
|
638 except (KeyError, exceptions.UnknownEntityError): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
639 pass |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
640 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
641 ## Resources ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
642 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
643 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
|
644 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
|
645 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
|
646 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
647 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
|
648 """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
|
649 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
650 @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
|
651 @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
|
652 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
|
653 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
654 @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
|
655 @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
|
656 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
657 if entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
658 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
|
659 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
|
660 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
661 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
|
662 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
663 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
|
664 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
|
665 resources.discard(None) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
666 return resources |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
667 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
668 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
|
669 """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
|
670 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
671 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
|
672 @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
|
673 @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
|
674 return (list[unicode]): list of available resources |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
675 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
676 @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
|
677 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
678 available = [] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
679 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
|
680 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
|
681 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
682 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
687 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
|
688 available.append(resource) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
689 return available |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
690 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
691 def _getMainResource(self, jid_s, profile_key): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
692 client = self.host.getClient(profile_key) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
693 jid_ = jid.JID(jid_s) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
694 return self.getMainResource(client, jid_) or "" |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
695 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
696 def getMainResource(self, client, entity_jid): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
697 """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
|
698 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
699 @param entity_jid: bare entity jid |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
700 @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
|
701 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
702 if entity_jid.resource: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
703 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
|
704 try: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
705 if self.host.plugins["XEP-0045"].isJoinedRoom(client, 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
|
706 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
|
707 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
|
708 pass |
1689
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
709 try: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
710 resources = self.getAllResources(entity_jid, client.profile) |
1689
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
711 except exceptions.UnknownEntityError: |
a40124e03baf
core (memory): catch exceptions.UnknownEntityError in getMainResource
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
712 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
|
713 return None |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
714 priority_resources = [] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
715 for resource in resources: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
716 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
|
717 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
718 try: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
719 presence_data = self.getEntityDatum(full_jid, "presence", client.profile) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
720 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
|
721 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
|
722 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
723 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
|
724 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 return None |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
729 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
730 ## Entities data ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
731 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
732 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
|
733 """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
|
734 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
735 @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
|
736 @return (dict): profile cache |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
737 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
738 @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
|
739 @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
|
740 """ |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
741 profile = self.getProfileName(profile_key) |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
742 if not profile: |
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
743 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
|
744 try: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
745 profile_cache = self._entities_cache[profile] |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
diff
changeset
|
746 except KeyError: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
747 raise exceptions.ProfileNotInCacheError |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
748 return profile_cache |
1251
51a85e8f599a
memory: add method isContactConnected
souliane <souliane@mailoo.org>
parents:
1247
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 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
|
751 """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
|
752 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
753 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
|
754 @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
|
755 @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
|
756 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
757 if signal: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
758 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
|
759 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
760 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
|
761 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
762 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
|
763 """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
|
764 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
765 @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
|
766 @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
|
767 @return (list[unicode]): list of jids |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
768 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
769 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
|
770 # 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
|
771 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
|
772 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
|
773 if resource is None: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
774 continue |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
775 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
|
776 full_jid.resource = resource |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
777 yield full_jid |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
778 |
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
|
779 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
|
780 """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
|
781 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
782 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
|
783 @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
|
784 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
|
785 @param key: key to set (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
786 @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
|
787 @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
|
788 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
789 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
790 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
|
791 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
|
792 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
|
793 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
794 entities = (entity_jid,) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
795 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
796 for jid_ in entities: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
797 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
|
798 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 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
|
803 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
804 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
|
805 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
806 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
|
807 """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
|
808 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
809 @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
|
810 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
|
811 @param key: key to delete (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
812 @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
|
813 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
814 @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
|
815 @raise KeyError: key is not in cache |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
816 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
817 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
|
818 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
|
819 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
|
820 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
821 entities = (entity_jid,) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
822 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
823 for jid_ in entities: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
824 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
825 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
|
826 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
827 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
|
828 try: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
829 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
|
830 except KeyError as e: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
831 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
|
832 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
|
833 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
834 raise e |
399 | 835 |
1314
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
836 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
|
837 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
|
838 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
|
839 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
840 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
|
841 """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
|
842 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
843 @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
|
844 @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
|
845 @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
|
846 @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
|
847 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
|
848 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
|
849 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
|
850 in resulting dict |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
851 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
852 @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
|
853 """ |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
854 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
|
855 entity_data = {} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
856 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
|
857 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
|
858 else: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
859 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
|
860 try: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
861 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
|
862 except KeyError: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
863 continue |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
864 return entity_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
865 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
866 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
|
867 ret_data = {} |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
868 if entities_jids: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
869 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
|
870 try: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
871 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
|
872 except KeyError: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
873 continue |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
874 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
|
875 else: |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
876 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
|
877 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
|
878 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
|
879 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
|
880 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
|
881 |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
882 return ret_data |
bb9c32249778
core: added getEntitiesData which get cache data for several entities at once
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
883 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
884 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
|
885 """Get a list of cached values for entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
886 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
887 @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
|
888 @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
|
889 @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
|
890 @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
|
891 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
|
892 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
|
893 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
894 @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
|
895 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
896 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
|
897 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
898 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
|
899 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
900 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
|
901 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
|
902 return entity_data |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
903 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
904 return {key: entity_data[key] for key in keys_list if key in entity_data} |
47 | 905 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
906 def getEntityDatum(self, entity_jid, key, profile_key): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
907 """Get a datum from entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
908 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
909 @param entity_jid: JID of the entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
910 @param keys: key to get |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
911 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
912 @return: requested value |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
913 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
914 @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
|
915 @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
|
916 """ |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
917 return self.getEntityData(entity_jid, (key,), profile_key)[key] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
918 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
919 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
|
920 """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
|
921 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
922 @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
|
923 @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
|
924 @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
|
925 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
926 @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
|
927 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
928 profile_cache = self._getProfileCache(profile_key) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
929 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
930 if delete_all_resources: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
931 if entity_jid.resource: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
932 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
|
933 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
934 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
|
935 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
936 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
|
937 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
938 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
939 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
|
940 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
941 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
|
942 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
943 ## Encryption ## |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
944 |
1090
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
945 def encryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
946 """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
|
947 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
|
948 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
949 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
950 @param value (str): the value to encrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
951 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
952 @return: the deferred encrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
953 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
954 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
|
955 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
|
956 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
957 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
|
958 return BlockCipher.encrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
959 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
960 def decryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
961 """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
|
962 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
|
963 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
964 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
965 @param value (str): the value to decrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
966 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
967 @return: the deferred decrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
968 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
969 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
|
970 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
|
971 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
972 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
|
973 return BlockCipher.decrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
974 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
975 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
|
976 """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
|
977 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
978 @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
|
979 @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
|
980 @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
|
981 @param profile: %(profile_doc)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
982 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
983 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
984 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
985 def gotIndMemory(data): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
986 d = BlockCipher.encrypt(crypto_key, data_value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
987 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
988 def cb(cipher): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
989 data[data_key] = cipher |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
990 return data.force(data_key) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
991 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
992 return d.addCallback(cb) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
993 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
994 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
|
995 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
|
996 {'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
|
997 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
998 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
|
999 return d.addCallback(gotIndMemory).addCallback(done) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
1000 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1001 ## Subscription requests ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1002 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
1003 def addWaitingSub(self, type_, entity_jid, profile_key): |
47 | 1004 """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
|
1005 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1006 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1007 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
|
1008 self.subscriptions[profile] = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
1009 self.subscriptions[profile][entity_jid] = type_ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1010 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
1011 def delWaitingSub(self, entity_jid, profile_key): |
47 | 1012 """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
|
1013 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1014 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1015 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
|
1016 del self.subscriptions[profile][entity_jid] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1017 |
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
|
1018 def getWaitingSub(self, profile_key): |
47 | 1019 """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
|
1020 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
|
1021 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
1022 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
|
1023 return {} |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1024 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
|
1025 return {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1026 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
1027 return self.subscriptions[profile] |
0 | 1028 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1029 ## Parameters ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1030 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1031 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
|
1032 return self.params.getStringParamA(name, category, attr, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1033 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1034 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
|
1035 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
|
1036 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1037 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
|
1038 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
|
1039 |
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
|
1040 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
|
1041 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
|
1042 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1043 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
|
1044 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
|
1045 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1046 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
|
1047 return self.params.getParamsUI(security_limit, app, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1048 |
0 | 1049 def getParamsCategories(self): |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1050 return self.params.getParamsCategories() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1051 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1052 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
|
1053 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
|
1054 |
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
|
1055 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
|
1056 return self.params.updateParams(xml) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1057 |
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
|
1058 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
|
1059 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
|
1060 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
1061 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
|
1062 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
|
1063 |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1064 ## Files ## |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1065 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1066 def checkFilePermission(self, file_data, peer_jid, perms_to_check): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1067 """check that an entity has the right permission on a file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1068 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1069 @param file_data(dict): data of one file, as returned by getFiles |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1070 @param peer_jid(jid.JID): entity trying to access the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1071 @param perms_to_check(tuple[unicode]): permissions to check |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1072 tuple of C.ACCESS_PERM_* |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1073 @param check_parents(bool): if True, also check all parents until root node |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1074 @raise exceptions.PermissionError: peer_jid doesn't have all permission |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1075 in perms_to_check for file_data |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1076 @raise exceptions.InternalError: perms_to_check is invalid |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1077 """ |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1078 if peer_jid is None and perms_to_check is None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1079 return |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1080 peer_jid = peer_jid.userhostJID() |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1081 if peer_jid == file_data['owner']: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1082 # the owner has all rights |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1083 return |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1084 if not C.ACCESS_PERMS.issuperset(perms_to_check): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1085 raise exceptions.InternalError(_(u'invalid permission')) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1086 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1087 for perm in perms_to_check: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1088 # we check each perm and raise PermissionError as soon as one condition is not valid |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1089 # we must never return here, we only return after the loop if nothing was blocking the access |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1090 try: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1091 perm_data = file_data[u'access'][perm] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1092 perm_type = perm_data[u'type'] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1093 except KeyError: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1094 raise failure.Failure(exceptions.PermissionError()) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1095 if perm_type == C.ACCESS_TYPE_PUBLIC: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1096 continue |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1097 elif perm_type == C.ACCESS_TYPE_WHITELIST: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1098 try: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1099 jids = perm_data[u'jids'] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1100 except KeyError: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1101 raise failure.Failure(exceptions.PermissionError()) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1102 if peer_jid.full() in jids: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1103 continue |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1104 else: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1105 raise failure.Failure(exceptions.PermissionError()) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1106 else: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1107 raise exceptions.InternalError(_(u'unknown access type: {type}').format(type=perm_type)) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1108 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1109 @defer.inlineCallbacks |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1110 def checkPermissionToRoot(self, client, file_data, peer_jid, perms_to_check): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1111 """do checkFilePermission on file_data and all its parents until root""" |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1112 current = file_data |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1113 while True: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1114 self.checkFilePermission(current, peer_jid, perms_to_check) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1115 parent = current[u'parent'] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1116 if not parent: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1117 break |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1118 files_data = yield self.getFile(self, client, peer_jid=None, file_id=parent, perms_to_check=None) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1119 try: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1120 current = files_data[0] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1121 except IndexError: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1122 raise exceptions.DataError(u'Missing parent') |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1123 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1124 @defer.inlineCallbacks |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1125 def _getParentDir(self, client, path, parent, namespace, owner, peer_jid, perms_to_check): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1126 """Retrieve parent node from a path, or last existing directory |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1127 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1128 each directory of the path will be retrieved, until the last existing one |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1129 @return (tuple[unicode, list[unicode])): parent, remaining path elements: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1130 - parent is the id of the last retrieved directory (or u'' for root) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1131 - remaining path elements are the directories which have not been retrieved |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1132 (i.e. which don't exist) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1133 """ |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1134 # if path is set, we have to retrieve parent directory of the file(s) from it |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1135 if parent is not None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1136 raise exceptions.ConflictError(_(u"You can't use path and parent at the same time")) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1137 path_elts = filter(None, path.split(u'/')) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1138 if {u'..', u'.'}.intersection(path_elts): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1139 raise ValueError(_(u'".." or "." can\'t be used in path')) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1140 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1141 # we retrieve all directories from path until we get the parent container |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1142 # non existing directories will be created |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1143 parent = u'' |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1144 for idx, path_elt in enumerate(path_elts): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1145 directories = yield self.storage.getFiles(client, parent=parent, type_=C.FILE_TYPE_DIRECTORY, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1146 name=path_elt, namespace=namespace, owner=owner) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1147 if not directories: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1148 defer.returnValue((parent, path_elts[idx:])) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1149 # from this point, directories don't exist anymore, we have to create them |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1150 elif len(directories) > 1: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1151 raise exceptions.InternalError(_(u"Several directories found, this should not happen")) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1152 else: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1153 directory = directories[0] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1154 self.checkFilePermission(directory, peer_jid, perms_to_check) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1155 parent = directory[u'id'] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1156 defer.returnValue((parent, [])) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1157 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1158 @defer.inlineCallbacks |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1159 def getFiles(self, client, peer_jid, file_id=None, version=None, parent=None, path=None, type_=None, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1160 file_hash=None, hash_algo=None, name=None, namespace=None, mime_type=None, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1161 owner=None, access=None, projection=None, unique=False, perms_to_check=(C.ACCESS_PERM_READ,)): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1162 """retrieve files with with given filters |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1163 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1164 @param peer_jid(jid.JID, None): jid trying to access the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1165 needed to check permission. |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1166 Use None to ignore permission (perms_to_check must be None too) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1167 @param file_id(unicode, None): id of the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1168 None to ignore |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1169 @param version(unicode, None): version of the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1170 None to ignore |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1171 empty string to look for current version |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1172 @param parent(unicode, None): id of the directory containing the files |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1173 None to ignore |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1174 empty string to look for root files/directories |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1175 @param projection(list[unicode], None): name of columns to retrieve |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1176 None to retrieve all |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1177 @param unique(bool): if True will remove duplicates |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1178 @param perms_to_check(tuple[unicode],None): permission to check |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1179 must be a tuple of C.ACCESS_PERM_* or None |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1180 if None, permission will no be checked (peer_jid must be None too in this case) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1181 other params are the same as for [setFile] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1182 @return (list[dict]): files corresponding to filters |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1183 @raise exceptions.NotFound: parent directory not found (when path is specified) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1184 @raise exceptions.PermissionError: peer_jid can't use perms_to_check for one of the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1185 on the path |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1186 """ |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1187 if peer_jid is None and perms_to_check or perms_to_check is None and peer_jid: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1188 raise exceptions.InternalError('if you want to disable permission check, both peer_jid and perms_to_check must be None') |
2518
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1189 if owner is not None: |
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1190 owner = owner.userhostJID() |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1191 if path is not None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1192 # permission are checked by _getParentDir |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1193 parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, peer_jid, perms_to_check) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1194 if remaining_path_elts: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1195 # if we have remaining path elements, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1196 # the parent directory is not found |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1197 raise failure.Failure(exceptions.NotFound()) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1198 if parent and peer_jid: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1199 # if parent is given directly and permission check is need, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1200 # we need to check all the parents |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1201 parent_data = yield self.storage.getFiles(client, file_id=parent) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1202 try: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1203 parent_data = parent_data[0] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1204 except IndexError: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1205 raise exceptions.DataError(u'mising parent') |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1206 yield self.checkPermissionToRoot(client, parent_data, peer_jid, perms_to_check) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1207 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1208 files = yield self.storage.getFiles(client, file_id=file_id, version=version, parent=parent, type_=type_, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1209 file_hash=file_hash, hash_algo=hash_algo, name=name, namespace=namespace, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1210 mime_type=mime_type, owner=owner, access=access, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1211 projection=projection, unique=unique) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1212 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1213 if peer_jid: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1214 # if permission are checked, we must remove all file tha use can't access |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1215 to_remove = [] |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1216 for file_data in files: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1217 try: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1218 self.checkFilePermission(file_data, peer_jid, perms_to_check) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1219 except exceptions.PermissionError: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1220 to_remove.append(file_data) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1221 for file_data in to_remove: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1222 files.remove(file_data) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1223 defer.returnValue(files) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1224 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1225 @defer.inlineCallbacks |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1226 def setFile(self, client, name, file_id=None, version=u'', parent=None, path=None, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1227 type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None, namespace=None, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1228 mime_type=None, created=None, modified=None, owner=None, access=None, extra=None, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1229 peer_jid = None, perms_to_check=(C.ACCESS_PERM_WRITE,)): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1230 """set a file metadata |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1231 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1232 @param name(unicode): basename of the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1233 @param file_id(unicode): unique id of the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1234 @param version(unicode): version of this file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1235 empty string for current version or when there is no versioning |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1236 @param parent(unicode, None): id of the directory containing the files |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1237 @param path(unicode, None): virtual path of the file in the namespace |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1238 if set, parent must be None. All intermediate directories will be created if needed, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1239 using current access. |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1240 @param file_hash(unicode): unique hash of the payload |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1241 @param hash_algo(unicode): algorithm used for hashing the file (usually sha-256) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1242 @param size(int): size in bytes |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1243 @param namespace(unicode, None): identifier (human readable is better) to group files |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1244 for instance, namespace could be used to group files in a specific photo album |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1245 @param mime_type(unicode): MIME type of the file, or None if not known/guessed |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1246 @param created(int): UNIX time of creation |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1247 @param modified(int,None): UNIX time of last modification, or None to use created date |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1248 @param owner(jid.JID, None): jid of the owner of the file (mainly useful for component) |
2518
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1249 will be used to check permission (only bare jid is used, don't use with MUC). |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1250 Use None to ignore permission (perms_to_check must be None too) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1251 @param access(dict, None): serialisable dictionary with access rules. |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1252 None (or empty dict) to use private access, i.e. allow only profile's jid to access the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1253 key can be on on C.ACCESS_PERM_*, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1254 then a sub dictionary with a type key is used (one of C.ACCESS_TYPE_*). |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1255 According to type, extra keys can be used: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1256 - C.ACCESS_TYPE_PUBLIC: the permission is granted for everybody |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1257 - C.ACCESS_TYPE_WHITELIST: the permission is granted for jids (as unicode) in the 'jids' key |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1258 will be encoded to json in database |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1259 @param extra(dict, None): serialisable dictionary of any extra data |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1260 will be encoded to json in database |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1261 @param perms_to_check(tuple[unicode],None): permission to check |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1262 must be a tuple of C.ACCESS_PERM_* or None |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1263 if None, permission will no be checked (peer_jid must be None too in this case) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1264 @param profile(unicode): profile owning the file |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1265 """ |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1266 if '/' in name: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1267 raise ValueError('name must not contain a slash ("/")') |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1268 if file_id is None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1269 file_id = shortuuid.uuid() |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1270 if file_hash is not None and hash_algo is None or hash_algo is not None and file_hash is None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1271 raise ValueError('file_hash and hash_algo must be set at the same time') |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1272 if mime_type is None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1273 mime_type, file_encoding = mimetypes.guess_type(name) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1274 if created is None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1275 created = time.time() |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1276 if namespace is not None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1277 namespace = namespace.strip() or None |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1278 if type_ == C.FILE_TYPE_DIRECTORY: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1279 if any(version, file_hash, size, mime_type): |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1280 raise ValueError(u"version, file_hash, size and mime_type can't be set for a directory") |
2518
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1281 if owner is not None: |
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1282 owner = owner.userhostJID() |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1283 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1284 if path is not None: |
2518
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1285 # _getParentDir will check permissions if peer_jid is set, so we use owner |
2508
4e5cc45e2be7
core (memory): fixed _getParentDir call in setFile
Goffi <goffi@goffi.org>
parents:
2501
diff
changeset
|
1286 parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, owner, perms_to_check) |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1287 # if remaining directories don't exist, we have to create them |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1288 for new_dir in remaining_path_elts: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1289 new_dir_id = shortuuid.uuid() |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1290 yield self.storage.setFile(client, name=new_dir, file_id=new_dir_id, version=u'', parent=parent, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1291 type_=C.FILE_TYPE_DIRECTORY, namespace=namespace, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1292 created=time.time(), |
2518
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1293 owner=owner, |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1294 access=access, extra={}) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1295 parent = new_dir_id |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1296 elif parent is None: |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1297 parent = u'' |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1298 |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1299 yield self.storage.setFile(client, file_id=file_id, version=version, parent=parent, type_=type_, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1300 file_hash=file_hash, hash_algo=hash_algo, name=name, size=size, |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1301 namespace=namespace, mime_type=mime_type, created=created, modified=modified, |
2518
e4de2f16a284
core (memory): use bare jid for owner in setFiles:
Goffi <goffi@goffi.org>
parents:
2508
diff
changeset
|
1302 owner=owner, |
2501
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1303 access=access, extra=extra) |
3b67fe672206
core (memory): file metadata handling methods:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1304 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1305 ## Misc ## |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1306 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1307 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
|
1308 """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
|
1309 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1310 @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
|
1311 @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
|
1312 @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
|
1313 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1314 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
|
1315 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
|
1316 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1317 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
|
1318 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
|
1319 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
|
1320 return False |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
1321 return presence_data.show != C.PRESENCE_UNAVAILABLE |