annotate libervia/backend/plugins/plugin_xep_0353.py @ 4112:bc60875cb3b8

plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI: - XEP-0166: add `jingle_preflight` and `jingle_preflight_cancel` methods to prepare a jingle session, principally used by XEP-0353 to create and cancel a session - XEP-0167: preflight methods implementation, workflow split in more methods/signals to handle UI and call events (e.g.: retract or reject a call) - XEP-0234: implementation of preflight methods as they are now mandatory - XEP-0353: handle various events using the new preflight methods rel 423
author Goffi <goffi@goffi.org>
date Wed, 09 Aug 2023 00:07:37 +0200
parents 4b842c1fb686
children 0da563780ffc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3405
diff changeset
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
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4055
diff changeset
32 from libervia.backend.tools import xml_tools
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 log = getLogger(__name__)
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
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 NS_JINGLE_MESSAGE = "urn:xmpp:jingle-message:0"
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 PLUGIN_INFO = {
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_NAME: "Jingle Message Initiation",
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_IMPORT_NAME: "XEP-0353",
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_TYPE: "XEP",
3651
867a15f05476 plugin XEP-0353: fix plugin modes
Goffi <goffi@goffi.org>
parents: 3517
diff changeset
43 C.PI_MODES: [C.PLUG_MODE_CLIENT],
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 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
45 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0334"],
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 C.PI_MAIN: "XEP_0353",
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 C.PI_HANDLER: "yes",
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 C.PI_DESCRIPTION: _("""Implementation of Jingle Message Initiation"""),
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
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
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
52 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
53
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 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
55 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
56 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
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
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 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
60 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
61
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
62
3517
8508fab9bcc2 plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
63 class XEP_0353:
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def __init__(self, host):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 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
66 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
67 host.register_namespace("jingle-message", NS_JINGLE_MESSAGE)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 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
69 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
70 host.trigger.add(
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
71 "XEP-0166_initiate_elt_built",
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
72 self._on_initiate_trigger,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
73 # 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
74 # 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
75 priority=host.trigger.MAX_PRIORITY,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
76 )
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
77 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
78 "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
79 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
80 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
81 )
4051
c23cad65ae99 core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
82 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
83
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
84 def get_handler(self, client):
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 return Handler()
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
87 def profile_connecting(self, client):
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 # 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
89 client._xep_0353_pending_sessions = {}
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
91 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
92 mess_data = {
4055
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
93 "from": client.jid,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
94 "to": peer_jid,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
95 "uid": "",
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
96 "message": {},
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
97 "type": C.MESS_TYPE_CHAT,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
98 "subject": {},
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
99 "extra": {},
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 }
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
101 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
102 message_elt = mess_data["xml"]
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
103 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
104 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
105 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
106 return mess_data
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
4055
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
108 async def _on_initiate_trigger(
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
109 self,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
110 client: SatXMPPEntity,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
111 session: dict,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
112 iq_elt: domish.Element,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
113 jingle_elt: domish.Element,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
114 ) -> bool:
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
115 peer_jid = session["peer_jid"]
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if peer_jid.resource:
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 return True
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
118
3652
6e34307319c0 plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents: 3651
diff changeset
119 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
120 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
121 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
122 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
123 categories = {}
6e34307319c0 plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents: 3651
diff changeset
124 else:
6e34307319c0 plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents: 3651
diff changeset
125 raise e
6e34307319c0 plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents: 3651
diff changeset
126 else:
6e34307319c0 plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents: 3651
diff changeset
127 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
128 if "component" in categories:
8508fab9bcc2 plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
129 # 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
130 return True
8508fab9bcc2 plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
131
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if peer_jid.userhostJID() not in client.roster:
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 # 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
134 # according to XEP-0353 §3.1
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 await client.presence.available(peer_jid)
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
4055
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
137 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
138 message_elt = mess_data["xml"]
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
139 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
140 # 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
141 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
142 # 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
143 description_elt = domish.Element(
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
144 (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
145 defaultUri=jingle_description_elt.defaultUri,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
146 attribs=jingle_description_elt.attributes,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
147 localPrefixes=jingle_description_elt.localPrefixes,
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
148 )
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
149 message_elt.propose.addChild(description_elt)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 response_d = defer.Deferred()
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 # 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
152 # 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
153 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
154 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
155 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
156 await client.send_message_data(mess_data)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 accepting_jid = await response_d
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 except defer.TimeoutError:
4055
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
159 log.warning(
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
160 _("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
161 peer_jid=peer_jid
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
162 )
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
163 )
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
164 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
165 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
166 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
167 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
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
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 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
171 return False
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 else:
4055
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
173 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
174 raise exceptions.InternalError(
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
175 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
176 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
177 "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
178 )
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
179 iq_elt["to"] = accepting_jid.full()
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 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
181 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
182 del client._xep_0353_pending_sessions[session["id"]]
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 return True
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
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
185 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
186 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
187 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
188 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
189 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
190 ) -> 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
191 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
192 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
193 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
194 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
195 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
196 # 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
197 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
198 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
199 )
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 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
201 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
202
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 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
204
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
205 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
206 for elt in message_elt.elements():
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 if elt.uri == NS_JINGLE_MESSAGE:
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 if elt.name == "propose":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
209 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
210 elif elt.name == "retract":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
211 return self._handle_retract(client, message_elt, elt)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 elif elt.name == "proceed":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
213 return self._handle_proceed(client, message_elt, elt)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 elif elt.name == "accept":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
215 return self._handle_accept(client, message_elt, elt)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 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
217 return self._handle_reject(client, message_elt, elt)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 else:
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 log.warning(f"invalid element: {elt.toXml}")
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 return True
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
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
223 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
224 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
225 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
226 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
227 ) -> 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
228 """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
229 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
230 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
231 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
232 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
233 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
234 raise e
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 try:
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 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
237 except KeyError as e:
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 log.warning(
4055
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
239 _(
38819c69aa39 plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
240 "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
241 ).format(session_id=session_id)
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 )
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
243 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
244 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
245
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 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
247 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
248 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
249 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
250 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
251 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
252 (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
253 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
254 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
255 ]
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 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265 )
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 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
267
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 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
269 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
270 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
271
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 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
273 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
274 )
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 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
277 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
278 # 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
279 # 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
280 # 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
281 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
282 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
283
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 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
285 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
286 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
287 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
288 )
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 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
290 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
291
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 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
293 # 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
294 # 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
295 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
296 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
297 # 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
298 # 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
299 # 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
300 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
301
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 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
303 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
304 )
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 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
306 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
307
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 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
309 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
310 # 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
311 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
312 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
313
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 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
315 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
316
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 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
318 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
319
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 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
321
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 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
333 )
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 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
335 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
336 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
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344
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 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
346 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
347 __, 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
348 except KeyError:
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 return True
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
350
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 response_d.callback(jid.JID(message_elt["from"]))
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 return False
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
353
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
354 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
355 pass
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
356
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
357 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
358 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
359 __, 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
360 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
361 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
362 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
363 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
364 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
365 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
366
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 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
368 return False
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
369
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 @implementer(iwokkel.IDisco)
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 class Handler(xmlstream.XMPPHandler):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 return [disco.DiscoFeature(NS_JINGLE_MESSAGE)]
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
375
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 return []