Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0353.py @ 4118:07370d2a9bde
plugin XEP-0167: keep media order when starting a call:
media content order is relevant when building Jingle contents/SDP notably for bundling.
This patch fixes the previous behaviour of always using the same order by keeping the
order of the data (i.e. order of original SDP offer). Previous behaviour could lead to
call failure.
rel 424
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Oct 2023 15:15:24 +0200 |
parents | 0da563780ffc |
children | 6784d07b99c8 |
rev | line source |
---|---|
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
3 # Libervia plugin for Jingle Message Initiation (XEP-0353) |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from twisted.internet import defer |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from twisted.internet import reactor |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
21 from twisted.words.protocols.jabber import error, jid |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
22 from twisted.words.protocols.jabber import xmlstream |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.words.xish import domish |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from wokkel import disco, iwokkel |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
25 from zope.interface import implementer |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
26 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
27 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
28 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
29 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
30 from libervia.backend.core.i18n import D_, _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
31 from libervia.backend.core.log import getLogger |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 log = getLogger(__name__) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 NS_JINGLE_MESSAGE = "urn:xmpp:jingle-message:0" |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 PLUGIN_INFO = { |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_NAME: "Jingle Message Initiation", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_IMPORT_NAME: "XEP-0353", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_TYPE: "XEP", |
3651 | 42 C.PI_MODES: [C.PLUG_MODE_CLIENT], |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_PROTOCOLS: ["XEP-0353"], |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
44 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0334"], |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 C.PI_MAIN: "XEP_0353", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 C.PI_HANDLER: "yes", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 C.PI_DESCRIPTION: _("""Implementation of Jingle Message Initiation"""), |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 } |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
51 class RejectException(exceptions.CancelError): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
52 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
53 def __init__(self, reason: str, text: str|None = None): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
54 super().__init__(text) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
55 self.reason = reason |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
56 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
57 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
58 class RetractException(exceptions.CancelError): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
59 pass |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
60 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
61 |
3517
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
62 class XEP_0353: |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 def __init__(self, host): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 log.info(_("plugin {name} initialization").format(name=PLUGIN_INFO[C.PI_NAME])) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
66 host.register_namespace("jingle-message", NS_JINGLE_MESSAGE) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 self._j = host.plugins["XEP-0166"] |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
68 self._h = host.plugins["XEP-0334"] |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
69 host.trigger.add( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
70 "XEP-0166_initiate_elt_built", |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
71 self._on_initiate_trigger, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
72 # this plugin set the resource, we want it to happen first to other trigger |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
73 # can get the full peer JID |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
74 priority=host.trigger.MAX_PRIORITY, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
75 ) |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
76 host.trigger.add( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
77 "XEP-0166_terminate", |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
78 self._terminate_trigger, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
79 priority=host.trigger.MAX_PRIORITY, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
80 ) |
4051
c23cad65ae99
core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents:
4044
diff
changeset
|
81 host.trigger.add("message_received", self._on_message_received) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
83 def get_handler(self, client): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 return Handler() |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
86 def profile_connecting(self, client): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 # mapping from session id to deferred used to wait for destinee answer |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 client._xep_0353_pending_sessions = {} |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
90 def build_message_data(self, client, peer_jid, verb, session_id): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 mess_data = { |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
92 "from": client.jid, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
93 "to": peer_jid, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
94 "uid": "", |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
95 "message": {}, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
96 "type": C.MESS_TYPE_CHAT, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
97 "subject": {}, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
98 "extra": {}, |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
100 client.generate_message_xml(mess_data) |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
101 message_elt = mess_data["xml"] |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
102 verb_elt = message_elt.addElement((NS_JINGLE_MESSAGE, verb)) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 verb_elt["id"] = session_id |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
104 self._h.add_hint_elements(message_elt, [self._h.HINT_STORE]) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 return mess_data |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
107 async def _on_initiate_trigger( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
108 self, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
109 client: SatXMPPEntity, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
110 session: dict, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
111 iq_elt: domish.Element, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
112 jingle_elt: domish.Element, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
113 ) -> bool: |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
114 peer_jid = session["peer_jid"] |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 if peer_jid.resource: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
3652
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
118 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
119 infos = await self.host.memory.disco.get_infos(client, peer_jid) |
3652
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
120 except error.StanzaError as e: |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
121 if e.condition == "service-unavailable": |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
122 categories = {} |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
123 else: |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
124 raise e |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
125 else: |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
126 categories = {c for c, __ in infos.identities} |
3517
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
127 if "component" in categories: |
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 # we don't use message initiation with components |
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
129 return True |
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
130 |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 if peer_jid.userhostJID() not in client.roster: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 # if the contact is not in our roster, we need to send a directed presence |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 # according to XEP-0353 §3.1 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 await client.presence.available(peer_jid) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
136 mess_data = self.build_message_data(client, peer_jid, "propose", session["id"]) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
137 message_elt = mess_data["xml"] |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
138 for content_data in session["contents"].values(): |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
139 # we get the full element build by the application plugin |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
140 jingle_description_elt = content_data["application_data"]["desc_elt"] |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
141 # and copy it to only keep the root <description> element, no children |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
142 description_elt = domish.Element( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
143 (jingle_description_elt.uri, jingle_description_elt.name), |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
144 defaultUri=jingle_description_elt.defaultUri, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
145 attribs=jingle_description_elt.attributes, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
146 localPrefixes=jingle_description_elt.localPrefixes, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
147 ) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
148 message_elt.propose.addChild(description_elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 response_d = defer.Deferred() |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 # we wait for 2 min before cancelling the session init |
4044
3900626bc100
plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
4042
diff
changeset
|
151 # FIXME: let's application decide timeout? |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
152 response_d.addTimeout(2 * 60, reactor) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
153 client._xep_0353_pending_sessions[session["id"]] = response_d |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 try: |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
155 await client.send_message_data(mess_data) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 accepting_jid = await response_d |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 except defer.TimeoutError: |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
158 log.warning( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
159 _("Message initiation with {peer_jid} timed out").format( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
160 peer_jid=peer_jid |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
161 ) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
162 ) |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
163 except exceptions.CancelError as e: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
164 for content in session["contents"].values(): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
165 await content["application"].handler.jingle_preflight_cancel( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
166 client, session, e |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
167 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
168 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
169 self._j.delete_session(client, session["id"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
170 return False |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 else: |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
172 if iq_elt["to"] != accepting_jid.userhost(): |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
173 raise exceptions.InternalError( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
174 f"<jingle> 'to' attribute ({iq_elt['to']!r}) must not differ " |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
175 f"from bare JID of the accepting entity ({accepting_jid!r}), this " |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
176 "may be a sign of an internal bug, a hack attempt, or a MITM attack!" |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
177 ) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
178 iq_elt["to"] = accepting_jid.full() |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 session["peer_jid"] = accepting_jid |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
180 finally: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
181 del client._xep_0353_pending_sessions[session["id"]] |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
184 def _terminate_trigger( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
185 self, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
186 client: SatXMPPEntity, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
187 session: dict, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
188 reason_elt: domish.Element |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
189 ) -> bool: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
190 session_id = session["id"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
191 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
192 response_d = client._xep_0353_pending_sessions[session_id] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
193 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
194 return True |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
195 # we have a XEP-0353 session, that means that we are retracting a proposed session |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
196 mess_data = self.build_message_data( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
197 client, session["peer_jid"], "retract", session_id |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
198 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
199 defer.ensureDeferred(client.send_message_data(mess_data)) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
200 response_d.errback(RetractException()) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
201 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
202 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
203 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
204 async def _on_message_received(self, client, message_elt, post_treat): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 for elt in message_elt.elements(): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 if elt.uri == NS_JINGLE_MESSAGE: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 if elt.name == "propose": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
208 return await self._handle_propose(client, message_elt, elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 elif elt.name == "retract": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
210 return self._handle_retract(client, message_elt, elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 elif elt.name == "proceed": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
212 return self._handle_proceed(client, message_elt, elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 elif elt.name == "accept": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
214 return self._handle_accept(client, message_elt, elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 elif elt.name == "reject": |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
216 return self._handle_reject(client, message_elt, elt) |
4115
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
217 elif elt.name == "ringing": |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
218 return await self._handle_ringing(client, message_elt, elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 else: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 log.warning(f"invalid element: {elt.toXml}") |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
224 def _get_sid_and_response_d( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
225 self, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
226 client: SatXMPPEntity, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
227 elt: domish.Element |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
228 ) -> tuple[str, defer.Deferred]: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
229 """Retrieve session ID and response_d from response element""" |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 try: |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
231 session_id = elt["id"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
232 except KeyError as e: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
233 assert elt.parent is not None |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
234 log.warning(f"invalid proceed element in message_elt: {elt.parent.toXml()}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
235 raise e |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 try: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 response_d = client._xep_0353_pending_sessions[session_id] |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
238 except KeyError as e: |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 log.warning( |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
240 _( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
241 "no pending session found with id {session_id}, did it timed out?" |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
242 ).format(session_id=session_id) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 ) |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
244 raise e |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
245 return session_id, response_d |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
246 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
247 async def _handle_propose(self, client, message_elt, elt): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
248 peer_jid = jid.JID(message_elt["from"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
249 local_jid = jid.JID(message_elt["to"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
250 session_id = elt["id"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
251 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
252 desc_and_apps = [ |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
253 (description_elt, self._j.get_application(description_elt.uri)) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
254 for description_elt in elt.elements() |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
255 if description_elt.name == "description" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
256 ] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
257 if not desc_and_apps: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
258 raise AttributeError |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
259 except AttributeError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
260 log.warning(f"Invalid propose element: {message_elt.toXml()}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
261 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
262 except exceptions.NotFound: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
263 log.warning( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
264 f"There is not registered application to handle this " |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
265 f"proposal: {elt.toXml()}" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
266 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
267 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
268 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
269 if not desc_and_apps: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
270 log.warning("No application specified: {message_elt.toXml()}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
271 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
272 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
273 session = self._j.create_session( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
274 client, session_id, self._j.ROLE_RESPONDER, peer_jid, local_jid |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
275 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
276 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
277 is_in_roster = peer_jid.userhostJID() in client.roster |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
278 if is_in_roster: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
279 # we indicate that device is ringing as explained in |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
280 # https://xmpp.org/extensions/xep-0353.html#ring , but we only do that if user |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
281 # is in roster to avoid presence leak of all our devices. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
282 mess_data = self.build_message_data(client, peer_jid, "ringing", session_id) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
283 await client.send_message_data(mess_data) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
284 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
285 for description_elt, application in desc_and_apps: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
286 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
287 await application.handler.jingle_preflight( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
288 client, session, description_elt |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
289 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
290 except exceptions.CancelError as e: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
291 log.info(f"{client.profile} refused the session: {e}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
292 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
293 if is_in_roster: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
294 # peer is in our roster, we send reject to them, ou other devices will |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
295 # get carbon copies |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
296 reject_dest_jid = peer_jid |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
297 else: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
298 # peer is not in our roster, we send the "reject" only to our own |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
299 # devices to make them stop ringing/doing notification, and we don't |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
300 # send anything to peer to avoid presence leak. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
301 reject_dest_jid = client.jid.userhostJID() |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
302 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
303 mess_data = self.build_message_data( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
304 client, reject_dest_jid, "reject", session_id |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
305 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
306 await client.send_message_data(mess_data) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
307 self._j.delete_session(client, session_id) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
308 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
309 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
310 except defer.CancelledError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
311 # raised when call is retracted before user can reply |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
312 self._j.delete_session(client, session_id) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
313 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
314 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
315 if peer_jid.userhostJID() not in client.roster: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
316 await client.presence.available(peer_jid) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
317 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
318 mess_data = self.build_message_data(client, peer_jid, "proceed", session_id) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
319 await client.send_message_data(mess_data) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
320 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
321 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
322 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
323 def _handle_retract(self, client, message_elt, retract_elt): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
324 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
325 session = self._j.get_session(client, retract_elt["id"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
326 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
327 log.warning(f"invalid retract element: {message_elt.toXml()}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
328 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
329 except exceptions.NotFound: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
330 log.warning(f"no session found with ID {retract_elt['id']}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
331 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
332 log.debug( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
333 f"{message_elt['from']} are retracting their proposal {retract_elt['id']}" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
334 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
335 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
336 cancellable_deferred = session["cancellable_deferred"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
337 if not cancellable_deferred: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
338 raise KeyError |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
339 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
340 self._j.delete_session(client, session["id"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
341 else: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
342 for d in cancellable_deferred: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
343 d.cancel() |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
344 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
345 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
346 def _handle_proceed(self, client, message_elt, proceed_elt): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
347 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
348 __, response_d = self._get_sid_and_response_d(client, proceed_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
349 except KeyError: |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 response_d.callback(jid.JID(message_elt["from"])) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 return False |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
355 def _handle_accept(self, client, message_elt, accept_elt): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 pass |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
358 def _handle_reject(self, client, message_elt, reject_elt): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
359 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
360 __, response_d = self._get_sid_and_response_d(client, reject_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
361 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
362 return True |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
363 reason_elt = self._j.get_reason_elt(reject_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
364 reason, text = self._j.parse_reason_elt(reason_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
365 if reason is None: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
366 reason = "busy" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
367 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
368 response_d.errback(RejectException(reason, text)) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
369 return False |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 |
4115
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
371 async def _handle_ringing(self, client, message_elt, ringing_elt): |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
372 session_id = ringing_elt["id"] |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
373 try: |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
374 session = self._j.get_session(client, session_id) |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
375 except exceptions.NotFound: |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
376 log.warning(f"Session {session_id!r} unknown, ignoring ringing.") |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
377 return False |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
378 for __, content_data in session["contents"].items(): |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
379 await content_data["application"].handler.jingle_preflight_info( |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
380 client, session, "ringing", None |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
381 ) |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
382 |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
383 return False |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
384 |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 @implementer(iwokkel.IDisco) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 class Handler(xmlstream.XMPPHandler): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 return [disco.DiscoFeature(NS_JINGLE_MESSAGE)] |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 return [] |