Mercurial > libervia-backend
annotate sat/core/xmpp.py @ 3170:39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Feb 2020 18:13:17 +0100 |
parents | b5c058c7692e |
children | dcebc585c29f |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3162
diff
changeset
|
3 # SàT: a XMPP client |
3136 | 4 # Copyright (C) 2009-2020 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 |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
19 import sys |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
20 import time |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
21 import calendar |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
22 import uuid |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
23 from functools import partial |
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
|
24 import shortuuid |
1053
71d63750963e
core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents:
1037
diff
changeset
|
25 from sat.core.i18n import _ |
923 | 26 from sat.core.constants import Const as C |
2109
85f3e12e984d
core (memory/cache): file caching handling, first draft:
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
27 from sat.memory import cache |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
28 from twisted.internet import defer, error as internet_error |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
29 from twisted.internet import ssl |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
30 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
31 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
|
32 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
|
33 from twisted.words.protocols.jabber import jid |
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
|
34 from twisted.words.xish import domish |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 from twisted.python import failure |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
36 from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
37 from wokkel import component |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
38 from wokkel import delay |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
39 from sat.core.log import getLogger |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
40 from sat.core import exceptions |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
41 from sat.memory import encryption |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
42 from sat.memory import persistent |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
43 from sat.tools import xml_tools |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3162
diff
changeset
|
44 from sat.tools.common import data_format |
3028 | 45 from zope.interface import implementer |
0 | 46 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
47 log = getLogger(__name__) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
48 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
49 |
3028 | 50 NS_X_DATA = "jabber:x:data" |
51 NS_DISCO_INFO = "http://jabber.org/protocol/disco#info" | |
52 NS_XML_ELEMENT = "urn:xmpp:xml-element" | |
53 NS_ROSTER_VER = "urn:xmpp:features:rosterver" | |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
54 # 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
|
55 # with roster jids |
3028 | 56 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
|
57 |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
58 |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
59 class SatXMPPEntity: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
60 """Common code for Client and Component""" |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
61 # profile is added there when startConnection begins and removed when it is finished |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
62 profiles_connecting = set() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
63 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
64 def __init__(self, host_app, profile, max_retries): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
65 factory = self.factory |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
66 |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
67 # we monkey patch clientConnectionLost to handle networkEnabled/networkDisabled |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
68 # and to allow plugins to tune reconnection mechanism |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
69 clientConnectionFailed_ori = factory.clientConnectionFailed |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
70 clientConnectionLost_ori = factory.clientConnectionLost |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
71 factory.clientConnectionFailed = partial( |
3028 | 72 self.connectionTerminated, term_type="failed", cb=clientConnectionFailed_ori) |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
73 factory.clientConnectionLost = partial( |
3028 | 74 self.connectionTerminated, term_type="lost", cb=clientConnectionLost_ori) |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
75 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
76 factory.maxRetries = max_retries |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
77 factory.maxDelay = 30 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
78 # 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
|
79 # 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
|
80 self._connected_d = None |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
81 self.profile = profile |
64 | 82 self.host_app = host_app |
2109
85f3e12e984d
core (memory/cache): file caching handling, first draft:
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
83 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
|
84 self.mess_id2uid = {} # map from message id to uid used in history. |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
85 # Key: (full_jid, message_id) Value: uid |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
86 # this Deferred fire when entity is connected |
341 | 87 self.conn_deferred = defer.Deferred() |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
88 self._progress_cb = {} # callback called when a progress is requested |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
89 # (key = progress id) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
90 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
|
91 self.encryption = encryption.EncryptionHandler(self) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
92 |
3040 | 93 def __str__(self): |
94 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
|
95 |
3040 | 96 def __repr__(self): |
97 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
|
98 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
99 ## initialisation ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
100 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
101 @defer.inlineCallbacks |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
102 def _callConnectionTriggers(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
103 """Call conneting trigger prepare connected trigger |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
104 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
105 @param plugins(iterable): plugins to use |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
106 @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
|
107 - plugin instance |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
108 - profileConnected* triggers (to call after connection) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
109 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
110 plugin_conn_cb = [] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
111 for plugin in self._getPluginsList(): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
112 # we check if plugin handle client mode |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
113 if plugin.is_handler: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
114 plugin.getHandler(self).setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
115 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
116 # profileConnecting/profileConnected methods handling |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
117 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
118 # profile connecting is called right now (before actually starting client) |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
119 connecting_cb = getattr(plugin, "profileConnecting", None) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
120 if connecting_cb is not None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
121 yield connecting_cb(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
122 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
123 # profile connected is called after client is ready and roster is got |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
124 connected_cb = getattr(plugin, "profileConnected", None) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
125 if connected_cb is not None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
126 plugin_conn_cb.append((plugin, connected_cb)) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
127 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
128 defer.returnValue(plugin_conn_cb) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
129 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
130 def _getPluginsList(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
131 """Return list of plugin to use |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
132 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
133 need to be implemented by subclasses |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
134 this list is used to call profileConnect* triggers |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
135 @return(iterable[object]): plugins to use |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
136 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
137 raise NotImplementedError |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
138 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
139 def _createSubProtocols(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
140 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
141 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
142 def entityConnected(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
143 """Called once connection is done |
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 may return a Deferred, to perform initialisation tasks |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
146 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
147 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
148 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
149 @classmethod |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
150 @defer.inlineCallbacks |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
151 def startConnection(cls, host, profile, max_retries): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
152 """instantiate the entity and start the connection""" |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
153 # FIXME: reconnection doesn't seems to be handled correclty |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
154 # (client is deleted then recreated from scratch) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
155 # 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
|
156 # (e.g. adding subprotocols) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
157 # 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
|
158 # (independently of connection/deconnection) |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
159 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
|
160 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
|
161 cls.profiles_connecting.add(profile) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
162 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
163 port = int( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
164 host.memory.getParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
165 C.FORCE_PORT_PARAM, "Connection", profile_key=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
166 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
167 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
168 except ValueError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
169 log.debug(_("Can't parse port value, using default value")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
170 port = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
171 None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
172 ) # will use default value 5222 or be retrieved from a DNS SRV record |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
173 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
174 password = yield host.memory.asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
175 "Password", "Connection", profile_key=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
176 ) |
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
|
177 |
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
|
178 entity_jid_s = yield host.memory.asyncGetParamA( |
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
|
179 "JabberID", "Connection", profile_key=profile) |
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
|
180 entity_jid = jid.JID(entity_jid_s) |
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
|
181 |
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
|
182 if not entity_jid.resource and not cls.is_component and entity_jid.user: |
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
|
183 # if no resource is specified, we create our own instead of using |
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
|
184 # server returned one, as it will then stay stable in case of reconnection. |
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
|
185 # we only do that for client and if there is a user part, to let server |
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
|
186 # decide for anonymous login |
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
|
187 resource_dict = yield host.memory.storage.getPrivates( |
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
|
188 "core:xmpp", ["resource"] , profile=profile) |
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
|
189 try: |
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
|
190 resource = resource_dict["resource"] |
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
|
191 except KeyError: |
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
|
192 resource = f"{C.APP_NAME_FILE}.{shortuuid.uuid()}" |
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
|
193 yield host.memory.storage.setPrivateValue( |
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
|
194 "core:xmpp", "resource", resource, profile=profile) |
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
|
195 |
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
|
196 log.info(_("We'll use the stable resource {resource}").format( |
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
|
197 resource=resource)) |
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
|
198 entity_jid.resource = resource |
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
|
199 |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
200 if profile in host.profiles: |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
201 raise exceptions.InternalError( |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
202 f"There is already a profile of name {profile} in host") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
203 entity = host.profiles[profile] = cls( |
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
|
204 host, profile, entity_jid, password, |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
205 host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
206 profile_key=profile) or None, |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
207 port, max_retries, |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
208 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
209 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
210 entity._createSubProtocols() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
211 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
212 entity.fallBack = SatFallbackHandler(host) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
213 entity.fallBack.setHandlerParent(entity) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
214 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
215 entity.versionHandler = SatVersionHandler(C.APP_NAME_FULL, host.full_version) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
216 entity.versionHandler.setHandlerParent(entity) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
217 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
218 entity.identityHandler = SatIdentityHandler() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
219 entity.identityHandler.setHandlerParent(entity) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
220 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
221 log.debug(_("setting plugins parents")) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
222 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
223 plugin_conn_cb = yield entity._callConnectionTriggers() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
224 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
225 entity.startService() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
226 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
227 yield entity.conn_deferred |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
228 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
229 yield defer.maybeDeferred(entity.entityConnected) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
230 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
231 # Call profileConnected callback for all plugins, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
232 # and print error message if any of them fails |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
233 conn_cb_list = [] |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
234 for __, callback in plugin_conn_cb: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
235 conn_cb_list.append(defer.maybeDeferred(callback, entity)) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
236 list_d = defer.DeferredList(conn_cb_list) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
237 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
238 def logPluginResults(results): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
239 all_succeed = all([success for success, result in results]) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
240 if not all_succeed: |
3028 | 241 log.error(_("Plugins initialisation error")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
242 for idx, (success, result) in enumerate(results): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
243 if not success: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
244 log.error( |
3028 | 245 "error (plugin %(name)s): %(failure)s" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
246 % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
247 "name": plugin_conn_cb[idx][0]._info["import_name"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
248 "failure": result, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
249 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
250 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
251 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
252 yield list_d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
253 logPluginResults |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
254 ) # FIXME: we should have a timeout here, and a way to know if a plugin freeze |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
255 # TODO: mesure launch time of each plugin |
341 | 256 |
3153
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
257 cls.profiles_connecting.remove(profile) |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
258 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
259 def _disconnectionCb(self, __): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
260 self._connected_d = None |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
261 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
262 def _disconnectionEb(self, failure_): |
3028 | 263 log.error(_("Error while disconnecting: {}".format(failure_))) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
264 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
265 def _authd(self, xmlstream): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
266 super(SatXMPPEntity, self)._authd(xmlstream) |
3028 | 267 log.debug(_("{profile} identified").format(profile=self.profile)) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
268 self.streamInitialized() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
269 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
270 def _finish_connection(self, __): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
271 self.conn_deferred.callback(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
272 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
273 def streamInitialized(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
274 """Called after _authd""" |
3028 | 275 log.debug(_("XML stream is initialized")) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
276 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
|
277 return |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
278 self.postStreamInit() |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
279 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
280 def postStreamInit(self): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
281 """Workflow after stream initalisation.""" |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
282 log.info( |
3028 | 283 _("********** [{profile}] CONNECTED **********").format(profile=self.profile) |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
284 ) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
285 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
286 # 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
|
287 # 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
|
288 self._connected_d = defer.Deferred() |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
289 self._connected_d.addCallback(self._cleanConnection) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
290 self._connected_d.addCallback(self._disconnectionCb) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
291 self._connected_d.addErrback(self._disconnectionEb) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
292 |
2894
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
293 # we send the signal to the clients |
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
294 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
|
295 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
296 self.disco = SatDiscoProtocol(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
297 self.disco.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
298 self.discoHandler = disco.DiscoHandler() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
299 self.discoHandler.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
300 disco_d = defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
301 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
302 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
|
303 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
304 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
305 disco_d.addCallback(self._finish_connection) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
306 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
307 def initializationFailed(self, reason): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
308 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
309 _( |
3028 | 310 "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
|
311 % {"profile": self.profile, "reason": reason} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
312 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
313 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
314 self.conn_deferred.errback(reason.value) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
315 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
316 super(SatXMPPEntity, self).initializationFailed(reason) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
317 except: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
318 # 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
|
319 pass |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
320 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
321 ## connection ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
322 |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
323 def connectionTerminated(self, connector, reason, term_type, cb): |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
324 """Display disconnection reason, and call factory method |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
325 |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
326 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
|
327 reconnection with the triggers. |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
328 @param connector(twisted.internet.base.BaseConnector): current connector |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
329 @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
|
330 @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
|
331 @param cb(callable): original factory method |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
332 |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
333 @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
|
334 @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
|
335 anymore |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
336 """ |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
337 # 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
|
338 # if reconnection is disabled |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
339 self._saved_connector = connector |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
340 if reason is not None and not isinstance(reason.value, |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
341 internet_error.ConnectionDone): |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
342 try: |
3028 | 343 reason_str = str(reason.value) |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
344 except Exception: |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
345 # FIXME: workaround for Android were p4a strips docstrings |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
346 # while Twisted use docstring in __str__ |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
347 # 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
|
348 # is used |
3028 | 349 reason_str = str(reason.value.__class__) |
350 log.warning("Connection {term_type}: {reason}".format( | |
2885
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
351 term_type = term_type, |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
352 reason=reason_str)) |
3028 | 353 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
|
354 return |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
355 return cb(connector, reason) |
e9016bfd8cb2
core (xmpp): advanced handling of connection termination
Goffi <goffi@goffi.org>
parents:
2884
diff
changeset
|
356 |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
357 def networkDisabled(self): |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
358 """Indicate that network has been completely disabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
359 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
360 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
|
361 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
|
362 use resources (notably battery on mobiles). |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
363 """ |
3028 | 364 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
|
365 self.factory.continueTrying = 0 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
366 self._network_disabled = True |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
367 if self.xmlstream is not None: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
368 self.xmlstream.transport.abortConnection() |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
369 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
370 def networkEnabled(self): |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
371 """Indicate that network has been (re)enabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
372 |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
373 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
|
374 """ |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
375 try: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
376 connector = self._saved_connector |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
377 network_disabled = self._network_disabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
378 except AttributeError: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
379 # connection has not been stopped by networkDisabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
380 # 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
|
381 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
|
382 return |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
383 else: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
384 del self._network_disabled |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
385 if not network_disabled: |
3028 | 386 raise exceptions.InternalError("network_disabled should be True") |
387 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
|
388 # we want to be sure to start fresh |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
389 self.factory.resetDelay() |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
390 # 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
|
391 # we can now try to reconnect |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
392 connector.connect() |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
393 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
394 def _connected(self, xs): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
395 send_hooks = [] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
396 receive_hooks = [] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
397 self.host_app.trigger.point( |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
398 "stream_hooks", self, receive_hooks, send_hooks) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
399 for hook in receive_hooks: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
400 xs.addHook(C.STREAM_HOOK_RECEIVE, hook) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
401 for hook in send_hooks: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
402 xs.addHook(C.STREAM_HOOK_SEND, hook) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
403 super(SatXMPPEntity, self)._connected(xs) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
404 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
405 def disconnectProfile(self, reason): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
406 if self._connected_d is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
407 self.host_app.bridge.disconnected( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
408 self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
409 ) # we send the signal to the clients |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
410 log.info( |
3028 | 411 _("********** [{profile}] DISCONNECTED **********").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
412 profile=self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
413 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
414 ) |
3135
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
415 # 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
|
416 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
|
417 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
|
418 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
|
419 # and we remove references to this client |
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
420 self.host_app.purgeEntity(self.profile) |
b9395c4df8b9
core (xmpp): don't purge entity on disconnect if continueTrying is set
Goffi <goffi@goffi.org>
parents:
3125
diff
changeset
|
421 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
422 if not self.conn_deferred.called: |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
423 if reason is None: |
3028 | 424 err = error.StreamError("Server unexpectedly closed the connection") |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
425 else: |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
426 err = reason |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
427 try: |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
428 if err.value.args[0][0][2] == "certificate verify failed": |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
429 err = exceptions.InvalidCertificate( |
3028 | 430 _("Your server certificate is not valid " |
431 "(its identity can't be checked).\n\n" | |
432 "This should never happen and may indicate that " | |
433 "somebody is trying to spy on you.\n" | |
434 "Please contact your server administrator.")) | |
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
|
435 self.factory.stopTrying() |
2886
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
436 try: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
437 # 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
|
438 # so we delete saved connector to avoid reconnection if |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
439 # networkEnabled is called. |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
440 del self._saved_connector |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
441 except AttributeError: |
b06cb71079fa
core (xmpp): new networkEnabled() and networkDisabled() methods:
Goffi <goffi@goffi.org>
parents:
2885
diff
changeset
|
442 pass |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
443 except (IndexError, TypeError): |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
444 pass |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
445 self.conn_deferred.errback(err) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
446 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
447 def _disconnected(self, reason): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
448 super(SatXMPPEntity, self)._disconnected(reason) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
449 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
|
450 return |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
451 self.disconnectProfile(reason) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
452 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
453 @defer.inlineCallbacks |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
454 def _cleanConnection(self, __): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
455 """method called on disconnection |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
456 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
457 used to call profileDisconnected* triggers |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
458 """ |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
459 trigger_name = "profileDisconnected" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
460 for plugin in self._getPluginsList(): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
461 disconnected_cb = getattr(plugin, trigger_name, None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
462 if disconnected_cb is not None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
463 yield disconnected_cb(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
464 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
465 def isConnected(self): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
466 try: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
467 return bool(self.xmlstream.transport.connected) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
468 except AttributeError: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
469 return False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
470 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
471 def entityDisconnect(self): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
472 if not self.host_app.trigger.point("disconnecting", self): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
473 return |
3028 | 474 log.info(_("Disconnecting...")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
475 self.stopService() |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
476 if self._connected_d is not None: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
477 return self._connected_d |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
478 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
479 return defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
480 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
481 ## sending ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
482 |
3028 | 483 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
|
484 """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
|
485 |
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
|
486 @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
|
487 @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
|
488 @return((D)domish.Element: result stanza |
2d633b3c923d
plugin XEP-0231: Bits of Binary first draft:
Goffi <goffi@goffi.org>
parents:
2109
diff
changeset
|
489 errback is called if and 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
|
490 """ |
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
|
491 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
|
492 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
|
493 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
|
494 |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
495 def sendError(self, iq_elt, condition): |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
496 """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
|
497 |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
498 @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
|
499 @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
|
500 """ |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
501 iq_error_elt = error.StanzaError(condition).toResponse(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
|
502 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
|
503 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
504 def generateMessageXML(self, data): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
505 """Generate <message/> stanza from message data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
506 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
507 @param data(dict): message data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
508 domish element will be put in data['xml'] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
509 following keys are needed: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
510 - from |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
511 - to |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
512 - 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
|
513 - message |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
514 - type |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
515 - subject |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
516 - extra |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
517 @return (dict) message data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
518 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
519 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
|
520 message_elt["to"] = data["to"].full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
521 message_elt["from"] = data["from"].full() |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
522 message_elt["type"] = data["type"] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
523 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
|
524 # by a plugin to avoid id on purpose |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
525 message_elt["id"] = data["uid"] |
3028 | 526 for lang, subject in data["subject"].items(): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
527 subject_elt = message_elt.addElement("subject", content=subject) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
528 if lang: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
529 subject_elt[(C.NS_XML, "lang")] = lang |
3028 | 530 for lang, message in data["message"].items(): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
531 body_elt = message_elt.addElement("body", content=message) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
532 if lang: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
533 body_elt[(C.NS_XML, "lang")] = lang |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
534 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
535 thread = data["extra"]["thread"] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
536 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
537 if "thread_parent" in data["extra"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
538 raise exceptions.InternalError( |
3028 | 539 "thread_parent found while there is not associated thread" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
540 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
541 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
542 thread_elt = message_elt.addElement("thread", content=thread) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
543 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
544 thread_elt["parent"] = data["extra"]["thread_parent"] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
545 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
546 pass |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
547 return data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
548 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
549 def addPostXmlCallbacks(self, post_xml_treatments): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
550 """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
|
551 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
552 @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
|
553 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
554 raise NotImplementedError |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
555 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
556 def sendMessage(self, to_jid, message, subject=None, mess_type="auto", extra=None, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
557 uid=None, no_trigger=False,): |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
558 r"""Send a message to an entity |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
559 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
560 @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
|
561 @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
|
562 @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
|
563 @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
|
564 - auto: for automatic type detection |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
565 - 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
|
566 @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
|
567 - info_type: information type, can be |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
568 TODO |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
569 @param uid(unicode, None): unique id: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
570 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
|
571 if None, an uuid will be generated |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
572 @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
|
573 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
|
574 /!\ this will also skip encryption methods! |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
575 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
576 if subject is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
577 subject = {} |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
578 if extra is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
579 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
|
580 |
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
|
581 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
|
582 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
583 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
|
584 "from": self.jid, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
585 "to": to_jid, |
3028 | 586 "uid": uid or str(uuid.uuid4()), |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
587 "message": message, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
588 "subject": subject, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
589 "type": mess_type, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
590 "extra": extra, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
591 "timestamp": time.time(), |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
592 } |
2645 | 593 # XXX: plugin can add their pre XML treatments to this deferred |
594 pre_xml_treatments = defer.Deferred() | |
595 # XXX: plugin can add their post XML treatments to this deferred | |
596 post_xml_treatments = defer.Deferred() | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
597 |
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
|
598 if data["type"] == C.MESS_TYPE_AUTO: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
599 # we try to guess the type |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
600 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
|
601 data["type"] = C.MESS_TYPE_NORMAL |
2645 | 602 elif not data["to"].resource: # if to JID has a resource, |
603 # the type is not 'groupchat' | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
604 # 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
|
605 try: |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2985
diff
changeset
|
606 entity_type = self.host_app.memory.getEntityDatum( |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2985
diff
changeset
|
607 data["to"], C.ENTITY_TYPE, self.profile |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2985
diff
changeset
|
608 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
609 # FIXME: should entity_type manage resources ? |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
610 except (exceptions.UnknownEntityError, KeyError): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
611 entity_type = "contact" |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
612 |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2985
diff
changeset
|
613 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
|
614 data["type"] = C.MESS_TYPE_GROUPCHAT |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
615 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
|
616 data["type"] = C.MESS_TYPE_CHAT |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
617 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
|
618 data["type"] == C.MESS_TYPE_CHAT |
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
|
619 data["type"] == C.MESS_TYPE_CHAT if data["subject"] else C.MESS_TYPE_NORMAL |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
620 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
621 # 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
|
622 # 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
|
623 # thing internally, this could be unified |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
624 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
|
625 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
626 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
|
627 # is the session encrypted? If so we indicate it in data |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
628 self.encryption.setEncryptionFlag(data) |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
629 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
630 if not self.host_app.trigger.point( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
631 "sendMessage" + self.trigger_suffix, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
632 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
633 data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
634 pre_xml_treatments, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
635 post_xml_treatments, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
636 ): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
637 return defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
638 |
3028 | 639 log.debug(_("Sending message (type {type}, to {to})") |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
640 .format(type=data["type"], to=to_jid.full())) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
641 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
642 pre_xml_treatments.addCallback(lambda __: self.generateMessageXML(data)) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
643 pre_xml_treatments.chainDeferred(post_xml_treatments) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
644 post_xml_treatments.addCallback(self.sendMessageData) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
645 if send_only: |
3028 | 646 log.debug(_("Triggers, storage and echo have been inhibited by the " |
647 "'send_only' parameter")) | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
648 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
649 self.addPostXmlCallbacks(post_xml_treatments) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
650 post_xml_treatments.addErrback(self._cancelErrorTrap) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
651 post_xml_treatments.addErrback(self.host_app.logErrback) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
652 pre_xml_treatments.callback(data) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
653 return pre_xml_treatments |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
654 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
655 def _cancelErrorTrap(self, failure): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
656 """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
|
657 failure.trap(exceptions.CancelError) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
658 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
659 def messageAddToHistory(self, data): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
660 """Store message into database (for local history) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
661 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
662 @param data: message data dictionnary |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
663 @param client: profile's client |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
664 """ |
3028 | 665 if data["type"] != C.MESS_TYPE_GROUPCHAT: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
666 # 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
|
667 # and they will be added then |
3028 | 668 if data["message"] or data["subject"]: # we need a message to store |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
669 self.host_app.memory.addToHistory(self, data) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
670 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
671 log.warning( |
3028 | 672 "No message found" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
673 ) # 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
|
674 return data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
675 |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
676 def messageGetBridgeArgs(self, data): |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
677 """Generate args to use with bridge from data dict""" |
3028 | 678 return (data["uid"], data["timestamp"], data["from"].full(), |
679 data["to"].full(), data["message"], data["subject"], | |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3162
diff
changeset
|
680 data["type"], data_format.serialise(data["extra"])) |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
681 |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
682 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
683 def messageSendToBridge(self, data): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
684 """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
|
685 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
686 @param data: message data dictionnary |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
687 @param client: profile's client |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
688 """ |
3028 | 689 if data["type"] != C.MESS_TYPE_GROUPCHAT: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
690 # 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
|
691 # and they will be added the |
3028 | 692 if (data["message"] or data["subject"]): # we need a message to send |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
693 # something |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
694 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
695 # We send back the message, so all frontends are aware of it |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
696 self.host_app.bridge.messageNew( |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
697 *self.messageGetBridgeArgs(data), |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
698 profile=self.profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
699 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
700 else: |
3028 | 701 log.warning(_("No message found")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
702 return data |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
703 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
704 |
3028 | 705 @implementer(iwokkel.IDisco) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
706 class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
707 trigger_suffix = "" |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
708 is_component = False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
709 |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
710 def __init__(self, host_app, profile, user_jid, password, host=None, |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
711 port=C.XMPP_C2S_PORT, max_retries=C.XMPP_MAX_RETRIES): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
712 # 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
|
713 # 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
|
714 self.started = time.time() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
715 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
716 # 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
|
717 # 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
|
718 # with a web frontend, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
719 # 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
|
720 # bridge |
3028 | 721 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
|
722 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
|
723 # for now we consider Android devices to be always phones |
3028 | 724 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
|
725 |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
726 hosts_map = host_app.memory.getConfig(None, "hosts_dict", {}) |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
727 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
|
728 host_data = hosts_map[user_jid.host] |
3028 | 729 if isinstance(host_data, str): |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
730 host = host_data |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
731 elif isinstance(host_data, dict): |
3028 | 732 if "host" in host_data: |
733 host = host_data["host"] | |
734 if "port" in host_data: | |
735 port = host_data["port"] | |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
736 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
737 log.warning( |
3028 | 738 _("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
|
739 ) |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
740 host_data = None |
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
741 if host_data is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
742 log.info( |
3028 | 743 "using {host}:{port} for host {host_ori} as requested in config" |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
744 .format(host_ori=user_jid.host, host=host, port=port) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
745 ) |
2259
f51315500eb1
core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
746 |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
747 self.check_certificate = host_app.memory.getParamA( |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
748 "check_certificate", "Connection", profile_key=profile) |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
749 |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
750 if self.check_certificate: |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
751 tls_required, configurationForTLS = True, None |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
752 else: |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
753 tls_required = False |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
754 configurationForTLS = ssl.CertificateOptions(trustRoot=None) |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
755 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
756 wokkel_client.XMPPClient.__init__( |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
757 self, user_jid, password, host or None, port or C.XMPP_C2S_PORT, |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
758 tls_required=tls_required, configurationForTLS=configurationForTLS |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
759 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
760 SatXMPPEntity.__init__(self, host_app, profile, max_retries) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
761 |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
762 if not self.check_certificate: |
3028 | 763 msg = (_("Certificate validation is deactivated, this is unsecure and " |
764 "somebody may be spying on you. If you have no good reason to disable " | |
765 "certificate validation, please activate \"Check certificate\" in your " | |
766 "settings in \"Connection\" tab.")) | |
767 xml_tools.quickNote(host_app, self, msg, _("Security notice"), | |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
768 level = C.XMLUI_DATA_LVL_WARNING) |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
769 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2661
diff
changeset
|
770 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
771 def _getPluginsList(self): |
3028 | 772 for p in self.host_app.plugins.values(): |
773 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
|
774 yield p |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
775 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
776 def _createSubProtocols(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
777 self.messageProt = SatMessageProtocol(self.host_app) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
778 self.messageProt.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
779 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
780 self.roster = SatRosterProtocol(self.host_app) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
781 self.roster.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
782 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
783 self.presence = SatPresenceProtocol(self.host_app) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
784 self.presence.setHandlerParent(self) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
785 |
2915 | 786 @classmethod |
787 @defer.inlineCallbacks | |
788 def startConnection(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
|
789 try: |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
790 yield super(SatXMPPClient, cls).startConnection(host, profile, max_retries) |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
791 except exceptions.CancelError as e: |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
792 log.warning(f"startConnection cancelled: {e}") |
2c7b42f53e9a
core (xmpp): avoid starting several clients at the same time:
Goffi <goffi@goffi.org>
parents:
3149
diff
changeset
|
793 return |
2915 | 794 entity = host.profiles[profile] |
795 # we finally send our presence | |
796 entity.presence.available() | |
797 | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
798 def entityConnected(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
799 # 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
|
800 return self.roster.got_roster |
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 def addPostXmlCallbacks(self, post_xml_treatments): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
803 post_xml_treatments.addCallback(self.messageAddToHistory) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
804 post_xml_treatments.addCallback(self.messageSendToBridge) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
805 |
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
|
806 def send(self, obj): |
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
|
807 # original send method accept string |
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
|
808 # but we restrict to domish.Element to make trigger treatments easier |
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
|
809 assert isinstance(obj, domish.Element) |
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
|
810 # XXX: this trigger is the last one before sending stanza on wire |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2498
diff
changeset
|
811 # it is intended for things like end 2 end encryption. |
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
|
812 # *DO NOT* cancel (i.e. return False) without very good reason |
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
|
813 # (out of band transmission for instance). |
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
|
814 # e2e should have a priority of 0 here, and out of band transmission |
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
|
815 # a lower priority |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
816 # FIXME: trigger not used yet, can be uncommented when e2e full stanza |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
817 # encryption is implemented |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
818 # if not self.host_app.trigger.point("send", self, obj): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
819 # return |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
820 super(SatXMPPClient, self).send(obj) |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
821 |
2645 | 822 @defer.inlineCallbacks |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
823 def sendMessageData(self, mess_data): |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
824 """Convenient method to send message data to stream |
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
|
825 |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
826 This method will send mess_data[u'xml'] to stream, but a trigger is there |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
827 The trigger can't be cancelled, it's a good place for e2e encryption which |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
828 don't handle full stanza encryption |
2645 | 829 This trigger can return a Deferred (it's an asyncPoint) |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
830 @param mess_data(dict): message data as constructed by onMessage workflow |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
831 @return (dict): mess_data (so it can be used in a deferred chain) |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
832 """ |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
833 # XXX: This is the last trigger before u"send" (last but one globally) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
834 # for sending message. |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
835 # This is intented for e2e encryption which doesn't do full stanza |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
836 # encryption (e.g. OTR) |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
837 # This trigger point can't cancel the method |
2650
3a8e7ec4648a
tools (trigger, async_trigger): added no_cancel argument to point and asyncPoint when a trigger must not be cancellable
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
838 yield self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data, |
3a8e7ec4648a
tools (trigger, async_trigger): added no_cancel argument to point and asyncPoint when a trigger must not be cancellable
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
839 triggers_no_cancel=True) |
3028 | 840 self.send(mess_data["xml"]) |
2645 | 841 defer.returnValue(mess_data) |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
842 |
2748
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
843 def feedback(self, to_jid, message, extra=None): |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
844 """Send message to frontends |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
845 |
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
846 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
|
847 It can be used to give feedback of a command |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
848 @param to_jid(jid.JID): destinee jid |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
849 @param message(unicode): message to send to frontends |
2748
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
850 @param extra(None, dict): extra data to use |
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
851 in particular, info subtype can be specified with MESS_EXTRA_INFO |
2136
cc3a6aea9508
core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
852 """ |
2748
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
853 if extra is None: |
ec9445c04a36
core (xmpp): added "extra" argument to client.feedback
Goffi <goffi@goffi.org>
parents:
2742
diff
changeset
|
854 extra = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
855 self.host_app.bridge.messageNew( |
3028 | 856 uid=str(uuid.uuid4()), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
857 timestamp=time.time(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
858 from_jid=self.jid.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
859 to_jid=to_jid.full(), |
3028 | 860 message={"": message}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
861 subject={}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
862 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
|
863 extra=data_format.serialise(extra), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
864 profile=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
865 ) |
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
|
866 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
867 def _finish_connection(self, __): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
868 d = self.roster.requestRoster() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
869 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
|
870 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
871 |
3028 | 872 @implementer(iwokkel.IDisco) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
873 class SatXMPPComponent(SatXMPPEntity, component.Component): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
874 """XMPP component |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
875 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
876 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
|
877 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
|
878 Component need to instantiate MessageProtocol itself |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
879 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
880 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
881 trigger_suffix = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
882 "Component" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
883 ) # used for to distinguish some trigger points set in SatXMPPEntity |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
884 is_component = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
885 sendHistory = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
886 False |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
887 ) # XXX: set to True from entry plugin to keep messages in history for received |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
888 # messages |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
889 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
890 def __init__(self, host_app, profile, component_jid, password, host=None, port=None, |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
891 max_retries=C.XMPP_MAX_RETRIES): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
892 self.started = time.time() |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
893 if port is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
894 port = C.XMPP_COMPONENT_PORT |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
895 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
896 ## entry point ## |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
897 entry_point = host_app.memory.getEntryPoint(profile) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
898 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
899 self.entry_plugin = host_app.plugins[entry_point] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
900 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
901 raise exceptions.NotFound( |
3028 | 902 _("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
|
903 entry_point=entry_point |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
904 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
905 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
906 |
3028 | 907 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
|
908 # 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
|
909 self.jid = component_jid |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
910 if host is None: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
911 try: |
3028 | 912 host = component_jid.host.split(".", 1)[1] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
913 except IndexError: |
3028 | 914 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
|
915 # 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
|
916 # 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
|
917 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
|
918 SatXMPPEntity.__init__(self, host_app, profile, max_retries) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
919 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
920 def _buildDependencies(self, current, plugins, required=True): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
921 """build recursively dependencies needed for a plugin |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
922 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
923 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
|
924 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
|
925 @param current(object): parent plugin to check |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
926 use entry_point for first call |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
927 @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
|
928 give an empty list for first call |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
929 @param required(bool): True if plugin is mandatory |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
930 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
|
931 @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
|
932 @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
|
933 is not |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
934 """ |
3028 | 935 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
|
936 if not required: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
937 return |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
938 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
939 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
940 _( |
3028 | 941 "Plugin {current_name} is needed for {entry_name}, " |
942 "but it doesn't handle component mode" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
943 ).format( |
3028 | 944 current_name=current._info["import_name"], |
945 entry_name=self.entry_plugin._info["import_name"], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
946 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
947 ) |
3028 | 948 raise exceptions.InternalError(_("invalid plugin mode")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
949 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
950 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
|
951 # plugins are already loaded as dependencies |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
952 # 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
|
953 dep = self.host_app.plugins[import_name] |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
954 self._buildDependencies(dep, plugins) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
955 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
956 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
|
957 # here plugins are only recommendations, |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
958 # 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
|
959 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
960 dep = self.host_app.plugins[import_name] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
961 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
962 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
963 self._buildDependencies(dep, plugins, required=False) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
964 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
965 if current not in plugins: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
966 # 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
|
967 # it can already be present in the list |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
968 plugins.append(current) |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
969 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
970 def _getPluginsList(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
971 # 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
|
972 # 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
|
973 plugins = [] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
974 self._buildDependencies(self.entry_plugin, plugins) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
975 return plugins |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
976 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
977 def entityConnected(self): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
978 # we can now launch entry point |
2498
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
979 try: |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
980 start_cb = self.entry_plugin.componentStart |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
981 except AttributeError: |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
982 return |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
983 else: |
d6de69da3dd4
core (client): component improvments:
Goffi <goffi@goffi.org>
parents:
2497
diff
changeset
|
984 return start_cb(self) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
985 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
986 def addPostXmlCallbacks(self, post_xml_treatments): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
987 if self.sendHistory: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
988 post_xml_treatments.addCallback(self.messageAddToHistory) |
0 | 989 |
990 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
991 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
|
992 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
993 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
994 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
995 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
996 |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
997 def parseMessage(self, message_elt): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
998 """parse a message XML and return message_data |
663 | 999 |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1000 @param message_elt(domish.Element): raw <message> xml |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1001 @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
|
1002 if None, mapping will not be done |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1003 @return(dict): message data |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1004 """ |
3028 | 1005 if message_elt.name != "message": |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1006 log.warning(_( |
3028 | 1007 "parseMessage used with a non <message/> stanza, ignoring: {xml}" |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1008 .format(xml=message_elt.toXml()))) |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1009 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
|
1010 |
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1011 if message_elt.uri is None: |
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1012 # wokkel element parsing strip out root namespace |
2794
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2778
diff
changeset
|
1013 message_elt.defaultUri = message_elt.uri = C.NS_CLIENT |
2979
f44a95f566d2
core, plugin XEP-0045: fix crashes when changing URIs:
Goffi <goffi@goffi.org>
parents:
2915
diff
changeset
|
1014 for c in message_elt.elements(): |
2794
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2778
diff
changeset
|
1015 if c.uri is None: |
2983
97a1faca8f58
core (xmpp): fixed URI correction while parsing messages:
Goffi <goffi@goffi.org>
parents:
2979
diff
changeset
|
1016 c.uri = C.NS_CLIENT |
2714
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1017 elif message_elt.uri != C.NS_CLIENT: |
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1018 log.warning(_( |
3028 | 1019 "received <message> with a wrong namespace: {xml}" |
2714
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1020 .format(xml=message_elt.toXml()))) |
57eac4fd0ec0
core (xmpp): check <message> namespace in parseMessage, and accept empty namespace (happen with Wokkel)
Goffi <goffi@goffi.org>
parents:
2701
diff
changeset
|
1021 |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1022 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
|
1023 |
3028 | 1024 if not message_elt.hasAttribute('to'): |
2731
a58e380c1c37
core (xmpp): set "to" attribute to <message> element when it's missing:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1025 message_elt['to'] = client.jid.full() |
a58e380c1c37
core (xmpp): set "to" attribute to <message> element when it's missing:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1026 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1027 message = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1028 subject = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1029 extra = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1030 data = { |
3028 | 1031 "from": jid.JID(message_elt["from"]), |
1032 "to": jid.JID(message_elt["to"]), | |
1033 "uid": message_elt.getAttribute( | |
1034 "uid", str(uuid.uuid4()) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1035 ), # XXX: uid is not a standard attribute but may be added by plugins |
3028 | 1036 "message": message, |
1037 "subject": subject, | |
1038 "type": message_elt.getAttribute("type", "normal"), | |
1039 "extra": extra, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1040 } |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1041 |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1042 try: |
3028 | 1043 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
|
1044 except KeyError: |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1045 pass |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1046 else: |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1047 client.mess_id2uid[(data["from"], message_id)] = data["uid"] |
663 | 1048 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1049 # message |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1050 for e in message_elt.elements(C.NS_CLIENT, "body"): |
3028 | 1051 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
|
1052 |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1053 # subject |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1054 for e in message_elt.elements(C.NS_CLIENT, "subject"): |
3028 | 1055 subject[e.getAttribute((C.NS_XML, "lang"), "")] = str(e) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1056 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1057 # delay and timestamp |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1058 try: |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1059 received_timestamp = message_elt._received_timestamp |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1060 except AttributeError: |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1061 # message_elt._received_timestamp should have been set in onMessage |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1062 # but if parseMessage is called directly, it can be missing |
3028 | 1063 log.debug("missing received timestamp for {message_elt}".format( |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1064 message_elt=message_elt)) |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1065 received_timestamp = time.time() |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1066 |
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1067 try: |
3028 | 1068 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
|
1069 except StopIteration: |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1070 data["timestamp"] = received_timestamp |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1071 else: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1072 parsed_delay = delay.Delay.fromElement(delay_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1073 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
|
1074 data["received_timestamp"] = received_timestamp |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1075 if parsed_delay.sender: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1076 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
|
1077 |
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1078 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
|
1079 return data |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1080 |
2645 | 1081 def _onMessageStartWorkflow(self, cont, client, message_elt, post_treat): |
1082 """Parse message and do post treatments | |
1083 | |
1084 It is the first callback called after MessageReceived trigger | |
1085 @param cont(bool): workflow will continue only if this is True | |
1086 @param message_elt(domish.Element): message stanza | |
1087 may have be modified by triggers | |
1088 @param post_treat(defer.Deferred): post parsing treatments | |
1089 """ | |
1090 if not cont: | |
1091 return | |
2701
2ea2369ae7de
plugin XEP-0313: implementation of MAM for messages:
Goffi <goffi@goffi.org>
parents:
2694
diff
changeset
|
1092 data = self.parseMessage(message_elt) |
2645 | 1093 post_treat.addCallback(self.skipEmptyMessage) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2714
diff
changeset
|
1094 post_treat.addCallback(self.addToHistory) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2714
diff
changeset
|
1095 post_treat.addCallback(self.bridgeSignal, data) |
2645 | 1096 post_treat.addErrback(self.cancelErrorTrap) |
1097 post_treat.callback(data) | |
1098 | |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1099 def onMessage(self, message_elt): |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1100 # TODO: handle threads |
2984
4bac4e734666
core (xmpp): set message timestamp on message reception:
Goffi <goffi@goffi.org>
parents:
2983
diff
changeset
|
1101 message_elt._received_timestamp = time.time() |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1102 client = self.parent |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1103 if not "from" in message_elt.attributes: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1104 message_elt["from"] = client.jid.host |
3028 | 1105 log.debug(_("got message from: {from_}").format(from_=message_elt["from"])) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1106 |
2645 | 1107 # plugin can add their treatments to this deferred |
1108 post_treat = defer.Deferred() | |
1109 | |
1110 d = self.host.trigger.asyncPoint( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1111 "MessageReceived", client, message_elt, post_treat |
2645 | 1112 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1113 |
2645 | 1114 d.addCallback(self._onMessageStartWorkflow, client, message_elt, post_treat) |
663 | 1115 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1116 def skipEmptyMessage(self, data): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1117 if not data["message"] and not data["extra"] and not data["subject"]: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1118 raise failure.Failure(exceptions.CancelError("Cancelled empty message")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1119 return data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1120 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2714
diff
changeset
|
1121 def addToHistory(self, data): |
3028 | 1122 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
|
1123 log.debug("history is skipped as requested") |
3028 | 1124 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
|
1125 else: |
3028 | 1126 if data["message"] or data["subject"]: # we need a message to store |
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
|
1127 return self.host.memory.addToHistory(self.parent, data) |
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
|
1128 else: |
3028 | 1129 log.debug("not storing empty message to history: {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
|
1130 .format(data=data)) |
663 | 1131 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2714
diff
changeset
|
1132 def bridgeSignal(self, __, data): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1133 try: |
3028 | 1134 data["extra"]["received_timestamp"] = str(data["received_timestamp"]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1135 data["extra"]["delay_sender"] = data["delay_sender"] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1136 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1137 pass |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2650
diff
changeset
|
1138 if C.MESS_KEY_ENCRYPTION in data: |
3028 | 1139 data["extra"]["encrypted"] = C.BOOL_TRUE |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1140 if data is not None: |
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
|
1141 if data["message"] or data["subject"] or data["type"] == C.MESS_TYPE_INFO: |
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
|
1142 self.host.bridge.messageNew( |
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
|
1143 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
|
1144 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
|
1145 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
|
1146 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
|
1147 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
|
1148 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
|
1149 data["type"], |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3162
diff
changeset
|
1150 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
|
1151 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
|
1152 ) |
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
|
1153 else: |
3028 | 1154 log.debug("Discarding bridge signal for empty message: {data}".format( |
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
|
1155 data=data)) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1156 return data |
1053
71d63750963e
core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents:
1037
diff
changeset
|
1157 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1158 def cancelErrorTrap(self, failure_): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1159 """A message sending can be cancelled by a plugin treatment""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1160 failure_.trap(exceptions.CancelError) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
611
diff
changeset
|
1161 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1162 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1163 class SatRosterProtocol(xmppim.RosterClientProtocol): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1164 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1165 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1166 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1167 self.host = host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1168 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
|
1169 # 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
|
1170 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
|
1171 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
|
1172 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1173 @property |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1174 def versioning(self): |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1175 """True if server support roster versioning""" |
3028 | 1176 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
|
1177 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1178 @property |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1179 def roster_cache(self): |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1180 """Cache of roster from storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1181 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1182 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
|
1183 manually if necessary |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1184 """ |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1185 return persistent.PersistentDict(NS_ROSTER_VER, self.parent.profile) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1186 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1187 def _registerItem(self, item): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1188 """Register item in local cache |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1189 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1190 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
|
1191 @param item (RosterIem): item added |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1192 """ |
3028 | 1193 log.debug("registering item: {}".format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1194 if item.entity.resource: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1195 log.warning( |
3028 | 1196 "Received a roster item with a resource, this is not common but not " |
1197 "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
|
1198 ) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1199 if not item.subscriptionTo: |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1200 if not item.subscriptionFrom: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1201 log.info( |
3028 | 1202 _("There's no subscription between you and [{}]!").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1203 item.entity.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1204 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1205 ) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1206 else: |
3028 | 1207 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
|
1208 if not item.subscriptionFrom: |
3028 | 1209 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
|
1210 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1211 for group in item.groups: |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1212 self._groups.setdefault(group, set()).add(item.entity) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1213 |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1214 @defer.inlineCallbacks |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1215 def _cacheRoster(self, version): |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1216 """Serialise local roster and save it to storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1217 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1218 @param version(unicode): version of roster in local cache |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1219 """ |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1220 roster_cache = self.roster_cache |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1221 yield roster_cache.clear() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1222 roster_cache[ROSTER_VER_KEY] = version |
3028 | 1223 for roster_jid, roster_item in self._jids.items(): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1224 roster_jid_s = roster_jid.full() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1225 roster_item_elt = roster_item.toElement().toXml() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1226 roster_cache[roster_jid_s] = roster_item_elt |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1227 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1228 @defer.inlineCallbacks |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1229 def resync(self): |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1230 """Ask full roster to resync database |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1231 |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1232 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
|
1233 to be somehow corrupted |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1234 """ |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1235 roster_cache = self.roster_cache |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1236 yield roster_cache.clear() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1237 self._jids.clear() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1238 self._groups.clear() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1239 yield self.requestRoster() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1240 |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2891
diff
changeset
|
1241 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1242 def requestRoster(self): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1243 """Ask the server for Roster list """ |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1244 if self.versioning: |
3028 | 1245 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
|
1246 roster_cache = self.roster_cache |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1247 yield roster_cache.load() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1248 try: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1249 version = roster_cache[ROSTER_VER_KEY] |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1250 except KeyError: |
3028 | 1251 log.info(_("no roster in cache, we start fresh")) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1252 # u"" means we use versioning without valid roster in cache |
3028 | 1253 version = "" |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1254 else: |
3028 | 1255 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
|
1256 # we deserialise cached roster to our local cache |
3028 | 1257 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
|
1258 if roster_jid_s == ROSTER_VER_KEY: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1259 continue |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1260 roster_jid = jid.JID(roster_jid_s) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1261 roster_item_elt = generic.parseXml(roster_item_elt_s.encode('utf-8')) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1262 roster_item = xmppim.RosterItem.fromElement(roster_item_elt) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1263 self._jids[roster_jid] = roster_item |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1264 self._registerItem(roster_item) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1265 else: |
3028 | 1266 log.warning(_("our server doesn't support roster versioning")) |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1267 version = None |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1268 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1269 log.debug("requesting roster") |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1270 roster = yield self.getRoster(version=version) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1271 if roster is None: |
3028 | 1272 log.debug("empty roster result received, we'll get roster item with roster " |
1273 "pushes") | |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1274 else: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1275 # a full roster is received |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1276 self._groups.clear() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1277 self._jids = roster |
3028 | 1278 for item in roster.values(): |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1279 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
|
1280 # 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
|
1281 # if there is no presence subscription |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1282 # may change in the future |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1283 log.info( |
3028 | 1284 "Removing contact {} from roster because there is no presence " |
1285 "subscription".format( | |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1286 item.jid |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1287 ) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1288 ) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1289 self.removeItem(item.entity) # FIXME: to be checked |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1290 else: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1291 self._registerItem(item) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1292 yield self._cacheRoster(roster.version) |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1293 |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1294 if not self.got_roster.called: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1295 # got_roster may already be called if we use resync() |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1296 self.got_roster.callback(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1297 |
875
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1298 def removeItem(self, to_jid): |
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1299 """Remove a contact from roster list |
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1300 @param to_jid: a JID instance |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1301 @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
|
1302 """ |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1303 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
|
1304 |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1305 def getAttributes(self, item): |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1306 """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
|
1307 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1308 @param item: RosterItem |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1309 @return: dictionary of attributes |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1310 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1311 item_attr = { |
3028 | 1312 "to": str(item.subscriptionTo), |
1313 "from": str(item.subscriptionFrom), | |
1314 "ask": str(item.ask), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1315 } |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1316 if item.name: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1317 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
|
1318 return item_attr |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1319 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1320 def setReceived(self, request): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1321 item = request.item |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1322 entity = item.entity |
3028 | 1323 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
|
1324 if request.version is not None: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1325 # we update the cache in storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1326 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
|
1327 roster_cache[entity.full()] = item.toElement().toXml() |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1328 roster_cache[ROSTER_VER_KEY] = request.version |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1329 |
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
|
1330 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
|
1331 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
|
1332 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
|
1333 jids_set = self._groups[group] |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1334 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
|
1335 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
|
1336 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
|
1337 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
|
1338 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
|
1339 self._jids[entity] = item |
1398
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
1340 self._registerItem(item) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1341 self.host.bridge.newContact( |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1342 entity.full(), self.getAttributes(item), item.groups, self.parent.profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1343 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1344 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1345 def removeReceived(self, request): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1346 entity = request.item.entity |
3028 | 1347 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
|
1348 if request.version is not None: |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1349 # we update the cache in storage |
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1350 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
|
1351 try: |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1352 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
|
1353 except KeyError: |
f6b0088ce247
code (xmpp): store version after roster item update + fix item removal:
Goffi <goffi@goffi.org>
parents:
2894
diff
changeset
|
1354 # 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
|
1355 # 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
|
1356 pass |
2891
6a0f42e9410a
core (xmpp): implemented roster versioning
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1357 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
|
1358 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1359 # 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
|
1360 try: |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1361 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
|
1362 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1363 log.error( |
3028 | 1364 "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
|
1365 entity |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1366 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1367 ) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1368 return |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1369 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
|
1370 try: |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1371 jids_set = self._groups[group] |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1372 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
|
1373 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
|
1374 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
|
1375 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1376 log.warning( |
3028 | 1377 "there is no cache for the group [{group}] of the removed roster " |
1378 "item [{jid_}]".format(group=group, jid=entity) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1379 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1380 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1381 # then we send the bridge signal |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1382 self.host.bridge.contactDeleted(entity.full(), self.parent.profile) |
50 | 1383 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
1384 def getGroups(self): |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1385 """Return a list of groups""" |
3028 | 1386 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
|
1387 |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
1388 def getItem(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
|
1389 """Return RosterItem for a given jid |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1390 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1391 @param entity_jid(jid.JID): jid of the contact |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1392 @return(RosterItem, None): RosterItem instance |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1393 None if contact is not in cache |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1394 """ |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
1395 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
|
1396 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1397 def getJids(self): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1398 """Return all jids of the roster""" |
3028 | 1399 return list(self._jids.keys()) |
487 | 1400 |
1401 def isJidInRoster(self, entity_jid): | |
1402 """Return True if jid is in roster""" | |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1403 return entity_jid in self._jids |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1404 |
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
|
1405 def isPresenceAuthorised(self, entity_jid): |
f8401024ab28
core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents:
2136
diff
changeset
|
1406 """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
|
1407 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
|
1408 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
|
1409 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
|
1410 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
|
1411 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
|
1412 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1413 def getItems(self): |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1414 """Return all items of the roster""" |
3028 | 1415 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
|
1416 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1417 def getJidsFromGroup(self, group): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1418 try: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1419 return self._groups[group] |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
1420 except KeyError: |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
1421 raise exceptions.UnknownGroupError(group) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1422 |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1423 def getJidsSet(self, type_, groups=None): |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1424 """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
|
1425 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1426 @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
|
1427 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
|
1428 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
|
1429 @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
|
1430 @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
|
1431 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1432 if type_ == C.ALL and groups is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1433 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
|
1434 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1435 if type_ == C.ALL: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1436 return set(self.getJids()) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1437 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
|
1438 jids = set() |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1439 for group in groups: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1440 jids.update(self.getJidsFromGroup(group)) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1441 return jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
1442 else: |
3028 | 1443 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
|
1444 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1445 def getNick(self, entity_jid): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1446 """Return a nick name for an entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1447 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1448 return nick choosed by user if available |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1449 else return user part of entity_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1450 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1451 item = self.getItem(entity_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1452 if item is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1453 return entity_jid.user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1454 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1455 return item.name or entity_jid.user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1456 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
1457 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1458 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1459 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1460 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1461 self.host = host |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1462 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
1463 def send(self, obj): |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
1464 presence_d = defer.succeed(None) |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
1465 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
|
1466 return |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
1467 presence_d.addCallback(lambda __: super(SatPresenceProtocol, self).send(obj)) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
1468 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1469 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
|
1470 if not statuses: |
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
1471 statuses = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1472 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1473 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
|
1474 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1475 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1476 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
|
1477 "presence_received", self.parent, entity, show, priority, statuses |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1478 ): |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
1479 return |
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
1480 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1481 self.host.memory.setPresenceStatus( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1482 entity, show or "", int(priority), statuses, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1483 ) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1484 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1485 # now it's time to notify frontends |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1486 self.host.bridge.presenceUpdate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1487 entity.full(), show or "", int(priority), statuses, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1488 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1489 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1490 def unavailableReceived(self, entity, statuses=None): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1491 log.debug( |
3028 | 1492 _("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1493 % {"entity": entity, C.PRESENCE_STATUSES: statuses} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1494 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1495 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
1496 if not statuses: |
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
1497 statuses = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1498 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1499 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
|
1500 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1501 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1502 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
|
1503 "presence_received", self.parent, entity, C.PRESENCE_UNAVAILABLE, 0, statuses, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1504 ): |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1167
diff
changeset
|
1505 return |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1167
diff
changeset
|
1506 |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1507 # now it's time to notify frontends |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1508 # 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
|
1509 # 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
|
1510 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1511 presence = self.host.memory.getEntityDatum( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1512 entity, "presence", self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1513 ) |
1690
772c8edd1057
core: fixed cache check on presence unavailable
Goffi <goffi@goffi.org>
parents:
1685
diff
changeset
|
1514 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
|
1515 # 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
|
1516 pass |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1517 else: |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
1518 if presence.show != C.PRESENCE_UNAVAILABLE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1519 self.host.bridge.presenceUpdate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1520 entity.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1521 C.PRESENCE_UNAVAILABLE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1522 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1523 statuses, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1524 self.parent.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1525 ) |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
1526 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1527 self.host.memory.setPresenceStatus( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1528 entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1529 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1530 |
611 | 1531 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
|
1532 """Set a presence and statuses. |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1533 |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1534 @param entity (jid.JID): entity |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1535 @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
|
1536 @param statuses (dict{unicode: unicode}): multilingual statuses with |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
1537 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
|
1538 """ |
611 | 1539 if priority is None: |
1540 try: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1541 priority = int( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1542 self.host.memory.getParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1543 "Priority", "Connection", profile_key=self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1544 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1545 ) |
611 | 1546 except ValueError: |
1547 priority = 0 | |
1548 | |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1549 if statuses is None: |
562
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
1550 statuses = {} |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1551 |
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1552 # default for us is None for wokkel |
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1553 # 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
|
1554 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
|
1555 statuses[None] = statuses.pop(C.PRESENCE_STATUSES_DEFAULT) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
1556 |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
1557 presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
1558 |
562
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
1559 # ... before switching back |
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
1560 if None in statuses: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1561 statuses["default"] = statuses.pop(None) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
1562 |
1167
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
1563 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
|
1564 return |
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
1565 self.send(presence_elt) |
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
1566 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1567 @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
|
1568 def subscribed(self, entity): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1569 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
|
1570 xmppim.PresenceClientProtocol.subscribed(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
|
1571 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1572 item = self.parent.roster.getItem(entity) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1573 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1574 not item or not item.subscriptionTo |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1575 ): # we automatically subscribe to 'to' presence |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
1576 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
|
1577 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
|
1578 |
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
|
1579 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
|
1580 xmppim.PresenceClientProtocol.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
|
1581 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) |
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
|
1582 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1583 def subscribedReceived(self, entity): |
3028 | 1584 log.debug(_("subscription approved for [%s]") % entity.userhost()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1585 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
|
1586 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1587 def unsubscribedReceived(self, entity): |
3028 | 1588 log.debug(_("unsubscription confirmed for [%s]") % entity.userhost()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1589 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
|
1590 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1591 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1592 def subscribeReceived(self, entity): |
3028 | 1593 log.debug(_("subscription request from [%s]") % entity.userhost()) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1594 yield self.parent.roster.got_roster |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1595 item = self.parent.roster.getItem(entity) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1596 if item and item.subscriptionTo: |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1597 # 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
|
1598 # contact presence |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1599 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
|
1600 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
|
1601 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1602 self.host.memory.addWaitingSub( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1603 "subscribe", entity.userhost(), self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1604 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1605 self.host.bridge.subscribe( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1606 "subscribe", entity.userhost(), self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1607 ) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1608 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1609 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1610 def unsubscribeReceived(self, entity): |
3028 | 1611 log.debug(_("unsubscription asked for [%s]") % entity.userhost()) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1612 yield self.parent.roster.got_roster |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
1613 item = self.parent.roster.getItem(entity) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1614 if item and item.subscriptionFrom: # we automatically remove contact |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1615 log.debug(_("automatic contact deletion")) |
875
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
1616 self.host.delContact(entity, self.parent.profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1617 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
|
1618 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1619 |
3028 | 1620 @implementer(iwokkel.IDisco) |
14 | 1621 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
|
1622 |
14 | 1623 def __init__(self, host): |
1624 disco.DiscoClientProtocol.__init__(self) | |
1625 | |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
1626 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
|
1627 # 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
|
1628 # and thus are always available |
2693
f64f1158a26e
core (xmpp): added NS_X_DATA to disco features
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
1629 return [disco.DiscoFeature(NS_X_DATA), |
2778
f7deb1c36b47
core, XEP-0315: move XML element handling to sat_tmp:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1630 disco.DiscoFeature(NS_XML_ELEMENT), |
2693
f64f1158a26e
core (xmpp): added NS_X_DATA to disco features
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
1631 disco.DiscoFeature(NS_DISCO_INFO)] |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
1632 |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
1633 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
|
1634 return [] |
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
1635 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1636 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1637 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1638 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1639 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1640 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1641 def iqFallback(self, iq): |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1642 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
|
1643 return |
3028 | 1644 log.debug("iqFallback: xml = [%s]" % (iq.toXml())) |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1645 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
1646 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1647 |
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
|
1648 class SatVersionHandler(generic.VersionHandler): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1649 |
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
|
1650 def getDiscoInfo(self, requestor, target, node): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1651 # 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
|
1652 # 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
|
1653 # 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
|
1654 # 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
|
1655 # 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
|
1656 # 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
|
1657 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
|
1658 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1659 |
3028 | 1660 @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
|
1661 class SatIdentityHandler(XMPPHandler): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1662 """Manage disco Identity of SàT.""" |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1663 # 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
|
1664 # 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
|
1665 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1666 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2139
diff
changeset
|
1667 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
|
1668 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2596
diff
changeset
|
1669 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
|
1670 return [] |