Mercurial > libervia-backend
annotate libervia/backend/core/xmpp.py @ 4306:94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
- Code has been rewritten using Pydantic models and `async` coroutines for data validation
and cleaner element parsing/generation.
- Delivery has been completely rewritten. It now works even if server doesn't support
multicast, and send to local multicast service first. Delivering to local multicast
service first is due to bad support of XEP-0033 in server (notably Prosody which has an
incomplete implementation), and the current impossibility to detect if a sub-domain
service handles fully multicast or only for local domains. This is a workaround to have
a good balance between backward compatilibity and use of bandwith, and to make it work
with the incoming email gateway implementation (the gateway will only deliver to
entities of its own domain).
- disco feature checking now uses `async` corountines. `host` implementation still use
Deferred return values for compatibility with legacy code.
rel 450
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:12:01 +0200 |
parents | 0f953ce5f0a8 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
3 # Libervia: an XMPP client |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
0 | 5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
6 # 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:
589
diff
changeset
|
7 # 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:
589
diff
changeset
|
8 # 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:
589
diff
changeset
|
9 # (at your option) any later version. |
0 | 10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
11 # 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:
589
diff
changeset
|
12 # 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:
589
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
14 # GNU Affero General Public License for more details. |
0 | 15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
16 # 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:
589
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
19 import asyncio |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
20 import calendar |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
21 import copy |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
22 from functools import partial |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
23 import mimetypes |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
24 from pathlib import Path |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
25 import sys |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
26 import time |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
27 from typing import Callable, Dict, Tuple, Optional |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
28 from urllib.parse import unquote, urlparse |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
29 import uuid |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
30 |
3149
f3700175c6a3
core (xmpp): use a stable resource (sat.[shortuuid]) instead of server one if nothing is specified
Goffi <goffi@goffi.org>
parents:
3138
diff
changeset
|
31 import shortuuid |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
32 from twisted.internet import defer, error as internet_error, reactor |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
33 from twisted.internet import ssl |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
34 from twisted.python import failure |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 from twisted.words.protocols.jabber import xmlstream |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
36 from twisted.words.protocols.jabber import error |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
37 from twisted.words.protocols.jabber import jid |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
38 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
2130
f0bc29dc8157
added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents:
2113
diff
changeset
|
39 from twisted.words.xish import domish |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
40 from wokkel import client as wokkel_client, disco, generic, iwokkel, xmppim |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
41 from wokkel import component |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
42 from wokkel import delay |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
43 from zope.interface import implementer |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
44 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
45 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
46 from libervia.backend.core import core_types |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
47 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
48 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
49 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
50 from libervia.backend.memory import cache |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
51 from libervia.backend.memory import encryption |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
52 from libervia.backend.memory import persistent |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
53 from libervia.backend.models.core import MessageData |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
54 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
55 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
56 from libervia.backend.tools.common import data_format |
0 | 57 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
58 log = getLogger(__name__) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
59 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
60 |
3028 | 61 NS_X_DATA = "jabber:x:data" |
62 NS_DISCO_INFO = "http://jabber.org/protocol/disco#info" | |
63 NS_XML_ELEMENT = "urn:xmpp:xml-element" | |
64 NS_ROSTER_VER = "urn:xmpp:features:rosterver" | |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
65 # we use 2 "@" which is illegal in a jid, to be sure we are not mixing keys |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
66 # with roster jids |
3028 | 67 ROSTER_VER_KEY = "@version@" |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
68 |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
69 |
3249
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
70 class ClientPluginWrapper: |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
71 """Use a plugin with default value if plugin is missing""" |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
72 |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
73 def __init__(self, client, plugin_name, missing): |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
74 self.client = client |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
75 self.plugin = client.host_app.plugins.get(plugin_name) |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
76 if self.plugin is None: |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
77 self.plugin_name = plugin_name |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
78 self.missing = missing |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
79 |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
80 def __getattr__(self, attr): |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
81 if self.plugin is None: |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
82 missing = self.missing |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
83 if isinstance(missing, type) and issubclass(missing, Exception): |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
84 raise missing(f"plugin {self.plugin_name!r} is not available") |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
85 elif isinstance(missing, Exception): |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
86 raise missing |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
87 else: |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
88 return lambda *args, **kwargs: missing |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
89 return partial(getattr(self.plugin, attr), self.client) |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
90 |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
91 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3533
diff
changeset
|
92 class SatXMPPEntity(core_types.SatXMPPEntity): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
93 """Common code for Client and Component""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
94 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
95 # profile is added there when start_connection begins and removed when it is finished |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
96 profiles_connecting = set() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
97 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
98 def __init__(self, host_app, profile, max_retries): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
99 factory = self.factory |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
100 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
101 # we monkey patch clientConnectionLost to handle network_enabled/network_disabled |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
102 # and to allow plugins to tune reconnection mechanism |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
103 clientConnectionFailed_ori = factory.clientConnectionFailed |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
104 clientConnectionLost_ori = factory.clientConnectionLost |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
105 factory.clientConnectionFailed = partial( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
106 self.connection_terminated, term_type="failed", cb=clientConnectionFailed_ori |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
107 ) |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
108 factory.clientConnectionLost = partial( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
109 self.connection_terminated, term_type="lost", cb=clientConnectionLost_ori |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
110 ) |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
111 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
112 factory.maxRetries = max_retries |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
113 factory.maxDelay = 30 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
114 # when self._connected_d is None, we are not connected |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
115 # else, it's a deferred which fire on disconnection |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
116 self._connected_d = None |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
117 self.profile = profile |
64 | 118 self.host_app = host_app |
2109
85f3e12e984d
core (memory/cache): file caching handling, first draft:
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
119 self.cache = cache.Cache(host_app, profile) |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
120 self.mess_id2uid = {} # map from message id to uid used in history. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
121 # Key: (full_jid, message_id) Value: uid |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
122 # this Deferred fire when entity is connected |
341 | 123 self.conn_deferred = defer.Deferred() |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
124 self._progress_cb = {} # callback called when a progress is requested |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
125 # (key = progress id) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
126 self.actions = {} # used to keep track of actions for retrieval (key = action_id) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2650
diff
changeset
|
127 self.encryption = encryption.EncryptionHandler(self) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
128 |
3040 | 129 def __str__(self): |
130 return f"Client for profile {self.profile}" | |
2742
1f5b02623355
core (xmpp): implemented human friendly __unicode__ for client
Goffi <goffi@goffi.org>
parents:
2736
diff
changeset
|
131 |
3040 | 132 def __repr__(self): |
133 return f"{super().__repr__()} - profile: {self.profile!r}" | |
2742
1f5b02623355
core (xmpp): implemented human friendly __unicode__ for client
Goffi <goffi@goffi.org>
parents:
2736
diff
changeset
|
134 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
135 ## initialisation ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
136 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
137 async def _call_connection_triggers(self, connection_timer): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
138 """Call conneting trigger prepare connected trigger |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
139 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
140 @param plugins(iterable): plugins to use |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
141 @return (list[object, callable]): plugin to trigger tuples with: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
142 - plugin instance |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
143 - profile_connected* triggers (to call after connection) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
144 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
145 plugin_conn_cb = [] |
4182
4dc00e848961
core (tools/trigger): new `add_with_check` method:
Goffi <goffi@goffi.org>
parents:
4168
diff
changeset
|
146 self.plugins = plugins = self._get_plugins_list() |
4dc00e848961
core (tools/trigger): new `add_with_check` method:
Goffi <goffi@goffi.org>
parents:
4168
diff
changeset
|
147 for plugin in plugins: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
148 # we check if plugin handle client mode |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
149 if plugin.is_handler: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
150 plugin.get_handler(self).setHandlerParent(self) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
151 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
152 # profile_connecting/profile_connected methods handling |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
153 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
154 timer = connection_timer[plugin] = {"total": 0} |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
155 # profile connecting is called right now (before actually starting client) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
156 connecting_cb = getattr(plugin, "profile_connecting", None) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
157 if connecting_cb is not None: |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
158 connecting_start = time.time() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
159 await utils.as_deferred(connecting_cb, self) |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
160 timer["connecting"] = time.time() - connecting_start |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
161 timer["total"] += timer["connecting"] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
162 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
163 # profile connected is called after client is ready and roster is got |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
164 connected_cb = getattr(plugin, "profile_connected", None) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
165 if connected_cb is not None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
166 plugin_conn_cb.append((plugin, connected_cb)) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
167 |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
168 return plugin_conn_cb |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
169 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
170 def _get_plugins_list(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
171 """Return list of plugin to use |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
172 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
173 need to be implemented by subclasses |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
174 this list is used to call profileConnect* triggers |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
175 @return(iterable[object]): plugins to use |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
176 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
177 raise NotImplementedError |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
178 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
179 def _create_sub_protocols(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
180 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
181 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
182 def entity_connected(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
183 """Called once connection is done |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
184 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
185 may return a Deferred, to perform initialisation tasks |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
186 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
187 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
188 |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
189 @staticmethod |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
190 async def _run_profile_connected( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
191 callback: Callable, entity: "SatXMPPEntity", timer: Dict[str, float] |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
192 ) -> None: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
193 connected_start = time.time() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
194 await utils.as_deferred(callback, entity) |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
195 timer["connected"] = time.time() - connected_start |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
196 timer["total"] += timer["connected"] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
197 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
198 @classmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
199 async def start_connection(cls, host, profile, max_retries): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
200 """instantiate the entity and start the connection""" |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
201 # FIXME: reconnection doesn't seems to be handled correclty |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
202 # (client is deleted then recreated from scratch) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
203 # most of methods called here should be called once on first connection |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
204 # (e.g. adding subprotocols) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
205 # but client should not be deleted except if session is finished |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
206 # (independently of connection/deconnection) |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
207 if profile in cls.profiles_connecting: |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
208 raise exceptions.CancelError(f"{profile} is already being connected") |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
209 cls.profiles_connecting.add(profile) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
210 try: |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
211 try: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
212 port = int( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
213 host.memory.param_get_a( |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
214 C.FORCE_PORT_PARAM, "Connection", profile_key=profile |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
215 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
216 ) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
217 except ValueError: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
218 log.debug(_("Can't parse port value, using default value")) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
219 port = None # will use default value 5222 or be retrieved from a DNS SRV record |
3149
f3700175c6a3
core (xmpp): use a stable resource (sat.[shortuuid]) instead of server one if nothing is specified
Goffi <goffi@goffi.org>
parents:
3138
diff
changeset
|
220 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
221 password = await host.memory.param_get_a_async( |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
222 "Password", "Connection", profile_key=profile |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
223 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
224 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
225 entity_jid_s = await host.memory.param_get_a_async( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
226 "JabberID", "Connection", profile_key=profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
227 ) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
228 entity_jid = jid.JID(entity_jid_s) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
229 |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
230 if not entity_jid.resource and not cls.is_component and entity_jid.user: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
231 # if no resource is specified, we create our own instead of using |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
232 # server returned one, as it will then stay stable in case of |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
233 # reconnection. we only do that for client and if there is a user part, to |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
234 # let server decide for anonymous login |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
235 resource_dict = await host.memory.storage.get_privates( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
236 "core:xmpp", ["resource"], profile=profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
237 ) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
238 try: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
239 resource = resource_dict["resource"] |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
240 except KeyError: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
241 resource = f"{C.APP_NAME_FILE}.{shortuuid.uuid()}" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
242 await host.memory.storage.set_private_value( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
243 "core:xmpp", "resource", resource, profile=profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
244 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
245 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
246 log.info( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
247 _("We'll use the stable resource {resource}").format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
248 resource=resource |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
249 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
250 ) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
251 entity_jid.resource = resource |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
252 |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
253 if profile in host.profiles: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
254 if host.profiles[profile].is_connected(): |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
255 raise exceptions.InternalError( |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
256 f"There is already a connected profile of name {profile!r} in " |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
257 f"host" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
258 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
259 log.debug("removing unconnected profile {profile!r}") |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
260 del host.profiles[profile] |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
261 entity = host.profiles[profile] = cls( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
262 host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
263 profile, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
264 entity_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
265 password, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
266 host.memory.param_get_a( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
267 C.FORCE_SERVER_PARAM, "Connection", profile_key=profile |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
268 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
269 or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
270 port, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
271 max_retries, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
272 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
273 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
274 await entity.encryption.load_sessions() |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
275 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
276 entity._create_sub_protocols() |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
277 |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
278 entity.fallBack = SatFallbackHandler(host) |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
279 entity.fallBack.setHandlerParent(entity) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
280 |
3553
01c23359b915
core (xmpp): show "Libervia" without the "(backend)" component in version
Goffi <goffi@goffi.org>
parents:
3542
diff
changeset
|
281 entity.versionHandler = SatVersionHandler(C.APP_NAME, host.full_version) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
282 entity.versionHandler.setHandlerParent(entity) |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
283 |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
284 entity.identityHandler = SatIdentityHandler() |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
285 entity.identityHandler.setHandlerParent(entity) |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
286 |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
287 log.debug(_("setting plugins parents")) |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
288 |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
289 connection_timer: Dict[str, Dict[str, float]] = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
290 plugin_conn_cb = await entity._call_connection_triggers(connection_timer) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
291 |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
292 entity.startService() |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
293 |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
294 await entity.conn_deferred |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
295 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
296 await defer.maybeDeferred(entity.entity_connected) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
297 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
298 # Call profile_connected callback for all plugins, |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
299 # and print error message if any of them fails |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
300 conn_cb_list = [] |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
301 for plugin, callback in plugin_conn_cb: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
302 conn_cb_list.append( |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
303 defer.ensureDeferred( |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
304 cls._run_profile_connected( |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
305 callback, entity, connection_timer[plugin] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
306 ) |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
307 ) |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
308 ) |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
309 list_d = defer.DeferredList(conn_cb_list) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
310 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
311 def log_plugin_results(results): |
4000
2d59974a8e3e
core (xmpp): improve pluging timing log by using highest `profileConnected` time:
Goffi <goffi@goffi.org>
parents:
3999
diff
changeset
|
312 if not results: |
2d59974a8e3e
core (xmpp): improve pluging timing log by using highest `profileConnected` time:
Goffi <goffi@goffi.org>
parents:
3999
diff
changeset
|
313 log.info("no plugin loaded") |
2d59974a8e3e
core (xmpp): improve pluging timing log by using highest `profileConnected` time:
Goffi <goffi@goffi.org>
parents:
3999
diff
changeset
|
314 return |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
315 all_succeed = all([success for success, result in results]) |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
316 if not all_succeed: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
317 log.error(_("Plugins initialisation error")) |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
318 for idx, (success, result) in enumerate(results): |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
319 if not success: |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
320 plugin_name = plugin_conn_cb[idx][0]._info["import_name"] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
321 log.error(f"error (plugin {plugin_name}): {result}") |
4000
2d59974a8e3e
core (xmpp): improve pluging timing log by using highest `profileConnected` time:
Goffi <goffi@goffi.org>
parents:
3999
diff
changeset
|
322 |
2d59974a8e3e
core (xmpp): improve pluging timing log by using highest `profileConnected` time:
Goffi <goffi@goffi.org>
parents:
3999
diff
changeset
|
323 log.debug(f"Plugin loading time for {profile!r} (longer to shorter):\n") |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
324 plugins_by_timer = sorted( |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
325 connection_timer, |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
326 key=lambda p: connection_timer[p]["total"], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
327 reverse=True, |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
328 ) |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
329 # total is the addition of all connecting and connected, doesn't really |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
330 # reflect the real loading time as connected are launched in a |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
331 # DeferredList |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
332 total_plugins = 0 |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
333 # total real sum all connecting (which happen sequentially) and the |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
334 # longuest connected (connected happen in parallel, thus the longuest is |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
335 # roughly the total time for connected) |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
336 total_real = 0 |
4000
2d59974a8e3e
core (xmpp): improve pluging timing log by using highest `profileConnected` time:
Goffi <goffi@goffi.org>
parents:
3999
diff
changeset
|
337 total_real = max(t.get("connected", 0) for t in connection_timer.values()) |
3999
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
338 |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
339 for plugin in plugins_by_timer: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
340 name = plugin._info["import_name"] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
341 timer = connection_timer[plugin] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
342 total_plugins += timer["total"] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
343 try: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
344 connecting = f"{timer['connecting']:.2f}s" |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
345 except KeyError: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
346 connecting = "n/a" |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
347 else: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
348 total_real += timer["connecting"] |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
349 try: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
350 connected = f"{timer['connected']:.2f}s" |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
351 except KeyError: |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
352 connected = "n/a" |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
353 log.debug( |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
354 f" - {name}: total={timer['total']:.2f}s " |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
355 f"connecting={connecting} connected={connected}" |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
356 ) |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
357 log.debug( |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
358 f" Plugins total={total_plugins:.2f}s real={total_real:.2f}s\n" |
f7fa3993df28
core: add debug trace to show plugins loading time
Goffi <goffi@goffi.org>
parents:
3920
diff
changeset
|
359 ) |
341 | 360 |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
361 await list_d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
362 log_plugin_results |
3244
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
363 ) # FIXME: we should have a timeout here, and a way to know if a plugin freeze |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
364 # TODO: mesure launch time of each plugin |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
365 finally: |
b10d207f95f9
core (xmpp): properly clean profile data in case of startConnection failure:
Goffi <goffi@goffi.org>
parents:
3238
diff
changeset
|
366 cls.profiles_connecting.remove(profile) |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
367 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
368 def _disconnection_cb(self, __): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
369 self._connected_d = None |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
370 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
371 def _disconnection_eb(self, failure_): |
3028 | 372 log.error(_("Error while disconnecting: {}".format(failure_))) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
373 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
374 def _authd(self, xmlstream): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
375 super(SatXMPPEntity, self)._authd(xmlstream) |
3028 | 376 log.debug(_("{profile} identified").format(profile=self.profile)) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
377 self.stream_initialized() |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
378 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
379 def _finish_connection(self, __): |
3698
a806dcad6bfc
core: don't callback `self.conn_deferred` if already called:
Goffi <goffi@goffi.org>
parents:
3553
diff
changeset
|
380 if self.conn_deferred.called: |
a806dcad6bfc
core: don't callback `self.conn_deferred` if already called:
Goffi <goffi@goffi.org>
parents:
3553
diff
changeset
|
381 # can happen in case of forced disconnection by server |
a806dcad6bfc
core: don't callback `self.conn_deferred` if already called:
Goffi <goffi@goffi.org>
parents:
3553
diff
changeset
|
382 log.debug(f"{self} has already been connected") |
a806dcad6bfc
core: don't callback `self.conn_deferred` if already called:
Goffi <goffi@goffi.org>
parents:
3553
diff
changeset
|
383 else: |
a806dcad6bfc
core: don't callback `self.conn_deferred` if already called:
Goffi <goffi@goffi.org>
parents:
3553
diff
changeset
|
384 self.conn_deferred.callback(None) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
385 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
386 def stream_initialized(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
387 """Called after _authd""" |
3028 | 388 log.debug(_("XML stream is initialized")) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
389 if not self.host_app.trigger.point("xml_init", self): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
390 return |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
391 self.post_stream_init() |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
392 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
393 def post_stream_init(self): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
394 """Workflow after stream initalisation.""" |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
395 log.info( |
3028 | 396 _("********** [{profile}] CONNECTED **********").format(profile=self.profile) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
397 ) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
398 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
399 # the following Deferred is used to know when we are connected |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
400 # so we need to be set it to None when connection is lost |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
401 self._connected_d = defer.Deferred() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
402 self._connected_d.addCallback(self._clean_connection) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
403 self._connected_d.addCallback(self._disconnection_cb) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
404 self._connected_d.addErrback(self._disconnection_eb) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
405 |
2894
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
406 # we send the signal to the clients |
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
407 self.host_app.bridge.connected(self.jid.full(), self.profile) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
408 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
409 self.disco = SatDiscoProtocol(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
410 self.disco.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
411 self.discoHandler = disco.DiscoHandler() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
412 self.discoHandler.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
413 disco_d = defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
414 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
415 if not self.host_app.trigger.point("Disco handled", disco_d, self.profile): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
416 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
417 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
418 disco_d.addCallback(self._finish_connection) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
419 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
420 def initializationFailed(self, reason): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
421 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
422 _( |
3028 | 423 "ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
424 % {"profile": self.profile, "reason": reason} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
425 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
426 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
427 self.conn_deferred.errback(reason.value) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
428 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
429 super(SatXMPPEntity, self).initializationFailed(reason) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
430 except: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
431 # we already chained an errback, no need to raise an exception |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
432 pass |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
433 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
434 ## connection ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
435 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
436 def connection_terminated(self, connector, reason, term_type, cb): |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
437 """Display disconnection reason, and call factory method |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
438 |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
439 This method is monkey patched to factory, allowing plugins to handle finely |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
440 reconnection with the triggers. |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
441 @param connector(twisted.internet.base.BaseConnector): current connector |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
442 @param reason(failure.Failure): why connection has been terminated |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
443 @param term_type(unicode): on of 'failed' or 'lost' |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
444 @param cb(callable): original factory method |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
445 |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
446 @trigger connection_failed(connector, reason): connection can't be established |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
447 @trigger connection_lost(connector, reason): connection was available but it not |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
448 anymore |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
449 """ |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
450 # we save connector because it may be deleted when connection will be dropped |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
451 # if reconnection is disabled |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
452 self._saved_connector = connector |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
453 if reason is not None and not isinstance( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
454 reason.value, internet_error.ConnectionDone |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
455 ): |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
456 try: |
3028 | 457 reason_str = str(reason.value) |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
458 except Exception: |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
459 # FIXME: workaround for Android were p4a strips docstrings |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
460 # while Twisted use docstring in __str__ |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
461 # TODO: create a ticket upstream, Twisted should work when optimization |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
462 # is used |
3028 | 463 reason_str = str(reason.value.__class__) |
3710
e3dddf65fa88
core (xmpp): specify profile when logging a connection problem
Goffi <goffi@goffi.org>
parents:
3698
diff
changeset
|
464 log.warning(f"[{self.profile}] Connection {term_type}: {reason_str}") |
3028 | 465 if not self.host_app.trigger.point("connection_" + term_type, connector, reason): |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
466 return |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
467 return cb(connector, reason) |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
468 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
469 def network_disabled(self): |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
470 """Indicate that network has been completely disabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
471 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
472 In other words, internet is not available anymore and transport must be stopped. |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
473 Retrying is disabled too, as it makes no sense to try without network, and it may |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
474 use resources (notably battery on mobiles). |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
475 """ |
3028 | 476 log.info(_("stopping connection because of network disabled")) |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
477 self.factory.continueTrying = 0 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
478 self._network_disabled = True |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
479 if self.xmlstream is not None: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
480 self.xmlstream.transport.abortConnection() |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
481 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
482 def network_enabled(self): |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
483 """Indicate that network has been (re)enabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
484 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
485 This happens when e.g. user activate WIFI connection. |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
486 """ |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
487 try: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
488 connector = self._saved_connector |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
489 network_disabled = self._network_disabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
490 except AttributeError: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
491 # connection has not been stopped by network_disabled |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
492 # we don't have to restart it |
3125
c3ce8c997fdf
plugin android: reconnect profiles with autoconnect if network is activated:
Goffi <goffi@goffi.org>
parents:
3059
diff
changeset
|
493 log.debug(f"no connection to restart [{self.profile}]") |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
494 return |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
495 else: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
496 del self._network_disabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
497 if not network_disabled: |
3028 | 498 raise exceptions.InternalError("network_disabled should be True") |
499 log.info(_("network is available, trying to connect")) | |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
500 # we want to be sure to start fresh |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
501 self.factory.resetDelay() |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
502 # we have a saved connector, meaning the connection has been stopped previously |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
503 # we can now try to reconnect |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
504 connector.connect() |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
505 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
506 def _connected(self, xs): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
507 send_hooks = [] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
508 receive_hooks = [] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
509 self.host_app.trigger.point("stream_hooks", self, receive_hooks, send_hooks) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
510 for hook in receive_hooks: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
511 xs.add_hook(C.STREAM_HOOK_RECEIVE, hook) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
512 for hook in send_hooks: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
513 xs.add_hook(C.STREAM_HOOK_SEND, hook) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
514 super(SatXMPPEntity, self)._connected(xs) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
515 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
516 def disconnect_profile(self, reason): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
517 if self._connected_d is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
518 self.host_app.bridge.disconnected( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
519 self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
520 ) # we send the signal to the clients |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
521 log.info( |
3028 | 522 _("********** [{profile}] DISCONNECTED **********").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
523 profile=self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
524 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
525 ) |
3135
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
526 # we purge only if no new connection attempt is expected |
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
527 if not self.factory.continueTrying: |
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
528 log.debug("continueTrying not set, purging entity") |
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
529 self._connected_d.callback(None) |
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
530 # and we remove references to this client |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
531 self.host_app.purge_entity(self.profile) |
3135
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
532 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
533 if not self.conn_deferred.called: |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
534 if reason is None: |
3028 | 535 err = error.StreamError("Server unexpectedly closed the connection") |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
536 else: |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
537 err = reason |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
538 try: |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
539 if err.value.args[0][0][2] == "certificate verify failed": |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
540 err = exceptions.InvalidCertificate( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
541 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
542 "Your server certificate is not valid " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
543 "(its identity can't be checked).\n\n" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
544 "This should never happen and may indicate that " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
545 "somebody is trying to spy on you.\n" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
546 "Please contact your server administrator." |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
547 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
548 ) |
2884
368a60f05d0e
core (xmpp): use the cleaner stopTrying() instead of setting `continueTrying = 0` when connection is not possible due to invalid certificate.
Goffi <goffi@goffi.org>
parents:
2820
diff
changeset
|
549 self.factory.stopTrying() |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
550 try: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
551 # with invalid certificate, we should not retry to connect |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
552 # so we delete saved connector to avoid reconnection if |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
553 # network_enabled is called. |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
554 del self._saved_connector |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
555 except AttributeError: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
556 pass |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
557 except (IndexError, TypeError): |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
558 pass |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
559 self.conn_deferred.errback(err) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
560 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
561 def _disconnected(self, reason): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
562 super(SatXMPPEntity, self)._disconnected(reason) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
563 if not self.host_app.trigger.point("disconnected", self, reason): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
564 return |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
565 self.disconnect_profile(reason) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
566 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
567 @defer.inlineCallbacks |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
568 def _clean_connection(self, __): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
569 """method called on disconnection |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
570 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
571 used to call profile_disconnected* triggers |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
572 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
573 trigger_name = "profile_disconnected" |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
574 for plugin in self._get_plugins_list(): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
575 disconnected_cb = getattr(plugin, trigger_name, None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
576 if disconnected_cb is not None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
577 yield disconnected_cb(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
578 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
579 def is_connected(self): |
3203
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
580 """Return True is client is fully connected |
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
581 |
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
582 client is considered fully connected if transport is started and all plugins |
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
583 are initialised |
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
584 """ |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
585 try: |
3203
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
586 transport_connected = bool(self.xmlstream.transport.connected) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
587 except AttributeError: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
588 return False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
589 |
3203
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
590 return self._connected_d is not None and transport_connected |
fee8e33e2b3f
core (xmpp): isConnected now returns True when full connection is done:
Goffi <goffi@goffi.org>
parents:
3197
diff
changeset
|
591 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
592 def entity_disconnect(self): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
593 if not self.host_app.trigger.point("disconnecting", self): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
594 return |
3028 | 595 log.info(_("Disconnecting...")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
596 self.stopService() |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
597 if self._connected_d is not None: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
598 return self._connected_d |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
599 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
600 return defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
601 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
602 ## sending ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
603 |
3028 | 604 def IQ(self, type_="set", timeout=60): |
1551
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
605 """shortcut to create an IQ element managing deferred |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
606 |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
607 @param type_(unicode): IQ type ('set' or 'get') |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
608 @param timeout(None, int): timeout in seconds |
2110
2d633b3c923d
plugin XEP-0231: Bits of Binary first draft:
Goffi <goffi@goffi.org>
parents:
2109
diff
changeset
|
609 @return((D)domish.Element: result stanza |
3221
b1c90eedbc12
core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
Goffi <goffi@goffi.org>
parents:
3203
diff
changeset
|
610 errback is called if an error stanza is returned |
1551
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
611 """ |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
612 iq_elt = xmlstream.IQ(self.xmlstream, type_) |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
613 iq_elt.timeout = timeout |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
614 return iq_elt |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
615 |
3522
41a6c144dc90
core (xmpp): added `appCondition` argument to `sendError`
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
616 def sendError(self, iq_elt, condition, text=None, appCondition=None): |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
617 """Send error stanza build from iq_elt |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
618 |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
619 @param iq_elt(domish.Element): initial IQ element |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
620 @param condition(unicode): error condition |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
621 """ |
3522
41a6c144dc90
core (xmpp): added `appCondition` argument to `sendError`
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
622 iq_error_elt = error.StanzaError( |
3533
4b33ed5abd8f
core (xmpp): fix typo in sendError
Goffi <goffi@goffi.org>
parents:
3522
diff
changeset
|
623 condition, text=text, appCondition=appCondition |
3522
41a6c144dc90
core (xmpp): added `appCondition` argument to `sendError`
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
624 ).toResponse(iq_elt) |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
625 self.xmlstream.send(iq_error_elt) |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
626 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
627 def generate_message_xml( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
628 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
629 data: core_types.MessageData, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
630 post_xml_treatments: Optional[defer.Deferred] = None, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
631 ) -> core_types.MessageData: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
632 """Generate <message/> stanza from message data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
633 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
634 @param data: message data |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
635 domish element will be put in data['xml'] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
636 following keys are needed: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
637 - from |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
638 - to |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
639 - uid: can be set to '' if uid attribute is not wanted |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
640 - message |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
641 - type |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
642 - subject |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
643 - extra |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
644 @param post_xml_treatments: a Deferred which will be called with data once XML is |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
645 generated |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
646 @return: message data |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
647 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
648 data["xml"] = message_elt = domish.Element((None, "message")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
649 message_elt["to"] = data["to"].full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
650 message_elt["from"] = data["from"].full() |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
651 message_elt["type"] = data["type"] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
652 if data["uid"]: # key must be present but can be set to '' |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
653 # by a plugin to avoid id on purpose |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
654 message_elt["id"] = data["uid"] |
3028 | 655 for lang, subject in data["subject"].items(): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
656 subject_elt = message_elt.addElement("subject", content=subject) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
657 if lang: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
658 subject_elt[(C.NS_XML, "lang")] = lang |
3028 | 659 for lang, message in data["message"].items(): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
660 body_elt = message_elt.addElement("body", content=message) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
661 if lang: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
662 body_elt[(C.NS_XML, "lang")] = lang |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
663 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
664 thread = data["extra"]["thread"] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
665 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
666 if "thread_parent" in data["extra"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
667 raise exceptions.InternalError( |
3028 | 668 "thread_parent found while there is not associated thread" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
669 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
670 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
671 thread_elt = message_elt.addElement("thread", content=thread) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
672 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
673 thread_elt["parent"] = data["extra"]["thread_parent"] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
674 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
675 pass |
3221
b1c90eedbc12
core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
Goffi <goffi@goffi.org>
parents:
3203
diff
changeset
|
676 |
b1c90eedbc12
core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
Goffi <goffi@goffi.org>
parents:
3203
diff
changeset
|
677 if post_xml_treatments is not None: |
b1c90eedbc12
core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
Goffi <goffi@goffi.org>
parents:
3203
diff
changeset
|
678 post_xml_treatments.callback(data) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
679 return data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
680 |
3777
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
681 @property |
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
682 def is_admin(self) -> bool: |
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
683 """True if a client is an administrator with extra privileges""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
684 return self.host_app.memory.is_admin(self.profile) |
3777
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
685 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
686 def add_post_xml_callbacks(self, post_xml_treatments): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
687 """Used to add class level callbacks at the end of the workflow |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
688 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
689 @param post_xml_treatments(D): the same Deferred as in sendMessage trigger |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
690 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
691 raise NotImplementedError |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
692 |
4297
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
693 async def a_send(self, obj: domish.Element) -> None: |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
694 # original send method accept string |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
695 # but we restrict to domish.Element to make trigger treatments easier |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
696 assert isinstance(obj, domish.Element) |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
697 # XXX: this trigger is the last one before sending stanza on wire |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
698 # it is intended for things like end 2 end encryption. |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
699 # *DO NOT* cancel (i.e. return False) without very good reason |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
700 # (out of band transmission for instance). |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
701 # e2e should have a priority of 0 here, and out of band transmission |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
702 # a lower priority |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
703 if not (await self.host_app.trigger.async_point("send", self, obj)): |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
704 return |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
705 super().send(obj) |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
706 |
4297
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
707 def send(self, obj: domish.Element): |
3913
944f51f9c2b4
core (xmpp): make `send` a blocking method, fix `sendMessageData` calls:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
708 defer.ensureDeferred(self.a_send(obj)) |
944f51f9c2b4
core (xmpp): make `send` a blocking method, fix `sendMessageData` calls:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
709 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
710 async def send_message_data(self, mess_data): |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
711 """Convenient method to send message data to stream |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
712 |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
713 This method will send mess_data[u'xml'] to stream, but a trigger is there |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
714 The trigger can't be cancelled, it's a good place for e2e encryption which |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
715 don't handle full stanza encryption |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
716 This trigger can return a Deferred (it's an async_point) |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
717 @param mess_data(dict): message data as constructed by onMessage workflow |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
718 @return (dict): mess_data (so it can be used in a deferred chain) |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
719 """ |
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4297
diff
changeset
|
720 # XXX: This is the last trigger before "send" (last but one globally) |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
721 # for sending message. |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
722 # This is intented for e2e encryption which doesn't do full stanza |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
723 # encryption (e.g. OTR) |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
724 # This trigger point can't cancel the method |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
725 await self.host_app.trigger.async_point( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
726 "send_message_data", self, mess_data, triggers_no_cancel=True |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
727 ) |
3913
944f51f9c2b4
core (xmpp): make `send` a blocking method, fix `sendMessageData` calls:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
728 await self.a_send(mess_data["xml"]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
729 return mess_data |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
730 |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3175
diff
changeset
|
731 def sendMessage( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
732 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
733 to_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
734 message, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
735 subject=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
736 mess_type="auto", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
737 extra=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
738 uid=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
739 no_trigger=False, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
740 ): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
741 r"""Send a message to an entity |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
742 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
743 @param to_jid(jid.JID): destinee of the message |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
744 @param message(dict): message body, key is the language (use '' when unknown) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
745 @param subject(dict): message subject, key is the language (use '' when unknown) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
746 @param mess_type(str): one of standard message type (cf RFC 6121 §5.2.2) or: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
747 - auto: for automatic type detection |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
748 - info: for information ("info_type" can be specified in extra) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
749 @param extra(dict, None): extra data. Key can be: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
750 - info_type: information type, can be |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
751 TODO |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
752 @param uid(unicode, None): unique id: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
753 should be unique at least in this XMPP session |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
754 if None, an uuid will be generated |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
755 @param no_trigger (bool): if True, sendMessage[suffix] trigger will no be used |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
756 useful when a message need to be sent without any modification |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
757 /!\ this will also skip encryption methods! |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
758 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
759 if subject is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
760 subject = {} |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
761 if extra is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
762 extra = {} |
2460
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
763 |
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
764 assert mess_type in C.MESS_TYPE_ALL |
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
765 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
766 data = { # dict is similar to the one used in client.onMessage |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
767 "from": self.jid, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
768 "to": to_jid, |
3028 | 769 "uid": uid or str(uuid.uuid4()), |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
770 "message": message, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
771 "subject": subject, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
772 "type": mess_type, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
773 "extra": extra, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
774 "timestamp": time.time(), |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
775 } |
2645 | 776 # XXX: plugin can add their pre XML treatments to this deferred |
777 pre_xml_treatments = defer.Deferred() | |
778 # XXX: plugin can add their post XML treatments to this deferred | |
779 post_xml_treatments = defer.Deferred() | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
780 |
2460
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
781 if data["type"] == C.MESS_TYPE_AUTO: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
782 # we try to guess the type |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
783 if data["subject"]: |
2460
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
784 data["type"] = C.MESS_TYPE_NORMAL |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
785 elif not data["to"].resource: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
786 # we may have a groupchat message, we check if the we know this jid |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
787 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
788 entity_type = self.host_app.memory.get_entity_datum( |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
789 self, data["to"], C.ENTITY_TYPE |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2985
diff
changeset
|
790 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
791 # FIXME: should entity_type manage resources ? |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
792 except (exceptions.UnknownEntityError, KeyError): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
793 entity_type = "contact" |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
794 |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2985
diff
changeset
|
795 if entity_type == C.ENTITY_TYPE_MUC: |
2460
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
796 data["type"] = C.MESS_TYPE_GROUPCHAT |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
797 else: |
2460
feaacc462fef
core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
798 data["type"] = C.MESS_TYPE_CHAT |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
799 else: |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3777
diff
changeset
|
800 data["type"] = C.MESS_TYPE_CHAT |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
801 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
802 # FIXME: send_only is used by libervia's OTR plugin to avoid |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
803 # the triggers from frontend, and no_trigger do the same |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
804 # thing internally, this could be unified |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
805 send_only = data["extra"].get("send_only", False) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
806 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
807 if not no_trigger and not send_only: |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
808 # is the session encrypted? If so we indicate it in data |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
809 self.encryption.set_encryption_flag(data) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
810 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
811 if not self.host_app.trigger.point( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
812 "sendMessage" + self.trigger_suffix, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
813 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
814 data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
815 pre_xml_treatments, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
816 post_xml_treatments, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
817 ): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
818 return defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
819 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
820 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
821 _("Sending message (type {type}, to {to})").format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
822 type=data["type"], to=to_jid.full() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
823 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
824 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
825 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
826 pre_xml_treatments.addCallback( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
827 lambda __: self.generate_message_xml(data, post_xml_treatments) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
828 ) |
3221
b1c90eedbc12
core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
Goffi <goffi@goffi.org>
parents:
3203
diff
changeset
|
829 pre_xml_treatments.addCallback(lambda __: post_xml_treatments) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
830 pre_xml_treatments.addErrback(self._cancel_error_trap) |
3913
944f51f9c2b4
core (xmpp): make `send` a blocking method, fix `sendMessageData` calls:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
831 post_xml_treatments.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
832 lambda __: defer.ensureDeferred(self.send_message_data(data)) |
3913
944f51f9c2b4
core (xmpp): make `send` a blocking method, fix `sendMessageData` calls:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
833 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
834 if send_only: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
835 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
836 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
837 "Triggers, storage and echo have been inhibited by the " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
838 "'send_only' parameter" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
839 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
840 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
841 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
842 self.add_post_xml_callbacks(post_xml_treatments) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
843 post_xml_treatments.addErrback(self._cancel_error_trap) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
844 post_xml_treatments.addErrback(self.host_app.log_errback) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
845 pre_xml_treatments.callback(data) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
846 return pre_xml_treatments |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
847 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
848 def _cancel_error_trap(self, failure): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
849 """A message sending can be cancelled by a plugin treatment""" |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
850 failure.trap(exceptions.CancelError) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
851 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
852 def is_message_printable(self, mess_data): |
3173
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
853 """Return True if a message contain payload to show in frontends""" |
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
854 return ( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
855 mess_data["message"] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
856 or mess_data["subject"] |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4021
diff
changeset
|
857 or mess_data["extra"].get(C.KEY_ATTACHMENTS) |
3173
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
858 or mess_data["type"] == C.MESS_TYPE_INFO |
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
859 ) |
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
860 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
861 async def message_add_to_history(self, data): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
862 """Store message into database (for local history) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
863 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
864 @param data: message data dictionnary |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
865 @param client: profile's client |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
866 """ |
3028 | 867 if data["type"] != C.MESS_TYPE_GROUPCHAT: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
868 # we don't add groupchat message to history, as we get them back |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
869 # and they will be added then |
3173
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
870 |
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
871 # we need a message to store |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
872 if self.is_message_printable(data): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
873 await self.host_app.memory.add_to_history(self, data) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
874 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
875 log.warning( |
3028 | 876 "No message found" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
877 ) # empty body should be managed by plugins before this point |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
878 return data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
879 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
880 def message_get_bridge_args(self, data): |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
881 """Generate args to use with bridge from data dict""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
882 return ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
883 data["uid"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
884 data["timestamp"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
885 data["from"].full(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
886 data["to"].full(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
887 data["message"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
888 data["subject"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
889 data["type"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
890 data_format.serialise(data["extra"]), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
891 ) |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
892 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
893 def message_send_to_bridge(self, data): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
894 """Send message to bridge, so frontends can display it |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
895 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
896 @param data: message data dictionnary |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
897 """ |
3028 | 898 if data["type"] != C.MESS_TYPE_GROUPCHAT: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
899 # we don't send groupchat message to bridge, as we get them back |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
900 # and they will be added the |
3173
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
901 |
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
902 # we need a message to send something |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
903 if self.is_message_printable(data): |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
904 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
905 # We send back the message, so all frontends are aware of it |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
906 self.host_app.bridge.message_new( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
907 *self.message_get_bridge_args(data), profile=self.profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
908 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
909 else: |
3028 | 910 log.warning(_("No message found")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
911 return data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
912 |
3249
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
913 ## helper methods ## |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
914 |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
915 def p(self, plugin_name, missing=exceptions.MissingModule): |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
916 """Get a plugin if available |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
917 |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
918 @param plugin_name(str): name of the plugin |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
919 @param missing(object): value to return if plugin is missing |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
920 if it is a subclass of Exception, it will be raised with a helping str as |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
921 argument. |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
922 @return (object): requested plugin wrapper, or default value |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
923 The plugin wrapper will return the method with client set as first |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
924 positional argument |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
925 """ |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
926 return ClientPluginWrapper(self, plugin_name, missing) |
f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
Goffi <goffi@goffi.org>
parents:
3244
diff
changeset
|
927 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
928 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
929 ExtraDict = dict # TODO |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
930 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
931 |
3028 | 932 @implementer(iwokkel.IDisco) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
933 class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
934 trigger_suffix = "" |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
935 is_component = False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
936 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
937 def __init__( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
938 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
939 host_app, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
940 profile, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
941 user_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
942 password, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
943 host=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
944 port=C.XMPP_C2S_PORT, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
945 max_retries=C.XMPP_MAX_RETRIES, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
946 ): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
947 # XXX: DNS SRV records are checked when the host is not specified. |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
948 # If no SRV record is found, the host is directly extracted from the JID. |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
949 self.started = time.time() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
950 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
951 # Currently, we use "client/pc/Salut à Toi", but as |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
952 # SàT is multi-frontends and can be used on mobile devices, as a bot, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
953 # with a web frontend, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
954 # etc., we should implement a way to dynamically update identities through the |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
955 # bridge |
3028 | 956 self.identities = [disco.DiscoIdentity("client", "pc", C.APP_NAME)] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
957 if sys.platform == "android": |
2594
59ba387c17ea
core (xmpp): use "phone" type in identities when backend is started from Android
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
958 # for now we consider Android devices to be always phones |
3028 | 959 self.identities = [disco.DiscoIdentity("client", "phone", C.APP_NAME)] |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
960 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
961 hosts_map = host_app.memory.config_get(None, "hosts_dict", {}) |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
962 if host is None and user_jid.host in hosts_map: |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
963 host_data = hosts_map[user_jid.host] |
3028 | 964 if isinstance(host_data, str): |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
965 host = host_data |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
966 elif isinstance(host_data, dict): |
3028 | 967 if "host" in host_data: |
968 host = host_data["host"] | |
969 if "port" in host_data: | |
970 port = host_data["port"] | |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
971 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
972 log.warning( |
3028 | 973 _("invalid data used for host: {data}").format(data=host_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
974 ) |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
975 host_data = None |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
976 if host_data is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
977 log.info( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
978 "using {host}:{port} for host {host_ori} as requested in config".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
979 host_ori=user_jid.host, host=host, port=port |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
980 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
981 ) |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
982 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
983 self.check_certificate = host_app.memory.param_get_a( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
984 "check_certificate", "Connection", profile_key=profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
985 ) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
986 |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
987 if self.check_certificate: |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
988 tls_required, configurationForTLS = True, None |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
989 else: |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
990 tls_required = False |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
991 configurationForTLS = ssl.CertificateOptions(trustRoot=None) |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
992 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
993 wokkel_client.XMPPClient.__init__( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
994 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
995 user_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
996 password, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
997 host or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
998 port or C.XMPP_C2S_PORT, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
999 tls_required=tls_required, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1000 configurationForTLS=configurationForTLS, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1001 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1002 SatXMPPEntity.__init__(self, host_app, profile, max_retries) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1003 |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
1004 if not self.check_certificate: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1005 msg = _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1006 "Certificate validation is deactivated, this is unsecure and " |
3028 | 1007 "somebody may be spying on you. If you have no good reason to disable " |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1008 'certificate validation, please activate "Check certificate" in your ' |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1009 'settings in "Connection" tab.' |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1010 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1011 xml_tools.quick_note( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1012 host_app, self, msg, _("Security notice"), level=C.XMLUI_DATA_LVL_WARNING |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1013 ) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
1014 |
3749
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1015 @property |
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1016 def server_jid(self): |
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1017 return jid.JID(self.jid.host) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
1018 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1019 def _get_plugins_list(self): |
3028 | 1020 for p in self.host_app.plugins.values(): |
1021 if C.PLUG_MODE_CLIENT in p._info["modes"]: | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1022 yield p |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1023 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1024 def _create_sub_protocols(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1025 self.messageProt = SatMessageProtocol(self.host_app) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1026 self.messageProt.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1027 |
4107
bc7d45dedeb0
backend: rename `SatRosterProtocol` to `LiberviaRosterProtocol`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1028 self.roster = LiberviaRosterProtocol(self.host_app) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1029 self.roster.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1030 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1031 self.presence = SatPresenceProtocol(self.host_app) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1032 self.presence.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1033 |
2915 | 1034 @classmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1035 async def start_connection(cls, host, profile, max_retries): |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
1036 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1037 await super(SatXMPPClient, cls).start_connection(host, profile, max_retries) |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
1038 except exceptions.CancelError as e: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1039 log.warning(f"start_connection cancelled: {e}") |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
1040 return |
2915 | 1041 entity = host.profiles[profile] |
1042 # we finally send our presence | |
1043 entity.presence.available() | |
1044 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1045 def entity_connected(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1046 # we want to be sure that we got the roster |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1047 return self.roster.got_roster |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1048 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1049 def add_post_xml_callbacks(self, post_xml_treatments): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1050 post_xml_treatments.addCallback(self.messageProt.complete_attachments) |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
1051 post_xml_treatments.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1052 lambda ret: defer.ensureDeferred(self.message_add_to_history(ret)) |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
1053 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1054 post_xml_treatments.addCallback(self.message_send_to_bridge) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1055 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
1056 def feedback( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1057 self, to_jid: jid.JID, message: str, extra: Optional[ExtraDict] = None |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
1058 ) -> None: |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
1059 """Send message to frontends |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
1060 |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
1061 This message will be an info message, not recorded in history. |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
1062 It can be used to give feedback of a command |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
1063 @param to_jid: destinee jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
1064 @param message: message to send to frontends |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
1065 @param extra: extra data to use in particular, info subtype can be specified with |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3795
diff
changeset
|
1066 MESS_EXTRA_INFO |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
1067 """ |
2748
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
1068 if extra is None: |
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
1069 extra = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1070 self.host_app.bridge.message_new( |
3028 | 1071 uid=str(uuid.uuid4()), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1072 timestamp=time.time(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1073 from_jid=self.jid.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1074 to_jid=to_jid.full(), |
3028 | 1075 message={"": message}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1076 subject={}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1077 mess_type=C.MESS_TYPE_INFO, |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3162
diff
changeset
|
1078 extra=data_format.serialise(extra), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1079 profile=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1080 ) |
2130
f0bc29dc8157
added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents:
2113
diff
changeset
|
1081 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1082 def _finish_connection(self, __): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1083 d = self.roster.request_roster() |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1084 d.addCallback(lambda __: super(SatXMPPClient, self)._finish_connection(__)) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1085 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1086 |
3028 | 1087 @implementer(iwokkel.IDisco) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1088 class SatXMPPComponent(SatXMPPEntity, component.Component): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1089 """XMPP component |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1090 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1091 This component are similar but not identical to clients. |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1092 An entry point plugin is launched after component is connected. |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1093 Component need to instantiate MessageProtocol itself |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1094 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1095 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1096 trigger_suffix = ( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1097 "Component" # used for to distinguish some trigger points set in SatXMPPEntity |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1098 ) |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1099 is_component = True |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1100 # XXX: set to True from entry plugin to keep messages in history for sent messages |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1101 sendHistory = False |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1102 # XXX: same as sendHistory but for received messaged |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1103 receiveHistory = False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1104 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1105 def __init__( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1106 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1107 host_app, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1108 profile, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1109 component_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1110 password, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1111 host=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1112 port=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1113 max_retries=C.XMPP_MAX_RETRIES, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1114 ): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1115 self.started = time.time() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1116 if port is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1117 port = C.XMPP_COMPONENT_PORT |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1118 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1119 ## entry point ## |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1120 entry_point = host_app.memory.get_entry_point(profile) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1121 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1122 self.entry_plugin = host_app.plugins[entry_point] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1123 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1124 raise exceptions.NotFound( |
3028 | 1125 _("The requested entry point ({entry_point}) is not available").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1126 entry_point=entry_point |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1127 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1128 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1129 |
4021
412b99c29d83
core (xmpp), component file sharing, plugin XEP-0363: `enabled_features` + HTTP Upload:
Goffi <goffi@goffi.org>
parents:
4000
diff
changeset
|
1130 self.enabled_features = set() |
3028 | 1131 self.identities = [disco.DiscoIdentity("component", "generic", C.APP_NAME)] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1132 # jid is set automatically on bind by Twisted for Client, but not for Component |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1133 self.jid = component_jid |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1134 if host is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1135 try: |
3028 | 1136 host = component_jid.host.split(".", 1)[1] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1137 except IndexError: |
3028 | 1138 raise ValueError("Can't guess host from jid, please specify a host") |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1139 # XXX: component.Component expect unicode jid, while Client expect jid.JID. |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1140 # this is not consistent, so we use jid.JID for SatXMPP* |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1141 component.Component.__init__(self, host, port, component_jid.full(), password) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1142 SatXMPPEntity.__init__(self, host_app, profile, max_retries) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1143 |
3749
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1144 @property |
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1145 def server_jid(self): |
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1146 # FIXME: not the best way to get server jid, maybe use config option? |
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1147 return jid.JID(self.jid.host.split(".", 1)[-1]) |
9581098b64f0
core (xmpp): add a `server_jid` property
Goffi <goffi@goffi.org>
parents:
3736
diff
changeset
|
1148 |
3777
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
1149 @property |
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
1150 def is_admin(self) -> bool: |
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
1151 return False |
001ea5f4a2f9
core: method to know if a profile/entity is an admin:
Goffi <goffi@goffi.org>
parents:
3749
diff
changeset
|
1152 |
4297
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1153 def is_local(self, jid_: jid.JID) -> bool: |
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1154 """Returns True if jid_ use a domain or subdomain of component's host""" |
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1155 local_host = self.host.split(".") |
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1156 assert local_host |
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1157 return jid_.host.split(".")[-len(local_host) :] == local_host |
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1158 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1159 def _create_sub_protocols(self): |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1160 self.messageProt = SatMessageProtocol(self.host_app) |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1161 self.messageProt.setHandlerParent(self) |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1162 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1163 def _build_dependencies(self, current, plugins, required=True): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1164 """build recursively dependencies needed for a plugin |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
1165 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1166 this method build list of plugin needed for a component and raises |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1167 errors if they are not available or not allowed for components |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1168 @param current(object): parent plugin to check |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1169 use entry_point for first call |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1170 @param plugins(list): list of validated plugins, will be filled by the method |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1171 give an empty list for first call |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1172 @param required(bool): True if plugin is mandatory |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1173 for recursive calls only, should not be modified by inital caller |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1174 @raise InternalError: one of the plugin is not handling components |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1175 @raise KeyError: one plugin should be present in self.host_app.plugins but it |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1176 is not |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1177 """ |
3028 | 1178 if C.PLUG_MODE_COMPONENT not in current._info["modes"]: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1179 if not required: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1180 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1181 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1182 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1183 _( |
3028 | 1184 "Plugin {current_name} is needed for {entry_name}, " |
1185 "but it doesn't handle component mode" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1186 ).format( |
3028 | 1187 current_name=current._info["import_name"], |
1188 entry_name=self.entry_plugin._info["import_name"], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1189 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1190 ) |
3028 | 1191 raise exceptions.InternalError(_("invalid plugin mode")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1192 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1193 for import_name in current._info.get(C.PI_DEPENDENCIES, []): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1194 # plugins are already loaded as dependencies |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1195 # so we know they are in self.host_app.plugins |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1196 dep = self.host_app.plugins[import_name] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1197 self._build_dependencies(dep, plugins) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1198 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1199 for import_name in current._info.get(C.PI_RECOMMENDATIONS, []): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1200 # here plugins are only recommendations, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1201 # so they may not exist in self.host_app.plugins |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1202 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1203 dep = self.host_app.plugins[import_name] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1204 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1205 continue |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1206 self._build_dependencies(dep, plugins, required=False) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1207 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1208 if current not in plugins: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1209 # current can be required for several plugins and so |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1210 # it can already be present in the list |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1211 plugins.append(current) |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
1212 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1213 def _get_plugins_list(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1214 # XXX: for component we don't launch all plugins triggers |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1215 # but only the ones from which there is a dependency |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1216 plugins = [] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1217 self._build_dependencies(self.entry_plugin, plugins) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1218 return plugins |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1219 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1220 def entity_connected(self): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1221 # we can now launch entry point |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1222 try: |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1223 start_cb = self.entry_plugin.componentStart |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1224 except AttributeError: |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1225 return |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1226 else: |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
1227 return start_cb(self) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1228 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1229 def add_post_xml_callbacks(self, post_xml_treatments): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1230 if self.sendHistory: |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
1231 post_xml_treatments.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1232 lambda ret: defer.ensureDeferred(self.message_add_to_history(ret)) |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
1233 ) |
0 | 1234 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1235 def get_owner_from_jid(self, to_jid: jid.JID) -> jid.JID: |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1236 """Retrieve "owner" of a component resource from the destination jid of the request |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1237 |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1238 This method needs plugin XEP-0106 for unescaping, if you use it you must add the |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1239 plugin to your dependencies. |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1240 A "user" part must be present in "to_jid" (otherwise, the component itself is addressed) |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1241 @param to_jid: destination JID of the request |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1242 """ |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1243 try: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1244 unescape = self.host_app.plugins["XEP-0106"].unescape |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1245 except KeyError: |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1246 raise exceptions.MissingPlugin("Plugin XEP-0106 is needed to retrieve owner") |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1247 else: |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1248 user = unescape(to_jid.user) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1249 if "@" in user: |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1250 # a full jid is specified |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1251 return jid.JID(user) |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1252 else: |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1253 # only user part is specified, we use our own host to build the full jid |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1254 return jid.JID(None, (user, self.host, None)) |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1255 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1256 def get_owner_and_peer(self, iq_elt: domish.Element) -> Tuple[jid.JID, jid.JID]: |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1257 """Retrieve owner of a component jid, and the jid of the requesting peer |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1258 |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1259 "owner" is found by either unescaping full jid from node, or by combining node |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1260 with our host. |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1261 Peer jid is the requesting jid from the IQ element |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1262 @param iq_elt: IQ stanza sent from the requested |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1263 @return: owner and peer JIDs |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1264 """ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1265 to_jid = jid.JID(iq_elt["to"]) |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1266 if to_jid.user: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1267 owner = self.get_owner_from_jid(to_jid) |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1268 else: |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1269 owner = jid.JID(iq_elt["from"]).userhostJID() |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1270 |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1271 peer_jid = jid.JID(iq_elt["from"]) |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1272 return peer_jid, owner |
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1273 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1274 def get_virtual_client(self, jid_: jid.JID) -> SatXMPPEntity: |
3736
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1275 """Get client for this component with a specified jid |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1276 |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1277 This is needed to perform operations with a virtual JID corresponding to a virtual |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1278 entity (e.g. identified of a legacy network account) instead of the JID of the |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1279 gateway itself. |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1280 @param jid_: virtual JID to use |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1281 @return: virtual client |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1282 """ |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1283 client = copy.copy(self) |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1284 client.jid = jid_ |
e52de21873d3
core (xmpp): new `getVirtualClient` for components:
Goffi <goffi@goffi.org>
parents:
3715
diff
changeset
|
1285 return client |
3366
e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents:
3316
diff
changeset
|
1286 |
0 | 1287 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1288 class SatMessageProtocol(xmppim.MessageProtocol): |
2714
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1289 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1290 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1291 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1292 self.host = host |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1293 self.messages_queue = defer.DeferredQueue() |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1294 |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1295 def setHandlerParent(self, parent): |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1296 super().setHandlerParent(parent) |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1297 defer.ensureDeferred(self.process_messages()) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1298 |
3197
f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
Goffi <goffi@goffi.org>
parents:
3196
diff
changeset
|
1299 @property |
f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
Goffi <goffi@goffi.org>
parents:
3196
diff
changeset
|
1300 def client(self): |
f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
Goffi <goffi@goffi.org>
parents:
3196
diff
changeset
|
1301 return self.parent |
f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
Goffi <goffi@goffi.org>
parents:
3196
diff
changeset
|
1302 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1303 def normalize_ns(self, elt: domish.Element, namespace: Optional[str]) -> None: |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1304 if elt.uri == namespace: |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1305 elt.defaultUri = elt.uri = C.NS_CLIENT |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1306 for child in elt.elements(): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1307 self.normalize_ns(child, namespace) |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1308 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1309 def parse_message(self, message_elt: domish.Element) -> MessageData: |
3173
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1310 """Parse a message XML and return message_data |
663 | 1311 |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1312 @param message_elt(domish.Element): raw <message> xml |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1313 @param client(SatXMPPClient, None): client to map message id to uid |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1314 if None, mapping will not be done |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1315 @return(dict): message data |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1316 """ |
3028 | 1317 if message_elt.name != "message": |
4297
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1318 log.error( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1319 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1320 "parse_message used with a non <message/> stanza, ignoring: {xml}".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1321 xml=message_elt.toXml() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1322 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1323 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1324 ) |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1325 return {} |
2714
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1326 |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1327 if message_elt.uri == None: |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1328 # xmlns may be None when wokkel element parsing strip out root namespace |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1329 self.normalize_ns(message_elt, None) |
2714
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1330 elif message_elt.uri != C.NS_CLIENT: |
4297
0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
1331 log.error( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1332 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1333 "received <message> with a wrong namespace: {xml}".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1334 xml=message_elt.toXml() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1335 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1336 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1337 ) |
2714
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1338 |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1339 client = self.parent |
2731
a58e380c1c37
core (xmpp): set "to" attribute to <message> element when it's missing:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1340 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1341 if not message_elt.hasAttribute("to"): |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1342 message_elt["to"] = client.jid.full() |
2731
a58e380c1c37
core (xmpp): set "to" attribute to <message> element when it's missing:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1343 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1344 message = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1345 subject = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1346 extra = {} |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1347 data: MessageData = { |
3028 | 1348 "from": jid.JID(message_elt["from"]), |
1349 "to": jid.JID(message_elt["to"]), | |
1350 "uid": message_elt.getAttribute( | |
1351 "uid", str(uuid.uuid4()) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1352 ), # XXX: uid is not a standard attribute but may be added by plugins |
3028 | 1353 "message": message, |
1354 "subject": subject, | |
1355 "type": message_elt.getAttribute("type", "normal"), | |
1356 "extra": extra, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1357 } |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1358 |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1359 try: |
3028 | 1360 message_id = data["extra"]["message_id"] = message_elt["id"] |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1361 except KeyError: |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1362 pass |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1363 else: |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1364 client.mess_id2uid[(data["from"], message_id)] = data["uid"] |
663 | 1365 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1366 # message |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1367 for e in message_elt.elements(C.NS_CLIENT, "body"): |
3028 | 1368 message[e.getAttribute((C.NS_XML, "lang"), "")] = str(e) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1369 |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1370 # subject |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1371 for e in message_elt.elements(C.NS_CLIENT, "subject"): |
3028 | 1372 subject[e.getAttribute((C.NS_XML, "lang"), "")] = str(e) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1373 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1374 # delay and timestamp |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1375 try: |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1376 received_timestamp = message_elt._received_timestamp |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1377 except AttributeError: |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1378 # message_elt._received_timestamp should have been set in onMessage |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1379 # but if parse_message is called directly, it can be missing |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1380 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1381 "missing received timestamp for {message_elt}".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1382 message_elt=message_elt |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1383 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1384 ) |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1385 received_timestamp = time.time() |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1386 |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1387 try: |
3028 | 1388 delay_elt = next(message_elt.elements(delay.NS_DELAY, "delay")) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1389 except StopIteration: |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1390 data["timestamp"] = received_timestamp |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1391 else: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1392 parsed_delay = delay.Delay.fromElement(delay_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1393 data["timestamp"] = calendar.timegm(parsed_delay.stamp.utctimetuple()) |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1394 data["received_timestamp"] = received_timestamp |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1395 if parsed_delay.sender: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1396 data["delay_sender"] = parsed_delay.sender.full() |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1397 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1398 self.host.trigger.point("message_parse", client, message_elt, data) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1399 return data |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1400 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1401 def onMessage(self, message_elt: domish.Element) -> None: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1402 message_elt._received_timestamp = time.time() |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1403 self.messages_queue.put(message_elt) |
2645 | 1404 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1405 async def process_messages(self) -> None: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1406 """Process message in order |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1407 |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1408 Messages are processed in a queue to avoid race conditions and ensure orderly |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1409 processing. |
2645 | 1410 """ |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1411 client = self.parent |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1412 if client is None: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1413 log.error("client should not be None!") |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1414 raise exceptions.InternalError() |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1415 while True: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1416 message_elt = await self.messages_queue.get() |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1417 try: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1418 await self.process_message(client, message_elt) |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1419 except Exception: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1420 log.exception(f"Can't process message {message_elt.toXml()}") |
2645 | 1421 |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1422 def _on_processing_timeout( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1423 self, message_elt: domish.Element, async_point_d: defer.Deferred |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1424 ) -> None: |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1425 log.error( |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1426 "Processing of following message took too long, cancelling:" |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1427 f"{message_elt.toXml()}" |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1428 ) |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1429 async_point_d.cancel() |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1430 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1431 async def process_message( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1432 self, client: SatXMPPEntity, message_elt: domish.Element |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1433 ) -> None: |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1434 # TODO: handle threads |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1435 if not "from" in message_elt.attributes: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1436 message_elt["from"] = client.jid.host |
3028 | 1437 log.debug(_("got message from: {from_}").format(from_=message_elt["from"])) |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1438 if self.client.is_component and message_elt.uri == component.NS_COMPONENT_ACCEPT: |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
1439 # we use client namespace all the time to simplify parsing |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1440 self.normalize_ns(message_elt, component.NS_COMPONENT_ACCEPT) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1441 |
2645 | 1442 # plugin can add their treatments to this deferred |
1443 post_treat = defer.Deferred() | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1444 async_point_d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1445 self.host.trigger.async_point( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1446 "message_received", client, message_elt, post_treat |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1447 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1448 ) |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1449 # message_received triggers block the messages queue, so they must not take too |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1450 # long to proceed. |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1451 delayed_call = reactor.callLater( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1452 10, self._on_processing_timeout, message_elt, async_point_d |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1453 ) |
4265
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1454 trigger_ret_continue = await async_point_d |
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1455 |
4230
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1456 if delayed_call.active(): |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1457 delayed_call.cancel() |
314d3c02bb67
core (xmpp): Add a timeout for messages processing to avoid blocking the queue.
Goffi <goffi@goffi.org>
parents:
4182
diff
changeset
|
1458 log.debug(f"delayed_call for {async_point_d} cancelled") |
4265
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1459 |
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1460 if not trigger_ret_continue: |
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1461 # trigger returned False, we stop the workflow. |
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1462 return |
2417ad1d0f23
core (xmpp): fix message workflow interruption from trigger.
Goffi <goffi@goffi.org>
parents:
4230
diff
changeset
|
1463 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1464 try: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1465 data = self.parse_message(message_elt) |
4168
d67eaa684484
core (message): fix calling of post treatments during message workflow
Goffi <goffi@goffi.org>
parents:
4151
diff
changeset
|
1466 # we now do all post treatments added by plugins |
d67eaa684484
core (message): fix calling of post treatments during message workflow
Goffi <goffi@goffi.org>
parents:
4151
diff
changeset
|
1467 post_treat.callback(data) |
d67eaa684484
core (message): fix calling of post treatments during message workflow
Goffi <goffi@goffi.org>
parents:
4151
diff
changeset
|
1468 await post_treat |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1469 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1470 self.complete_attachments(data) |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1471 if not data["message"] and not data["extra"] and not data["subject"]: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1472 raise exceptions.CancelError("Cancelled empty message") |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1473 if not client.is_component or client.receiveHistory: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1474 await self.add_to_history(data) |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1475 if not client.is_component: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1476 self.bridge_signal(data) |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1477 except exceptions.CancelError: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1478 pass |
663 | 1479 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1480 def complete_attachments(self, data: MessageData) -> MessageData: |
3175
b9a2dd4d750a
core (xmpp): add `name` and `media_type` in attachements if they are missing.
Goffi <goffi@goffi.org>
parents:
3173
diff
changeset
|
1481 """Complete missing metadata of attachments""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1482 for attachment in data["extra"].get(C.KEY_ATTACHMENTS, []): |
3920
993cc8e56aef
core (xmpp): check presence of some keys in attachment before using them:
Goffi <goffi@goffi.org>
parents:
3913
diff
changeset
|
1483 if "name" not in attachment and "url" in attachment: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1484 name = ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1485 Path(unquote(urlparse(attachment["url"]).path)).name |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1486 or C.FILE_DEFAULT_NAME |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1487 ) |
3175
b9a2dd4d750a
core (xmpp): add `name` and `media_type` in attachements if they are missing.
Goffi <goffi@goffi.org>
parents:
3173
diff
changeset
|
1488 attachment["name"] = name |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1489 if C.KEY_ATTACHMENTS_MEDIA_TYPE not in attachment and "name" in attachment: |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1490 media_type = mimetypes.guess_type(attachment["name"], strict=False)[0] |
3175
b9a2dd4d750a
core (xmpp): add `name` and `media_type` in attachements if they are missing.
Goffi <goffi@goffi.org>
parents:
3173
diff
changeset
|
1491 if media_type: |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4021
diff
changeset
|
1492 attachment[C.KEY_ATTACHMENTS_MEDIA_TYPE] = media_type |
3175
b9a2dd4d750a
core (xmpp): add `name` and `media_type` in attachements if they are missing.
Goffi <goffi@goffi.org>
parents:
3173
diff
changeset
|
1493 return data |
b9a2dd4d750a
core (xmpp): add `name` and `media_type` in attachements if they are missing.
Goffi <goffi@goffi.org>
parents:
3173
diff
changeset
|
1494 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1495 async def add_to_history(self, data: MessageData) -> MessageData: |
3028 | 1496 if data.pop("history", None) == C.HISTORY_SKIP: |
3059
aa728dc7b0ce
core: `history is skipped as requested` log message is now at debug level
Goffi <goffi@goffi.org>
parents:
3044
diff
changeset
|
1497 log.debug("history is skipped as requested") |
3028 | 1498 data["extra"]["history"] = C.HISTORY_SKIP |
2132
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2130
diff
changeset
|
1499 else: |
3173
343b8076e967
core (xmpp): new message key to handle attachments
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1500 # we need a message to store |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1501 if self.parent.is_message_printable(data): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1502 return await self.host.memory.add_to_history(self.parent, data) |
2751
286a32a187e7
core (xmpp): don't add to history a message if there is no message and no subject.
Goffi <goffi@goffi.org>
parents:
2748
diff
changeset
|
1503 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1504 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1505 "not storing empty message to history: {data}".format(data=data) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1506 ) |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1507 return data |
663 | 1508 |
4151
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1509 def bridge_signal(self, data: MessageData) -> MessageData: |
18026ce0819c
core (xmpp): message reception workflow refactoring:
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
1510 """Send signal to frontends for the given message""" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1511 try: |
3028 | 1512 data["extra"]["received_timestamp"] = str(data["received_timestamp"]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1513 data["extra"]["delay_sender"] = data["delay_sender"] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1514 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1515 pass |
3228
cc3fea71c365
core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra:
Goffi <goffi@goffi.org>
parents:
3226
diff
changeset
|
1516 if self.client.encryption.isEncrypted(data): |
cc3fea71c365
core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra:
Goffi <goffi@goffi.org>
parents:
3226
diff
changeset
|
1517 data["extra"]["encrypted"] = True |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1518 if data is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1519 if self.parent.is_message_printable(data): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1520 self.host.bridge.message_new( |
2736
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1521 data["uid"], |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1522 data["timestamp"], |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1523 data["from"].full(), |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1524 data["to"].full(), |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1525 data["message"], |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1526 data["subject"], |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1527 data["type"], |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3162
diff
changeset
|
1528 data_format.serialise(data["extra"]), |
2736
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1529 profile=self.parent.profile, |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1530 ) |
df2bc2e704bc
core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents:
2731
diff
changeset
|
1531 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1532 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1533 "Discarding bridge signal for empty message: {data}".format(data=data) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1534 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1535 return data |
1053
71d63750963e
core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents:
1037
diff
changeset
|
1536 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1537 |
4107
bc7d45dedeb0
backend: rename `SatRosterProtocol` to `LiberviaRosterProtocol`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1538 class LiberviaRosterProtocol(xmppim.RosterClientProtocol): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1539 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1540 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1541 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1542 self.host = host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1543 self.got_roster = defer.Deferred() # called when roster is received and ready |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1544 # XXX: the two following dicts keep a local copy of the roster |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1545 self._jids = {} # map from jids to RosterItem: key=jid value=RosterItem |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1546 self._groups = {} # map from groups to jids: key=group value=set of jids |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1547 |
3389
c3943afb4cac
core (xmpp): client.roster now implements __contains__
Goffi <goffi@goffi.org>
parents:
3383
diff
changeset
|
1548 def __contains__(self, entity_jid): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1549 return self.is_jid_in_roster(entity_jid) |
3389
c3943afb4cac
core (xmpp): client.roster now implements __contains__
Goffi <goffi@goffi.org>
parents:
3383
diff
changeset
|
1550 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1551 @property |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1552 def versioning(self): |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1553 """True if server support roster versioning""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1554 return (NS_ROSTER_VER, "ver") in self.parent.xmlstream.features |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1555 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1556 @property |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1557 def roster_cache(self): |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1558 """Cache of roster from storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1559 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1560 This property return a new PersistentDict on each call, it must be loaded |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1561 manually if necessary |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1562 """ |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1563 return persistent.PersistentDict(NS_ROSTER_VER, self.parent.profile) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1564 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1565 def _register_item(self, item): |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1566 """Register item in local cache |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1567 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1568 item must be already registered in self._jids before this method is called |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1569 @param item (RosterIem): item added |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1570 """ |
3028 | 1571 log.debug("registering item: {}".format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1572 if item.entity.resource: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1573 log.warning( |
3028 | 1574 "Received a roster item with a resource, this is not common but not " |
1575 "restricted by RFC 6121, this case may be not well tested." | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1576 ) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1577 if not item.subscriptionTo: |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1578 if not item.subscriptionFrom: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1579 log.info( |
3028 | 1580 _("There's no subscription between you and [{}]!").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1581 item.entity.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1582 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1583 ) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1584 else: |
3028 | 1585 log.info(_("You are not subscribed to [{}]!").format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1586 if not item.subscriptionFrom: |
3028 | 1587 log.info(_("[{}] is not subscribed to you!").format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1588 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1589 for group in item.groups: |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1590 self._groups.setdefault(group, set()).add(item.entity) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1591 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1592 @defer.inlineCallbacks |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1593 def _cache_roster(self, version): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1594 """Serialise local roster and save it to storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1595 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1596 @param version(unicode): version of roster in local cache |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1597 """ |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1598 roster_cache = self.roster_cache |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1599 yield roster_cache.clear() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1600 roster_cache[ROSTER_VER_KEY] = version |
3028 | 1601 for roster_jid, roster_item in self._jids.items(): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1602 roster_jid_s = roster_jid.full() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1603 roster_item_elt = roster_item.toElement().toXml() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1604 roster_cache[roster_jid_s] = roster_item_elt |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1605 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1606 @defer.inlineCallbacks |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1607 def resync(self): |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1608 """Ask full roster to resync database |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1609 |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1610 this should not be necessary, but may be used if user suspsect roster |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1611 to be somehow corrupted |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1612 """ |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1613 roster_cache = self.roster_cache |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1614 yield roster_cache.clear() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1615 self._jids.clear() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1616 self._groups.clear() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1617 yield self.request_roster() |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1618 |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1619 @defer.inlineCallbacks |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1620 def request_roster(self): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1621 """Ask the server for Roster list""" |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1622 if self.versioning: |
3028 | 1623 log.info(_("our server support roster versioning, we use it")) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1624 roster_cache = self.roster_cache |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1625 yield roster_cache.load() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1626 try: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1627 version = roster_cache[ROSTER_VER_KEY] |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1628 except KeyError: |
3028 | 1629 log.info(_("no roster in cache, we start fresh")) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1630 # u"" means we use versioning without valid roster in cache |
3028 | 1631 version = "" |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1632 else: |
3028 | 1633 log.info(_("We have roster v{version} in cache").format(version=version)) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1634 # we deserialise cached roster to our local cache |
3028 | 1635 for roster_jid_s, roster_item_elt_s in roster_cache.items(): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1636 if roster_jid_s == ROSTER_VER_KEY: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1637 continue |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1638 roster_jid = jid.JID(roster_jid_s) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1639 roster_item_elt = generic.parseXml(roster_item_elt_s.encode("utf-8")) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1640 roster_item = xmppim.RosterItem.fromElement(roster_item_elt) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1641 self._jids[roster_jid] = roster_item |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1642 self._register_item(roster_item) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1643 else: |
3028 | 1644 log.warning(_("our server doesn't support roster versioning")) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1645 version = None |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1646 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1647 log.debug("requesting roster") |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1648 roster = yield self.getRoster(version=version) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1649 if roster is None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1650 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1651 "empty roster result received, we'll get roster item with roster " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1652 "pushes" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1653 ) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1654 else: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1655 # a full roster is received |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1656 self._groups.clear() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1657 self._jids = roster |
3028 | 1658 for item in roster.values(): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1659 if not item.subscriptionTo and not item.subscriptionFrom and not item.ask: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1660 # XXX: current behaviour: we don't want contact in our roster list |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1661 # if there is no presence subscription |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1662 # may change in the future |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1663 log.info( |
3028 | 1664 "Removing contact {} from roster because there is no presence " |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1665 "subscription".format(item.jid) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1666 ) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1667 self.removeItem(item.entity) # FIXME: to be checked |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1668 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1669 self._register_item(item) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1670 yield self._cache_roster(roster.version) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1671 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1672 if not self.got_roster.called: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1673 # got_roster may already be called if we use resync() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1674 self.got_roster.callback(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1675 |
875
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1676 def removeItem(self, to_jid): |
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1677 """Remove a contact from roster list |
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1678 @param to_jid: a JID instance |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1679 @return: Deferred |
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:
341
diff
changeset
|
1680 """ |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1681 return xmppim.RosterClientProtocol.removeItem(self, to_jid) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1682 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1683 def get_attributes(self, item): |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1684 """Return dictionary of attributes as used in bridge from a RosterItem |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1685 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1686 @param item: RosterItem |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1687 @return: dictionary of attributes |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1688 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1689 item_attr = { |
3028 | 1690 "to": str(item.subscriptionTo), |
1691 "from": str(item.subscriptionFrom), | |
1692 "ask": str(item.ask), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1693 } |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1694 if item.name: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1695 item_attr["name"] = item.name |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1696 return item_attr |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1697 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1698 def setReceived(self, request): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1699 item = request.item |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1700 entity = item.entity |
3028 | 1701 log.info(_("adding {entity} to roster").format(entity=entity.full())) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1702 if request.version is not None: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1703 # we update the cache in storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1704 roster_cache = self.roster_cache |
2901
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1705 roster_cache[entity.full()] = item.toElement().toXml() |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1706 roster_cache[ROSTER_VER_KEY] = request.version |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1707 |
1427
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1708 try: # update the cache for the groups the contact has been removed from |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1709 left_groups = set(self._jids[entity].groups).difference(item.groups) |
1427
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1710 for group in left_groups: |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1711 jids_set = self._groups[group] |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1712 jids_set.remove(entity) |
1427
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1713 if not jids_set: |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1714 del self._groups[group] |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1715 except KeyError: |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
1716 pass # no previous item registration (or it's been cleared) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1717 self._jids[entity] = item |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1718 self._register_item(item) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1719 self.host.bridge.contact_new( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1720 entity.full(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1721 self.get_attributes(item), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1722 list(item.groups), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1723 self.parent.profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1724 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1725 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1726 def removeReceived(self, request): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1727 entity = request.item.entity |
3028 | 1728 log.info(_("removing {entity} from roster").format(entity=entity.full())) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1729 if request.version is not None: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1730 # we update the cache in storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1731 roster_cache = self.roster_cache |
2901
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1732 try: |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1733 del roster_cache[request.item.entity.full()] |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1734 except KeyError: |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1735 # because we don't use load(), cache won't have the key, but it |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1736 # will be deleted from storage anyway |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1737 pass |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1738 roster_cache[ROSTER_VER_KEY] = request.version |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1739 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1740 # we first remove item from local cache (self._groups and self._jids) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1741 try: |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1742 item = self._jids.pop(entity) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1743 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1744 log.error( |
3028 | 1745 "Received a roster remove event for an item not in cache ({})".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1746 entity |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1747 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1748 ) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1749 return |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1750 for group in item.groups: |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1751 try: |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1752 jids_set = self._groups[group] |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1753 jids_set.remove(entity) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1754 if not jids_set: |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1755 del self._groups[group] |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1756 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1757 log.warning( |
3316
5369ce5bcecf
core (xmpp): text can now be specified in `sendError`
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
1758 f"there is no cache for the group [{group}] of the removed roster " |
5369ce5bcecf
core (xmpp): text can now be specified in `sendError`
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
1759 f"item [{entity}]" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1760 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1761 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1762 # then we send the bridge signal |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1763 self.host.bridge.contact_deleted(entity.full(), self.parent.profile) |
50 | 1764 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1765 def get_groups(self): |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1766 """Return a list of groups""" |
3028 | 1767 return list(self._groups.keys()) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1768 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1769 def get_item(self, entity_jid): |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1770 """Return RosterItem for a given jid |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1771 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1772 @param entity_jid(jid.JID): jid of the contact |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1773 @return(RosterItem, None): RosterItem instance |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1774 None if contact is not in cache |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1775 """ |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
1776 return self._jids.get(entity_jid, None) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1777 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1778 def get_jids(self): |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1779 """Return all jids of the roster""" |
3028 | 1780 return list(self._jids.keys()) |
487 | 1781 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1782 def is_jid_in_roster(self, entity_jid): |
487 | 1783 """Return True if jid is in roster""" |
3197
f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
Goffi <goffi@goffi.org>
parents:
3196
diff
changeset
|
1784 if not isinstance(entity_jid, jid.JID): |
f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
Goffi <goffi@goffi.org>
parents:
3196
diff
changeset
|
1785 raise exceptions.InternalError( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1786 f"a JID is expected, not {type(entity_jid)}: {entity_jid!r}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1787 ) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1788 return entity_jid in self._jids |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1789 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1790 def is_subscribed_from(self, entity_jid: jid.JID) -> bool: |
2139
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1791 """Return True if entity is authorised to see our presence""" |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1792 try: |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1793 item = self._jids[entity_jid.userhostJID()] |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1794 except KeyError: |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1795 return False |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1796 return item.subscriptionFrom |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1797 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1798 def is_subscribed_to(self, entity_jid: jid.JID) -> bool: |
3585
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1799 """Return True if we are subscribed to entity""" |
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1800 try: |
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1801 item = self._jids[entity_jid.userhostJID()] |
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1802 except KeyError: |
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1803 return False |
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1804 return item.subscriptionTo |
31628770a15a
core (xmpp): renamed `SatRosterProtocol.presenceSubscribed` to `isSubscribedFrom` (and added `isSubscribedTo`)
Goffi <goffi@goffi.org>
parents:
3573
diff
changeset
|
1805 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1806 def get_items(self): |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1807 """Return all items of the roster""" |
3028 | 1808 return list(self._jids.values()) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1809 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1810 def get_jids_from_group(self, group): |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1811 try: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1812 return self._groups[group] |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1813 except KeyError: |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
1814 raise exceptions.UnknownGroupError(group) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1815 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1816 def get_jids_set(self, type_, groups=None): |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1817 """Helper method to get a set of jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1818 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1819 @param type_(unicode): one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1820 C.ALL: get all jids from roster |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1821 C.GROUP: get jids from groups (listed in "groups") |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1822 @groups(list[unicode]): list of groups used if type_==C.GROUP |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1823 @return (set(jid.JID)): set of selected jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1824 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1825 if type_ == C.ALL and groups is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1826 raise ValueError("groups must not be set for {} type".format(C.ALL)) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1827 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1828 if type_ == C.ALL: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1829 return set(self.get_jids()) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1830 elif type_ == C.GROUP: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1831 jids = set() |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1832 for group in groups: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1833 jids.update(self.get_jids_from_group(group)) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1834 return jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1835 else: |
3028 | 1836 raise ValueError("Unexpected type_ {}".format(type_)) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1837 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1838 def get_nick(self, entity_jid): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1839 """Return a nick name for an entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1840 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1841 return nick choosed by user if available |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1842 else return user part of entity_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1843 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1844 item = self.get_item(entity_jid) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1845 if item is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1846 return entity_jid.user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1847 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1848 return item.name or entity_jid.user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1849 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
1850 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1851 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1852 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1853 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1854 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1855 self.host = host |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1856 |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1857 @property |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1858 def client(self): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1859 return self.parent |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1860 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
1861 def send(self, obj): |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
1862 presence_d = defer.succeed(None) |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
1863 if not self.host.trigger.point("Presence send", self.parent, obj, presence_d): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
1864 return |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
1865 presence_d.addCallback(lambda __: super(SatPresenceProtocol, self).send(obj)) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1866 return presence_d |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
1867 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1868 def availableReceived(self, entity, show=None, statuses=None, priority=0): |
334
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
1869 if not statuses: |
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
1870 statuses = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1871 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1872 if None in statuses: # we only want string keys |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1873 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1874 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1875 if not self.host.trigger.point( |
2820
7ab8684784c6
core: renamed presenceReceived to presence_reveiced + use "client" as first arguments instead of "profile"
Goffi <goffi@goffi.org>
parents:
2794
diff
changeset
|
1876 "presence_received", self.parent, entity, show, priority, statuses |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1877 ): |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
1878 return |
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
1879 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1880 self.host.memory.set_presence_status( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1881 entity, show or "", int(priority), statuses, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1882 ) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1883 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1884 # now it's time to notify frontends |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1885 self.host.bridge.presence_update( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1886 entity.full(), show or "", int(priority), statuses, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1887 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1888 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1889 def unavailableReceived(self, entity, statuses=None): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1890 log.debug( |
3028 | 1891 _("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1892 % {"entity": entity, C.PRESENCE_STATUSES: statuses} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1893 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1894 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
1895 if not statuses: |
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
1896 statuses = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1897 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1898 if None in statuses: # we only want string keys |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1899 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1900 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1901 if not self.host.trigger.point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1902 "presence_received", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1903 self.parent, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1904 entity, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1905 C.PRESENCE_UNAVAILABLE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1906 0, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1907 statuses, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1908 ): |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1167
diff
changeset
|
1909 return |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1167
diff
changeset
|
1910 |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1911 # now it's time to notify frontends |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1912 # if the entity is not known yet in this session or is already unavailable, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1913 # there is no need to send an unavailable signal |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1914 try: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
1915 presence = self.host.memory.get_entity_datum(self.client, entity, "presence") |
1690
772c8edd1057
core: fixed cache check on presence unavailable
Goffi <goffi@goffi.org>
parents:
1685
diff
changeset
|
1916 except (KeyError, exceptions.UnknownEntityError): |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1917 # the entity has not been seen yet in this session |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1918 pass |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1919 else: |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1920 if presence.show != C.PRESENCE_UNAVAILABLE: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1921 self.host.bridge.presence_update( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1922 entity.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1923 C.PRESENCE_UNAVAILABLE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1924 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1925 statuses, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1926 self.parent.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1927 ) |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
1928 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1929 self.host.memory.set_presence_status( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1930 entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1931 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1932 |
611 | 1933 def available(self, entity=None, show=None, statuses=None, priority=None): |
1434
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1934 """Set a presence and statuses. |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1935 |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1936 @param entity (jid.JID): entity |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1937 @param show (unicode): value in ('unavailable', '', 'away', 'xa', 'chat', 'dnd') |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1938 @param statuses (dict{unicode: unicode}): multilingual statuses with |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1939 the entry key beeing a language code on 2 characters or "default". |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1940 """ |
611 | 1941 if priority is None: |
1942 try: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1943 priority = int( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1944 self.host.memory.param_get_a( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1945 "Priority", "Connection", profile_key=self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1946 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1947 ) |
611 | 1948 except ValueError: |
1949 priority = 0 | |
1950 | |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1951 if statuses is None: |
562
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
1952 statuses = {} |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1953 |
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1954 # default for us is None for wokkel |
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1955 # so we must temporarily switch to wokkel's convention... |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1956 if C.PRESENCE_STATUSES_DEFAULT in statuses: |
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1957 statuses[None] = statuses.pop(C.PRESENCE_STATUSES_DEFAULT) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
1958 |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1959 presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
1960 |
562
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
1961 # ... before switching back |
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
1962 if None in statuses: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1963 statuses["default"] = statuses.pop(None) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
1964 |
1167
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
1965 if not self.host.trigger.point("presence_available", presence_elt, self.parent): |
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
1966 return |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3249
diff
changeset
|
1967 return self.send(presence_elt) |
1167
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
1968 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1969 @defer.inlineCallbacks |
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:
341
diff
changeset
|
1970 def subscribed(self, entity): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1971 yield self.parent.roster.got_roster |
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:
341
diff
changeset
|
1972 xmppim.PresenceClientProtocol.subscribed(self, entity) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1973 self.host.memory.del_waiting_sub(entity.userhost(), self.parent.profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1974 item = self.parent.roster.get_item(entity) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1975 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1976 not item or not item.subscriptionTo |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1977 ): # we automatically subscribe to 'to' presence |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
1978 log.debug(_('sending automatic "from" subscription request')) |
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:
341
diff
changeset
|
1979 self.subscribe(entity) |
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:
341
diff
changeset
|
1980 |
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:
341
diff
changeset
|
1981 def unsubscribed(self, entity): |
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:
341
diff
changeset
|
1982 xmppim.PresenceClientProtocol.unsubscribed(self, entity) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1983 self.host.memory.del_waiting_sub(entity.userhost(), self.parent.profile) |
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:
341
diff
changeset
|
1984 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1985 def subscribedReceived(self, entity): |
3028 | 1986 log.debug(_("subscription approved for [%s]") % entity.userhost()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1987 self.host.bridge.subscribe("subscribed", entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1988 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1989 def unsubscribedReceived(self, entity): |
3028 | 1990 log.debug(_("unsubscription confirmed for [%s]") % entity.userhost()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1991 self.host.bridge.subscribe("unsubscribed", entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1992 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1993 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1994 def subscribeReceived(self, entity): |
3028 | 1995 log.debug(_("subscription request from [%s]") % entity.userhost()) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1996 yield self.parent.roster.got_roster |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1997 item = self.parent.roster.get_item(entity) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1998 if item and item.subscriptionTo: |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1999 # We automatically accept subscription if we are already subscribed to |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2000 # contact presence |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2001 log.debug(_("sending automatic subscription acceptance")) |
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:
341
diff
changeset
|
2002 self.subscribed(entity) |
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:
341
diff
changeset
|
2003 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2004 self.host.memory.add_waiting_sub( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2005 "subscribe", entity.userhost(), self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2006 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2007 self.host.bridge.subscribe( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2008 "subscribe", entity.userhost(), self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2009 ) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
2010 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
2011 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
2012 def unsubscribeReceived(self, entity): |
3028 | 2013 log.debug(_("unsubscription asked for [%s]") % entity.userhost()) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
2014 yield self.parent.roster.got_roster |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2015 item = self.parent.roster.get_item(entity) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
2016 if item and item.subscriptionFrom: # we automatically remove contact |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2017 log.debug(_("automatic contact deletion")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2018 self.host.contact_del(entity, self.parent.profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2019 self.host.bridge.subscribe("unsubscribe", entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
2020 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
2021 |
3028 | 2022 @implementer(iwokkel.IDisco) |
14 | 2023 class SatDiscoProtocol(disco.DiscoClientProtocol): |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
2024 |
14 | 2025 def __init__(self, host): |
2026 disco.DiscoClientProtocol.__init__(self) | |
2027 | |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
2028 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2778
f7deb1c36b47
core, XEP-0315: move XML element handling to sat_tmp:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
2029 # those features are implemented in Wokkel (or sat_tmp.wokkel) |
f7deb1c36b47
core, XEP-0315: move XML element handling to sat_tmp:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
2030 # and thus are always available |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
2031 return [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
2032 disco.DiscoFeature(NS_X_DATA), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
2033 disco.DiscoFeature(NS_XML_ELEMENT), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
2034 disco.DiscoFeature(NS_DISCO_INFO), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
2035 ] |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
2036 |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
2037 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
2038 return [] |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
2039 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
2040 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
2041 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
2042 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
2043 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
2044 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
2045 def iqFallback(self, iq): |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
2046 if iq.handled is True: |
292
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
2047 return |
3028 | 2048 log.debug("iqFallback: xml = [%s]" % (iq.toXml())) |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
2049 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
2050 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
2051 |
292
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
2052 class SatVersionHandler(generic.VersionHandler): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2053 |
292
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
2054 def getDiscoInfo(self, requestor, target, node): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2055 # XXX: We need to work around wokkel's behaviour (namespace not added if there |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2056 # is a node) as it cause issues with XEP-0115 & PEP (XEP-0163): there is a |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2057 # node when server ask for disco info, and not when we generate the key, so |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2058 # the hash is used with different disco features, and when the server (seen |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2059 # on ejabberd) generate its own hash for security check it reject our |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2060 # features (resulting in e.g. no notification on PEP) |
292
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
2061 return generic.VersionHandler.getDiscoInfo(self, requestor, target, None) |
666
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
2062 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
2063 |
3028 | 2064 @implementer(iwokkel.IDisco) |
666
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
2065 class SatIdentityHandler(XMPPHandler): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2066 """Manage disco Identity of SàT.""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4265
diff
changeset
|
2067 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2068 # TODO: dynamic identity update (see docstring). Note that a XMPP entity can have |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
2069 # several identities |
666
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
2070 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2071 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
2072 return self.parent.identities |
666
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
2073 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
2074 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
666
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
2075 return [] |