annotate libervia/backend/plugins/plugin_xep_0166/__init__.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 a8ac5e1e5848
children 79ec7d7beef3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
3 # Libervia plugin for Jingle (XEP-0166)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3404
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
5
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
10
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
15
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
19
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
20 import time
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from typing import Any, Callable, Dict, Final, List, Optional, Tuple
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
22 import uuid
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
23
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
24 from twisted.internet import defer
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
25 from twisted.internet import reactor
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
26 from twisted.python import failure
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
27 from twisted.words.protocols.jabber import jid
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
28 from twisted.words.protocols.jabber import error
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
29 from twisted.words.protocols.jabber import xmlstream
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
30 from twisted.words.xish import domish
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
31 from wokkel import disco, iwokkel
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
32 from zope.interface import implementer
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
33
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
34 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
35 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
36 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
37 from libervia.backend.core.i18n import D_, _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
38 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
39 from libervia.backend.tools import xml_tools
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4053
diff changeset
40 from libervia.backend.tools import utils
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
41
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
42 from .models import (
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
43 ApplicationData,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
44 BaseApplicationHandler,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
45 BaseTransportHandler,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
46 ContentData,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
47 TransportData,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
48 )
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
49
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
51 log = getLogger(__name__)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
52
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
53
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
54 IQ_SET : Final = '/iq[@type="set"]'
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
55 NS_JINGLE : Final = "urn:xmpp:jingle:1"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
56 NS_JINGLE_ERROR : Final = "urn:xmpp:jingle:errors:1"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
57 JINGLE_REQUEST : Final = f'{IQ_SET}/jingle[@xmlns="{NS_JINGLE}"]'
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
58 STATE_PENDING : Final = "PENDING"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
59 STATE_ACTIVE : Final = "ACTIVE"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
60 STATE_ENDED : Final = "ENDED"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
61 CONFIRM_TXT : Final = D_(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
62 "{entity} want to start a jingle session with you, do you accept ?"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
63 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
64
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
65 PLUGIN_INFO : Final = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
66 C.PI_NAME: "Jingle",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
67 C.PI_IMPORT_NAME: "XEP-0166",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
68 C.PI_TYPE: "XEP",
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
69 C.PI_MODES: C.PLUG_MODE_BOTH,
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
70 C.PI_PROTOCOLS: ["XEP-0166"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
71 C.PI_MAIN: "XEP_0166",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
72 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 C.PI_DESCRIPTION: _("""Implementation of Jingle"""),
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
74 }
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
75
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
76
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
77 class XEP_0166:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
78 namespace : Final = NS_JINGLE
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
79
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
80 ROLE_INITIATOR : Final = "initiator"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
81 ROLE_RESPONDER : Final = "responder"
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
82
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
83 TRANSPORT_DATAGRAM : Final = "UDP"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
84 TRANSPORT_STREAMING : Final = "TCP"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
85
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
86 REASON_SUCCESS : Final = "success"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
87 REASON_DECLINE : Final = "decline"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
88 REASON_FAILED_APPLICATION : Final = "failed-application"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
89 REASON_FAILED_TRANSPORT : Final = "failed-transport"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
90 REASON_CONNECTIVITY_ERROR : Final = "connectivity-error"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
91
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
92 # standard actions
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
93
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
94 A_SESSION_INITIATE : Final = "session-initiate"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
95 A_SESSION_ACCEPT : Final = "session-accept"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
96 A_SESSION_TERMINATE : Final = "session-terminate"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
97 A_SESSION_INFO : Final = "session-info"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
98 A_TRANSPORT_REPLACE : Final = "transport-replace"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
99 A_TRANSPORT_ACCEPT : Final = "transport-accept"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
100 A_TRANSPORT_REJECT : Final = "transport-reject"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
101 A_TRANSPORT_INFO : Final = "transport-info"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
102
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
103 # non standard actions
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
104
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
105 #: called before the confirmation request, first event for responder, useful for
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
106 #: parsing
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
107 A_PREPARE_CONFIRMATION : Final = "prepare-confirmation"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
108 #: initiator must prepare tranfer
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
109 A_PREPARE_INITIATOR : Final = "prepare-initiator"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
110 #: responder must prepare tranfer
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
111 A_PREPARE_RESPONDER : Final = "prepare-responder"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
112 #; session accepted ack has been received from initiator
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
113 A_ACCEPTED_ACK : Final = (
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 "accepted-ack"
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
115 )
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
116 A_START : Final = "start" # application can start
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
117 #: called when a transport is destroyed (e.g. because it is remplaced). Used to do
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
118 #: cleaning operations
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
119 A_DESTROY : Final = (
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 "destroy"
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
121 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
122
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
123 def __init__(self, host):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
124 log.info(_("plugin Jingle initialization"))
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 self._applications = {} # key: namespace, value: application data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 self._transports = {} # key: namespace, value: transport data
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
128 # we also keep transports by type, they are then sorted by priority
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 self._type_transports = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 XEP_0166.TRANSPORT_DATAGRAM: [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 XEP_0166.TRANSPORT_STREAMING: [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 }
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
133 host.bridge.add_method(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
134 "jingle_terminate",
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
135 ".plugin",
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
136 in_sign="ssss",
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
137 out_sign="",
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
138 method=self._terminate,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
139 async_=True,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
140 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
141
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
142 def profile_connected(self, client):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
143 client.jingle_sessions = {} # key = sid, value = session_data
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
144
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
145 def get_handler(self, client):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
146 return XEP_0166_handler(self)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
147
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
148 def get_session(self, client: SatXMPPEntity, session_id: str) -> dict:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
149 """Retrieve session from its SID
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
150
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
151 @param session_id: session ID
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
152 @return: found session
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
153
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
154 @raise exceptions.NotFound: no session with this SID has been found
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
155 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
156 try:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
157 return client.jingle_sessions[session_id]
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
158 except KeyError:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
159 raise exceptions.NotFound(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
160 f"No session with SID {session_id} found"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
161 )
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
162
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
163 def create_session(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
164 self,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
165 client: SatXMPPEntity,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
166 sid: str,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
167 role: str,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
168 peer_jid: jid.JID,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
169 local_jid: jid.JID|None = None,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
170 **kwargs
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
171 ) -> dict:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
172 """Create a new jingle session.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
173
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
174 @param client: The client entity.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
175 @param sid: Session ID.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
176 @param role: Session role (initiator or responder).
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
177 @param peer_jid: JID of the peer.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
178 @param local_jid: JID of the local entity.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
179 If None, defaults to client.jid.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
180 @param extra_data: Additional data to be added to the session. Defaults to None.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
181
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
182 @return: The created session.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
183
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
184 @raise ValueError: If the provided role is neither initiator nor responder.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
185 """
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
186 # TODO: session cleaning after timeout ?
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
187 if role not in [XEP_0166.ROLE_INITIATOR, XEP_0166.ROLE_RESPONDER]:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
188 raise ValueError(f"Invalid role {role}. Expected initiator or responder.")
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
189
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
190
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
191 session_data = {
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
192 "id": sid,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
193 "state": STATE_PENDING,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
194 "initiator": client.jid if role == XEP_0166.ROLE_INITIATOR else peer_jid,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
195 "role": role,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
196 "local_jid": local_jid or client.jid,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
197 "peer_jid": peer_jid,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
198 "started": time.time(),
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
199 "contents": {}
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
200 }
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
201
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
202 # If extra kw args are provided, merge them into the session_data
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
203 if kwargs:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
204 session_data.update(kwargs)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
205
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
206 # Add the session to the client's jingle sessions
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
207 client.jingle_sessions[sid] = session_data
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
208
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
209 return session_data
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
210
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
211
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
212 def delete_session(self, client, sid):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
213 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
214 del client.jingle_sessions[sid]
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
215 except KeyError:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
216 log.debug(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
217 f"Jingle session id {sid!r} is unknown, nothing to delete "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
218 f"[{client.profile}]")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
219 else:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
220 log.debug(f"Jingle session id {sid!r} deleted [{client.profile}]")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
221
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
222 ## helpers methods to build stanzas ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
223
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
224 def _build_jingle_elt(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
225 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
226 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
227 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
228 action: str
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
229 ) -> Tuple[xmlstream.IQ, domish.Element]:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 iq_elt = client.IQ("set")
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2920
diff changeset
231 iq_elt["from"] = session['local_jid'].full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 iq_elt["to"] = session["peer_jid"].full()
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
233 jingle_elt = iq_elt.addElement("jingle", NS_JINGLE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 jingle_elt["sid"] = session["id"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
235 jingle_elt["action"] = action
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
236 return iq_elt, jingle_elt
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
237
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
238 def sendError(self, client, error_condition, sid, request, jingle_condition=None):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
239 """Send error stanza
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
240
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
241 @param error_condition: one of twisted.words.protocols.jabber.error.STANZA_CONDITIONS keys
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
242 @param sid(unicode,None): jingle session id, or None, if session must not be destroyed
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
243 @param request(domish.Element): original request
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
244 @param jingle_condition(None, unicode): if not None, additional jingle-specific error information
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
245 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
246 iq_elt = error.StanzaError(error_condition).toResponse(request)
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
247 if jingle_condition is not None:
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
248 iq_elt.error.addElement((NS_JINGLE_ERROR, jingle_condition))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
249 if error.STANZA_CONDITIONS[error_condition]["type"] == "cancel" and sid:
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
250 self.delete_session(client, sid)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
252 "Error while managing jingle session, cancelling: {condition}".format(
2920
945e53cde9b2 plugin XEP-0166: fixed missing key in warning log
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
253 condition=error_condition
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
256 return client.send(iq_elt)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
257
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
258 def _terminate_eb(self, failure_):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
259 log.warning(_("Error while terminating session: {msg}").format(msg=failure_))
2487
ed1d71b91b29 plugin XEP-0166: added errback to terminate, which only logs issues
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
260
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
261 def _terminate(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
262 self,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
263 session_id: str,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
264 reason: str,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
265 reason_txt: str,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
266 profile: str
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
267 ) -> defer.Deferred:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
268 client = self.host.get_client(profile)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
269 session = self.get_session(client, session_id)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
270 if reason not in ("", "cancel", "decline", "busy"):
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
271 raise ValueError(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
272 'only "cancel", "decline" and "busy" and empty value are allowed'
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
273 )
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
274 return self.terminate(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
275 client,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
276 reason or None,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
277 session,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
278 text=reason_txt or None
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
279 )
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
280
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
281 def terminate(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
282 self,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
283 client: SatXMPPEntity,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
284 reason: str|list[domish.Element]|None,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
285 session: dict,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
286 text: str|None = None
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
287 ) -> defer.Deferred:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
288 """Terminate the session
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
289
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
290 send the session-terminate action, and delete the session data
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
291 @param reason: if unicode, will be transformed to an element
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
292 if a list of element, add them as children of the <reason/> element
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
293 @param session: data of the session
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
294 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
295 iq_elt, jingle_elt = self._build_jingle_elt(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
296 client, session, XEP_0166.A_SESSION_TERMINATE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
297 )
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
298 if reason is not None:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
299 reason_elt = jingle_elt.addElement("reason")
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
300 if isinstance(reason, str):
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
301 reason_elt.addElement(reason)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
302 else:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
303 for elt in reason:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
304 reason_elt.addChild(elt)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
305 else:
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
306 reason_elt = None
3527
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
307 if text is not None:
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
308 if reason_elt is None:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
309 raise ValueError(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
310 "You have to specify a reason if text is specified"
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
311 )
3527
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
312 reason_elt.addElement("text", content=text)
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
313 if not self.host.trigger.point(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
314 "XEP-0166_terminate",
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
315 client, session, reason_elt
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
316 ):
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
317 return defer.succeed(None)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
318 self.delete_session(client, session["id"])
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
319 d = iq_elt.send()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
320 d.addErrback(self._terminate_eb)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
321 return d
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
322
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
323 ## errors which doesn't imply a stanza sending ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
324
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
325 def _iq_error(self, failure_, sid, client):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
326 """Called when we got an <iq/> error
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
327
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
328 @param failure_(failure.Failure): the exceptions raised
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
329 @param sid(unicode): jingle session id
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
330 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
332 "Error while sending jingle <iq/> stanza: {failure_}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
333 failure_=failure_.value
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
334 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 )
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
336 self.delete_session(client, sid)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
337
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
338 def _jingle_error_cb(self, failure_, session, request, client):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
339 """Called when something is going wrong while parsing jingle request
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
340
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
341 The error condition depend of the exceptions raised:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
342 exceptions.DataError raise a bad-request condition
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
343 @param fail(failure.Failure): the exceptions raised
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
344 @param session(dict): data of the session
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
345 @param request(domsih.Element): jingle request
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
346 @param client: %(doc_client)s
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
347 """
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
348 del session["jingle_elt"]
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
349 log.warning(f"Error while processing jingle request [{client.profile}]")
3527
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
350 if isinstance(failure_.value, defer.FirstError):
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
351 failure_ = failure_.value.subFailure.value
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
352 if isinstance(failure_, exceptions.DataError):
3527
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
353 return self.sendError(client, "bad-request", session["id"], request)
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
354 elif isinstance(failure_, error.StanzaError):
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
355 return self.terminate(client, self.REASON_FAILED_APPLICATION, session,
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
356 text=str(failure_))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
357 else:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
358 log.error(f"Unmanaged jingle exception: {failure_}")
3527
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
359 return self.terminate(client, self.REASON_FAILED_APPLICATION, session,
bbf92ef05f38 plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
360 text=str(failure_))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
361
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
362 ## methods used by other plugins ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
363
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
364 def register_application(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
365 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
366 namespace: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
367 handler: BaseApplicationHandler
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
368 ) -> None:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
369 """Register an application plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
370
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
371 @param namespace(unicode): application namespace managed by the plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
372 @param handler(object): instance of a class which manage the application.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
373 May have the following methods:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
374 - request_confirmation(session, desc_elt, client):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
375 - if present, it is called on when session must be accepted.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
376 - if it return True the session is accepted, else rejected.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
377 A Deferred can be returned
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
378 - if not present, a generic accept dialog will be used
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
379 - jingle_session_init(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
380 client, self, session, content_name[, *args, **kwargs]
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
381 ): must return the domish.Element used for initial content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
382 - jingle_handler(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
383 client, self, action, session, content_name, transport_elt
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
384 ):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
385 called on several action to negociate the application or transport
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
386 - jingle_terminate: called on session terminate, with reason_elt
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
387 May be used to clean session
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
388 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
389 if namespace in self._applications:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
390 raise exceptions.ConflictError(
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
391 f"Trying to register already registered namespace {namespace}"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
392 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
393 self._applications[namespace] = ApplicationData(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
394 namespace=namespace, handler=handler
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
395 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
396 log.debug("new jingle application registered")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
397
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
398 def register_transport(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
399 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
400 namespace: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
401 transport_type: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
402 handler: BaseTransportHandler,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
403 priority: int = 0
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
404 ) -> None:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
405 """Register a transport plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
406
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
407 @param namespace: the XML namespace used for this transport
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
408 @param transport_type: type of transport to use (see XEP-0166 §8)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
409 @param handler: instance of a class which manage the application.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
410 @param priority: priority of this transport
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
411 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
412 assert transport_type in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
413 XEP_0166.TRANSPORT_DATAGRAM,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 XEP_0166.TRANSPORT_STREAMING,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
415 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
416 if namespace in self._transports:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
417 raise exceptions.ConflictError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
418 "Trying to register already registered namespace {}".format(namespace)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
419 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
420 transport_data = TransportData(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
421 namespace=namespace, handler=handler, priority=priority
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
422 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
423 self._type_transports[transport_type].append(transport_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
424 self._type_transports[transport_type].sort(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
425 key=lambda transport_data: transport_data.priority, reverse=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
426 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
427 self._transports[namespace] = transport_data
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
428 log.debug("new jingle transport registered")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
429
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
430 @defer.inlineCallbacks
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
431 def transport_replace(self, client, transport_ns, session, content_name):
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
432 """Replace a transport
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
433
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
434 @param transport_ns(unicode): namespace of the new transport to use
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
435 @param session(dict): jingle session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
436 @param content_name(unicode): name of the content
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
437 """
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
438 # XXX: for now we replace the transport before receiving confirmation from other peer
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
439 # this is acceptable because we terminate the session if transport is rejected.
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
440 # this behavious may change in the future.
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
441 content_data = session["contents"][content_name]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
442 transport_data = content_data["transport_data"]
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
443 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
444 transport = self._transports[transport_ns]
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
445 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
446 raise exceptions.InternalError("Unkown transport")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
447 yield content_data["transport"].handler.jingle_handler(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
448 client, XEP_0166.A_DESTROY, session, content_name, None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
449 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
450 content_data["transport"] = transport
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
451 transport_data.clear()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
452
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
453 iq_elt, jingle_elt = self._build_jingle_elt(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
454 client, session, XEP_0166.A_TRANSPORT_REPLACE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
455 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
456 content_elt = jingle_elt.addElement("content")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
457 content_elt["name"] = content_name
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
458 content_elt["creator"] = content_data["creator"]
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
459
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
460 transport_elt = transport.handler.jingle_session_init(client, session, content_name)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
461 content_elt.addChild(transport_elt)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
462 iq_elt.send()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
463
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
464 def build_action(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
465 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
466 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
467 action: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
468 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
469 content_name: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
470 iq_elt: Optional[xmlstream.IQ] = None,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
471 context_elt: Optional[domish.Element] = None
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
472 ) -> Tuple[xmlstream.IQ, domish.Element]:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
473 """Build an element according to requested action
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
474
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
475 @param action: a jingle action (see XEP-0166 §7.2),
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
476 session-* actions are not managed here
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
477 transport-replace is managed in the dedicated [transport_replace] method
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
478 @param session: jingle session data
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
479 @param content_name: name of the content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
480 @param iq_elt: use this IQ instead of creating a new one if provided
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
481 @param context_elt: use this element instead of creating a new one if provided
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
482 @return: parent <iq> element, <transport> or <description> element, according to action
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
483 """
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
484 # we first build iq, jingle and content element which are the same in every cases
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
485 if iq_elt is not None:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
486 try:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
487 jingle_elt = next(iq_elt.elements(NS_JINGLE, "jingle"))
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
488 except StopIteration:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
489 raise exceptions.InternalError(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
490 "The <iq> element provided doesn't have a <jingle> element"
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
491 )
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
492 else:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
493 iq_elt, jingle_elt = self._build_jingle_elt(client, session, action)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
494 # FIXME: XEP-0260 § 2.3 Ex 5 has an initiator attribute, but it should not according to XEP-0166 §7.1 table 1, must be checked
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
495 content_data = session["contents"][content_name]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
496 content_elt = jingle_elt.addElement("content")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
497 content_elt["name"] = content_name
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
498 content_elt["creator"] = content_data["creator"]
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
499
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
500 if context_elt is not None:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
501 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
502 elif action == XEP_0166.A_TRANSPORT_INFO:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
503 context_elt = transport_elt = content_elt.addElement(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
504 "transport", content_data["transport"].namespace
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
505 )
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
506 else:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
507 raise exceptions.InternalError(f"unmanaged action {action}")
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
508
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
509 return iq_elt, context_elt
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
510
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
511 def build_session_info(self, client, session):
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
512 """Build a session-info action
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
513
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
514 @param session(dict): jingle session data
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
515 @return (tuple[domish.Element, domish.Element]): parent <iq> element, <jingle> element
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
516 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
517 return self._build_jingle_elt(client, session, XEP_0166.A_SESSION_INFO)
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
518
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
519 def get_application(self, namespace: str) -> ApplicationData:
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
520 """Retreive application corresponding to a namespace
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
521
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
522 @raise exceptions.NotFound if application can't be found
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
523 """
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
524 try:
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
525 return self._applications[namespace]
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
526 except KeyError:
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
527 raise exceptions.NotFound(
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
528 f"No application registered for {namespace}"
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
529 )
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
530
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
531 def get_content_data(self, content: dict) -> ContentData:
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
532 """"Retrieve application and its argument from content"""
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
533 app_ns = content["app_ns"]
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
534 try:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
535 application = self.get_application(app_ns)
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
536 except exceptions.NotFound as e:
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
537 raise exceptions.InternalError(str(e))
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
538 app_args = content.get("app_args", [])
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
539 app_kwargs = content.get("app_kwargs", {})
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
540 transport_data = content.get("transport_data", {})
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
541 try:
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
542 content_name = content["name"]
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
543 except KeyError:
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
544 content_name = content["name"] = str(uuid.uuid4())
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
545 return ContentData(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
546 application,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
547 app_args,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
548 app_kwargs,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
549 transport_data,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
550 content_name
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
551 )
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
552
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
553 async def initiate(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
554 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
555 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
556 peer_jid: jid.JID,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
557 contents: List[dict],
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
558 encrypted: bool = False,
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
559 sid: str|None = None,
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
560 **extra_data: Any
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
561 ) -> str:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
562 """Send a session initiation request
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
563
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
564 @param peer_jid: jid to establith session with
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
565 @param contents: list of contents to use:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
566 The dict must have the following keys:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
567 - app_ns(str): namespace of the application
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
568 the following keys are optional:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
569 - transport_type(str): type of transport to use (see XEP-0166 §8)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
570 default to TRANSPORT_STREAMING
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
571 - name(str): name of the content
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
572 - senders(str): One of XEP_0166.ROLE_INITIATOR, XEP_0166.ROLE_RESPONDER,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
573 both or none
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
574 Defaults to BOTH (see XEP-0166 §7.3)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
575 - app_args(list): args to pass to the application plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
576 - app_kwargs(dict): keyword args to pass to the application plugin
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
577 @param encrypted: if True, session must be encrypted and "encryption" must be set
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
578 to all content data of session
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
579 @param sid: Session ID.
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
580 If None, one will be generated (and used as return value)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
581 @return: Sesson ID
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
582 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
583 assert contents # there must be at least one content
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2920
diff changeset
584 if (peer_jid == client.jid
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2920
diff changeset
585 or client.is_component and peer_jid.host == client.jid.host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
586 raise ValueError(_("You can't do a jingle session with yourself"))
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
587 if sid is None:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
588 sid = str(uuid.uuid4())
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
589 session = self.create_session(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
590 client, sid, XEP_0166.ROLE_INITIATOR, peer_jid, **extra_data
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
591 )
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
592 initiator = session["initiator"]
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
593
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
594 if not await self.host.trigger.async_point(
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
595 "XEP-0166_initiate",
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
596 client, session, contents
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
597 ):
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
598 return sid
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
599
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
600 iq_elt, jingle_elt = self._build_jingle_elt(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
601 client, session, XEP_0166.A_SESSION_INITIATE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
602 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
603 jingle_elt["initiator"] = initiator.full()
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
604 session["jingle_elt"] = jingle_elt
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
605
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
606 session_contents = session["contents"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
607
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
608 for content in contents:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
609 # we get the application plugin
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
610 content_data = self.get_content_data(content)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
611
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
612 # and the transport plugin
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
613 transport_type = content.get("transport_type", XEP_0166.TRANSPORT_STREAMING)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
614 try:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
615 transport = self._type_transports[transport_type][0]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
616 except IndexError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
617 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
618 "No transport registered for {}".format(transport_type)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
619 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
620
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
621 # we build the session data for this content
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
622 application_data = {}
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
623 transport_data = content_data.transport_data
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
624 session_content = {
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
625 "application": content_data.application,
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
626 "application_data": application_data,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
627 "transport": transport,
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
628 "transport_data": transport_data,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
629 "creator": XEP_0166.ROLE_INITIATOR,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
630 "senders": content.get("senders", "both"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
631 }
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
632 if content_data.content_name in session_contents:
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
633 raise exceptions.InternalError(
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
634 "There is already a content with this name"
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
635 )
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
636 session_contents[content_data.content_name] = session_content
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
637
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
638 # we construct the content element
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
639 content_elt = jingle_elt.addElement("content")
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
640 content_elt["creator"] = session_content["creator"]
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
641 content_elt["name"] = content_data.content_name
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
642 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
643 content_elt["senders"] = content["senders"]
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
644 except KeyError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
645 pass
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
646
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
647 # then the description element
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
648 application_data["desc_elt"] = desc_elt = await utils.as_deferred(
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
649 content_data.application.handler.jingle_session_init,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
650 client, session, content_data.content_name,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
651 *content_data.app_args, **content_data.app_kwargs
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
652 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
653 content_elt.addChild(desc_elt)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
654
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
655 # and the transport one
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
656 transport_data["transport_elt"] = transport_elt = await utils.as_deferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
657 transport.handler.jingle_session_init,
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
658 client, session, content_data.content_name,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
659 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
660 content_elt.addChild(transport_elt)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
661
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
662 if not await self.host.trigger.async_point(
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
663 "XEP-0166_initiate_elt_built",
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
664 client, session, iq_elt, jingle_elt
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
665 ):
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
666 return sid
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
667
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
668 # processing is done, we can remove elements
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
669 for content_data in session_contents.values():
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
670 del content_data["application_data"]["desc_elt"]
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
671 del content_data["transport_data"]["transport_elt"]
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
672 del session["jingle_elt"]
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
673
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
674 if encrypted:
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
675 for content in session["contents"].values():
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
676 if "encryption" not in content:
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
677 raise exceptions.EncryptionError(
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
678 "Encryption is requested, but no encryption has been set"
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
679 )
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
680
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
681 try:
3404
26a0af6e32c1 plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
682 await iq_elt.send()
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
683 except Exception as e:
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
684 failure_ = failure.Failure(e)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
685 self._iq_error(failure_, sid, client)
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
686 raise failure_
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
687 return sid
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
688
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
689 def delayed_content_terminate(self, *args, **kwargs):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
690 """Put content_terminate in queue but don't execute immediately
1617
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
691
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
692 This is used to terminate a content inside a handler, to avoid modifying contents
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
693 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
694 reactor.callLater(0, self.content_terminate, *args, **kwargs)
1617
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
695
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
696 def content_terminate(self, client, session, content_name, reason=REASON_SUCCESS):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
697 """Terminate and remove a content
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
698
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
699 if there is no more content, then session is terminated
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
700 @param session(dict): jingle session
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
701 @param content_name(unicode): name of the content terminated
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
702 @param reason(unicode): reason of the termination
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
703 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
704 contents = session["contents"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
705 del contents[content_name]
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
706 if not contents:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
707 self.terminate(client, reason, session)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
708
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
709 ## defaults methods called when plugin doesn't have them ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
710
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
711 def jingle_request_confirmation_default(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
712 self, client, action, session, content_name, desc_elt
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
713 ):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
714 """This method request confirmation for a jingle session"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
715 log.debug("Using generic jingle confirmation method")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
716 return xml_tools.defer_confirm(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
717 self.host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
718 _(CONFIRM_TXT).format(entity=session["peer_jid"].full()),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
719 _("Confirm Jingle session"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
720 profile=client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
721 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
722
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
723 ## jingle events ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
724
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
725 def _on_jingle_request(self, request: domish.Element, client: SatXMPPEntity) -> None:
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
726 defer.ensureDeferred(self.on_jingle_request(client, request))
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
727
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
728 async def on_jingle_request(
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
729 self,
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
730 client: SatXMPPEntity,
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
731 request: domish.Element
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
732 ) -> None:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
733 """Called when any jingle request is received
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
734
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
735 The request will then be dispatched to appropriate method
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
736 according to current state
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
737 @param request(domish.Element): received IQ request
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
738 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
739 request.handled = True
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
740 jingle_elt = next(request.elements(NS_JINGLE, "jingle"))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
741
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
742 # first we need the session id
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
743 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
744 sid = jingle_elt["sid"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
745 if not sid:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
746 raise KeyError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
747 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
748 log.warning("Received jingle request has no sid attribute")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
749 self.sendError(client, "bad-request", None, request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
750 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
751
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
752 # then the action
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
753 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
754 action = jingle_elt["action"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
755 if not action:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
756 raise KeyError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
757 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
758 log.warning("Received jingle request has no action")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
759 self.sendError(client, "bad-request", None, request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
760 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
761
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
762 peer_jid = jid.JID(request["from"])
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
763
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
764 # we get or create the session
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
765 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
766 session = client.jingle_sessions[sid]
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
767 except KeyError:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
768 if action == XEP_0166.A_SESSION_INITIATE:
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
769 pass
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
770 elif action == XEP_0166.A_SESSION_TERMINATE:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
771 log.debug(
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
772 "ignoring session terminate action (inexisting session id): "
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
773 "{request_id} [{profile}]".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
774 request_id=sid, profile=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
775 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
776 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
777 return
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
778 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
779 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
780 "Received request for an unknown session id: {request_id} [{profile}]".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
781 request_id=sid, profile=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
782 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
783 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
784 self.sendError(client, "item-not-found", None, request, "unknown-session")
1615
a1e5bcd9a6eb jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents: 1614
diff changeset
785 return
a1e5bcd9a6eb jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents: 1614
diff changeset
786
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
787 try:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4111
diff changeset
788 # session may have been already created in a jingle_preflight, in this
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4111
diff changeset
789 # case we re-use it.
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
790 session = self.get_session(client, sid)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
791 except exceptions.NotFound:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
792 # XXX: we store local_jid using request['to'] because for a component the
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
793 # jid used may not be client.jid (if a local part is used).
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
794 session = self.create_session(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
795 client, sid, XEP_0166.ROLE_RESPONDER, peer_jid, jid.JID(request['to'])
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
796 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
797 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
798 if session["peer_jid"] != peer_jid:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
799 log.warning(
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
800 "sid conflict ({}), the jid doesn't match. Can be a collision, a "
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
801 "hack attempt, or a bad sid generation".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
802 sid
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
803 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
804 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
805 self.sendError(client, "service-unavailable", sid, request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
806 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
807 if session["id"] != sid:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
808 log.error("session id doesn't match")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
809 self.sendError(client, "service-unavailable", sid, request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
810 raise exceptions.InternalError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
811
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
812 if action == XEP_0166.A_SESSION_INITIATE:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
813 await self.on_session_initiate(client, request, jingle_elt, session)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
814 elif action == XEP_0166.A_SESSION_TERMINATE:
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
815 await self.on_session_terminate(client, request, jingle_elt, session)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
816 elif action == XEP_0166.A_SESSION_ACCEPT:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
817 await self.on_session_accept(client, request, jingle_elt, session)
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
818 elif action == XEP_0166.A_SESSION_INFO:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
819 self.on_session_info(client, request, jingle_elt, session)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
820 elif action == XEP_0166.A_TRANSPORT_INFO:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
821 self.on_transport_info(client, request, jingle_elt, session)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
822 elif action == XEP_0166.A_TRANSPORT_REPLACE:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
823 await self.on_transport_replace(client, request, jingle_elt, session)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
824 elif action == XEP_0166.A_TRANSPORT_ACCEPT:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
825 self.on_transport_accept(client, request, jingle_elt, session)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
826 elif action == XEP_0166.A_TRANSPORT_REJECT:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
827 self.on_transport_reject(client, request, jingle_elt, session)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
828 else:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
829 raise exceptions.InternalError(f"Unknown action {action}")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
830
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
831 ## Actions callbacks ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
832
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
833 def _parse_elements(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
834 self,
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
835 jingle_elt: domish.Element,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
836 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
837 request: domish.Element,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
838 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
839 new: bool = False,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
840 creator: str = ROLE_INITIATOR,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
841 with_application: bool =True,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
842 with_transport: bool = True,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
843 store_in_session: bool = True,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
844 ) -> Dict[str, dict]:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
845 """Parse contents elements and fill contents_dict accordingly
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
846
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
847 after the parsing, contents_dict will containt handlers, "desc_elt" and
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
848 "transport_elt"
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
849 @param jingle_elt: parent <jingle> element, containing one or more <content>
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
850 @param session: session data
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
851 @param request: the whole request
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
852 @param client: %(doc_client)s
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
853 @param new: True if the content is new and must be created,
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
854 else the content must exists, and session data will be filled
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
855 @param creator: only used if new is True: creating pear (see § 7.3)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
856 @param with_application: if True, raise an error if there is no <description>
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
857 element else ignore it
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
858 @param with_transport: if True, raise an error if there is no <transport> element
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
859 else ignore it
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
860 @param store_in_session: if True, the ``session`` contents will be updated with
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
861 the parsed elements.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
862 Use False when you parse an action which can happen at any time (e.g.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
863 transport-info) and meaning that a parsed element may already be present in
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
864 the session (e.g. if an authorisation request is waiting for user answer),
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
865 This can't be used when ``new`` is set.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
866 @return: contents_dict (from session, or a new one if "store_in_session" is False)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
867 @raise exceptions.CancelError: the error is treated and the calling method can
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
868 cancel the treatment (i.e. return)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
869 """
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
870 if store_in_session:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
871 contents_dict = session["contents"]
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
872 else:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
873 if new:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
874 raise exceptions.InternalError(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
875 '"store_in_session" must not be used when "new" is set'
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
876 )
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
877 contents_dict = {n: {} for n in session["contents"]}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
878 content_elts = jingle_elt.elements(NS_JINGLE, "content")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
879
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
880 for content_elt in content_elts:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
881 name = content_elt["name"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
882
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
883 if new:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
884 # the content must not exist, we check it
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
885 if not name or name in contents_dict:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
886 self.sendError(client, "bad-request", session["id"], request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
887 raise exceptions.CancelError
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
888 content_data = contents_dict[name] = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
889 "creator": creator,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
890 "senders": content_elt.attributes.get("senders", "both"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
891 }
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
892 else:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
893 # the content must exist, we check it
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
894 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
895 content_data = contents_dict[name]
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
896 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
897 log.warning("Other peer try to access an unknown content")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
898 self.sendError(client, "bad-request", session["id"], request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
899 raise exceptions.CancelError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
900
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
901 # application
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
902 if with_application:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
903 desc_elt = content_elt.description
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
904 if not desc_elt:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
905 self.sendError(client, "bad-request", session["id"], request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
906 raise exceptions.CancelError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
907
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
908 if new:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
909 # the content is new, we need to check and link the application
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
910 app_ns = desc_elt.uri
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
911 if not app_ns or app_ns == NS_JINGLE:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
912 self.sendError(client, "bad-request", session["id"], request)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
913 raise exceptions.CancelError
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
914
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
915 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
916 application = self._applications[app_ns]
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
917 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
918 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
919 "Unmanaged application namespace [{}]".format(app_ns)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
920 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
921 self.sendError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
922 client, "service-unavailable", session["id"], request
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
923 )
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
924 raise exceptions.CancelError
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
925
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
926 content_data["application"] = application
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
927 content_data["application_data"] = {}
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
928 else:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
929 # the content exists, we check that we have not a former desc_elt
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
930 if "desc_elt" in content_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
931 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
932 "desc_elt should not exist at this point"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
933 )
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
934
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
935 content_data["desc_elt"] = desc_elt
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
936
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
937 # transport
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
938 if with_transport:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
939 transport_elt = content_elt.transport
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
940 if not transport_elt:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
941 self.sendError(client, "bad-request", session["id"], request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
942 raise exceptions.CancelError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
943
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
944 if new:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
945 # the content is new, we need to check and link the transport
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
946 transport_ns = transport_elt.uri
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
947 if not app_ns or app_ns == NS_JINGLE:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
948 self.sendError(client, "bad-request", session["id"], request)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
949 raise exceptions.CancelError
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
950
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
951 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
952 transport = self._transports[transport_ns]
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
953 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
954 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
955 "No transport registered for namespace {}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
956 transport_ns
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
957 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
958 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
959 content_data["transport"] = transport
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
960 content_data["transport_data"] = {}
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
961 else:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
962 # the content exists, we check that we have not a former transport_elt
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
963 if "transport_elt" in content_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
964 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
965 "transport_elt should not exist at this point"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
966 )
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
967
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
968 content_data["transport_elt"] = transport_elt
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
969
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
970 return contents_dict
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
971
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
972 def _ignore(self, client, action, session, content_name, elt):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
973 """Dummy method used when not exception must be raised if a method is not implemented in _call_plugins
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
974
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
975 must be used as app_default_cb and/or transp_default_cb
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
976 """
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
977 return elt
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
978
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
979 def _call_plugins(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
980 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
981 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
982 action: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
983 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
984 app_method_name: Optional[str] = "jingle_handler",
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
985 transp_method_name: Optional[str] = "jingle_handler",
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
986 app_default_cb: Optional[Callable] = None,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
987 transp_default_cb: Optional[Callable] = None,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
988 delete: bool = True,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
989 elements: bool = True,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
990 force_element: Optional[domish.Element] = None
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
991 ) -> List[defer.Deferred]:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
992 """Call application and transport plugin methods for all contents
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
993
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
994 @param action: jingle action name
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
995 @param session: jingle session data
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
996 @param app_method_name: name of the method to call for applications
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
997 None to ignore
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
998 @param transp_method_name: name of the method to call for transports
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
999 None to ignore
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1000 @param app_default_cb: default callback to use if plugin has not app_method_name
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1001 None to raise an exception instead
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1002 @param transp_default_cb: default callback to use if plugin has not transp_method_name
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1003 None to raise an exception instead
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1004 @param delete: if True, remove desc_elt and transport_elt from session
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1005 ignored if elements is False
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1006 @param elements: True if elements(desc_elt and tranport_elt) must be managed
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1007 must be True if _call_plugins is used in a request, and False if it is used
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1008 after a request (i.e. on <iq> result or error)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1009 @param force_element: if elements is False, it is used as element parameter
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1010 else it is ignored
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1011 @return : list of launched Deferred
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1012 @raise exceptions.NotFound: method is not implemented
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1013 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1014 contents_dict = session["contents"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1015 defers_list = []
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1016 for content_name, content_data in contents_dict.items():
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1017 for method_name, handler_key, default_cb, elt_name in (
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1018 (app_method_name, "application", app_default_cb, "desc_elt"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1019 (transp_method_name, "transport", transp_default_cb, "transport_elt"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1020 ):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1021 if method_name is None:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1022 continue
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1023
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1024 handler = content_data[handler_key].handler
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1025 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1026 method = getattr(handler, method_name)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1027 except AttributeError:
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
1028 if default_cb is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1029 raise exceptions.NotFound(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1030 "{} not implemented !".format(method_name)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1031 )
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
1032 else:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1033 method = default_cb
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1034 if elements:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1035 elt = content_data.pop(elt_name) if delete else content_data[elt_name]
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1036 else:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1037 elt = force_element
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1038 d = utils.as_deferred(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1039 method, client, action, session, content_name, elt
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1040 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1041 defers_list.append(d)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1042
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1043 return defers_list
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1044
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1045 async def on_session_initiate(
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1046 self,
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1047 client: SatXMPPEntity,
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1048 request: domish.Element,
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1049 jingle_elt: domish.Element,
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1050 session: Dict[str, Any]
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1051 ) -> None:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1052 """Called on session-initiate action
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1053
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1054 The "jingle_request_confirmation" method of each application will be called
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1055 (or self.jingle_request_confirmation_default if the former doesn't exist).
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1056 The session is only accepted if all application are confirmed.
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1057 The application must manage itself multiple contents scenari (e.g. audio/video).
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1058 @param client: %(doc_client)s
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1059 @param request(domish.Element): full request
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1060 @param jingle_elt(domish.Element): <jingle> element
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1061 @param session(dict): session data
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1062 """
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1063 contents_dict = session["contents"]
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1064 if contents_dict:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1065 raise exceptions.InternalError(
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1066 "Contents dict should not already be set at this point"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1067 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1068
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1069 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1070 self._parse_elements(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1071 jingle_elt, session, request, client, True, XEP_0166.ROLE_INITIATOR
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1072 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1073 except exceptions.CancelError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1074 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1075
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1076 if not contents_dict:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1077 # there MUST be at least one content
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1078 self.sendError(client, "bad-request", session["id"], request)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1079 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1080
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1081 # at this point we can send the <iq/> result to confirm reception of the request
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1082 client.send(xmlstream.toResponse(request, "result"))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1083
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1084
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1085 assert "jingle_elt" not in session
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1086 session["jingle_elt"] = jingle_elt
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1087 if not await self.host.trigger.async_point(
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1088 "XEP-0166_on_session_initiate",
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1089 client, session, request, jingle_elt
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1090 ):
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1091 return
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1092
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1093 await defer.DeferredList(self._call_plugins(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1094 client,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1095 XEP_0166.A_PREPARE_CONFIRMATION,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1096 session,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1097 delete=False
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1098 ))
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1099
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1100 # we now request each application plugin confirmation
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1101 # and if all are accepted, we can accept the session
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1102 confirm_defers = self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1103 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1104 XEP_0166.A_SESSION_INITIATE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1105 session,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1106 "jingle_request_confirmation",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1107 None,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1108 self.jingle_request_confirmation_default,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1109 delete=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1110 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1111
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1112 confirm_dlist = defer.gatherResults(confirm_defers)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1113 confirm_dlist.addCallback(self._confirmation_cb, session, jingle_elt, client)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1114 confirm_dlist.addErrback(self._jingle_error_cb, session, request, client)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1115
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1116 def _confirmation_cb(self, confirm_results, session, jingle_elt, client):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1117 """Method called when confirmation from user has been received
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1118
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1119 This method is only called for the responder
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1120 @param confirm_results(list[bool]): all True if session is accepted
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1121 @param session(dict): session data
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1122 @param jingle_elt(domish.Element): jingle data of this session
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1123 @param client: %(doc_client)s
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1124 """
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1125 del session["jingle_elt"]
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1126 confirmed = all(confirm_results)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1127 if not confirmed:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
1128 return self.terminate(client, XEP_0166.REASON_DECLINE, session)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1129
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1130 iq_elt, jingle_elt = self._build_jingle_elt(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1131 client, session, XEP_0166.A_SESSION_ACCEPT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1132 )
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2920
diff changeset
1133 jingle_elt["responder"] = session['local_jid'].full()
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1134 session["jingle_elt"] = jingle_elt
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1135
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1136 # contents
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1137
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1138 def addElement(domish_elt, content_elt):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1139 content_elt.addChild(domish_elt)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1140
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1141 defers_list = []
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1142
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1143 for content_name, content_data in session["contents"].items():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1144 content_elt = jingle_elt.addElement("content")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1145 content_elt["creator"] = XEP_0166.ROLE_INITIATOR
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1146 content_elt["name"] = content_name
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1147
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1148 application = content_data["application"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1149 app_session_accept_cb = application.handler.jingle_handler
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1150
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1151 app_d = utils.as_deferred(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1152 app_session_accept_cb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1153 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1154 XEP_0166.A_SESSION_INITIATE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1155 session,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1156 content_name,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1157 content_data.pop("desc_elt"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1158 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1159 app_d.addCallback(addElement, content_elt)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1160 defers_list.append(app_d)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1161
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1162 transport = content_data["transport"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1163 transport_session_accept_cb = transport.handler.jingle_handler
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1164
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1165 transport_d = utils.as_deferred(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1166 transport_session_accept_cb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1167 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1168 XEP_0166.A_SESSION_INITIATE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1169 session,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1170 content_name,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1171 content_data.pop("transport_elt"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1172 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1173 transport_d.addCallback(addElement, content_elt)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1174 defers_list.append(transport_d)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1175
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1176 d_list = defer.DeferredList(defers_list)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1177 d_list.addCallback(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1178 lambda __: self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1179 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1180 XEP_0166.A_PREPARE_RESPONDER,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1181 session,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1182 app_method_name=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1183 elements=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1184 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1185 )
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1186 d_list.addCallback(lambda __: session.pop("jingle_elt"))
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1187 d_list.addCallback(lambda __: iq_elt.send())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1188
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1189 def change_state(__, session):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1190 session["state"] = STATE_ACTIVE
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1191
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1192 d_list.addCallback(change_state, session)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1193 d_list.addCallback(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1194 lambda __: self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1195 client, XEP_0166.A_ACCEPTED_ACK, session, elements=False
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1196 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1197 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1198 d_list.addErrback(self._iq_error, session["id"], client)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1199 return d_list
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1200
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1201 def get_reason_elt(self, parent_elt: domish.Element) -> domish.Element:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1202 """Find a <reason> element in parent_elt
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1203
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1204 if none is found, add an empty one to the element
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1205 @return: the <reason> element
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1206 """
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1207 try:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1208 return next(parent_elt.elements(NS_JINGLE, "reason"))
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1209 except StopIteration:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1210 log.warning("No reason given for session termination")
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1211 reason_elt = parent_elt.addElement("reason")
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1212 return reason_elt
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1213
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1214 def parse_reason_elt(self, reason_elt: domish.Element) -> tuple[str|None, str|None]:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1215 """Parse a <reason> element
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1216
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1217 @return: reason found, and text if any
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1218 """
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1219 reason, text = None, None
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1220 for elt in reason_elt.elements():
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1221 if elt.uri == NS_JINGLE:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1222 if elt.name == "text":
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1223 text = str(elt)
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1224 else:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1225 reason = elt.name
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1226
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1227 if reason is None:
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1228 log.debug("no reason specified,")
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1229
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1230 return reason, text
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1231
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1232 async def on_session_terminate(
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1233 self,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1234 client: SatXMPPEntity,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1235 request: domish.Element,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1236 jingle_elt: domish.Element,
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1237 session: dict
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1238 ) -> None:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1239 # TODO: check reason, display a message to user if needed
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1240 log.debug(f"Jingle Session {session['id']} terminated")
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1241 reason_elt = self.get_reason_elt(jingle_elt)
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
1242
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1243 terminate_defers = self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1244 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1245 XEP_0166.A_SESSION_TERMINATE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1246 session,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1247 "jingle_terminate",
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1248 "jingle_terminate",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1249 self._ignore,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1250 self._ignore,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1251 elements=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1252 force_element=reason_elt,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1253 )
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
1254 terminate_dlist = defer.DeferredList(terminate_defers)
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
1255
4111
a8ac5e1e5848 plugin XEP-0166: `jingle_terminate`, session handling and reason parsing:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
1256 terminate_dlist.addCallback(lambda __: self.delete_session(client, session["id"]))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1257 client.send(xmlstream.toResponse(request, "result"))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1258
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1259 async def on_session_accept(self, client, request, jingle_elt, session):
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1260 """Method called once session is accepted
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1261
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1262 This method is only called for initiator
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1263 @param client: %(doc_client)s
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1264 @param request(domish.Element): full <iq> request
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1265 @param jingle_elt(domish.Element): the <jingle> element
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1266 @param session(dict): session data
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1267 """
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1268 log.debug(f"Jingle session {session['id']} has been accepted")
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1269
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1270 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1271 self._parse_elements(jingle_elt, session, request, client)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1272 except exceptions.CancelError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1273 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1274
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1275 # at this point we can send the <iq/> result to confirm reception of the request
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1276 client.send(xmlstream.toResponse(request, "result"))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1277 # and change the state
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1278 session["state"] = STATE_ACTIVE
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1279 session["jingle_elt"] = jingle_elt
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1280
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1281 await defer.DeferredList(self._call_plugins(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1282 client,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1283 XEP_0166.A_PREPARE_INITIATOR,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1284 session,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1285 delete=False
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1286 ))
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1287
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1288 negociate_defers = []
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1289 negociate_defers = self._call_plugins(client, XEP_0166.A_SESSION_ACCEPT, session)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1290
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1291 negociate_dlist = defer.gatherResults(negociate_defers)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1292
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1293 # after negociations we start the transfer
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1294 negociate_dlist.addCallback(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1295 lambda __: self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1296 client, XEP_0166.A_START, session, app_method_name=None, elements=False
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1297 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1298 )
4053
dd39e60ca2aa plugin XEP-0166: set `jingle_elt`, `desc_elt` and `transport_elt`:
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
1299 negociate_dlist.addCallback(lambda __: session.pop("jingle_elt"))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1300
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1301 def _on_session_cb(self, result, client, request, jingle_elt, session):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1302 client.send(xmlstream.toResponse(request, "result"))
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1303
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1304 def _on_session_eb(self, failure_, client, request, jingle_elt, session):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1305 log.error("Error while handling on_session_info: {}".format(failure_.value))
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1306 # XXX: only error managed so far, maybe some applications/transports need more
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1307 self.sendError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1308 client, "feature-not-implemented", None, request, "unsupported-info"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1309 )
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1310
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1311 def on_session_info(self, client, request, jingle_elt, session):
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1312 """Method called when a session-info action is received from other peer
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1313
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1314 This method is only called for initiator
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1315 @param client: %(doc_client)s
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1316 @param request(domish.Element): full <iq> request
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1317 @param jingle_elt(domish.Element): the <jingle> element
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1318 @param session(dict): session data
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1319 """
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1320 if not jingle_elt.children:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1321 # this is a session ping, see XEP-0166 §6.8
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1322 client.send(xmlstream.toResponse(request, "result"))
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1323 return
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1324
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1325 try:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1326 # XXX: session-info is most likely only used for application, so we don't call transport plugins
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1327 # if a future transport use it, this behaviour must be adapted
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1328 defers = self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1329 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1330 XEP_0166.A_SESSION_INFO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1331 session,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1332 "jingle_session_info",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1333 None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1334 elements=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1335 force_element=jingle_elt,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1336 )
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1337 except exceptions.NotFound as e:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1338 self._on_session_eb(failure.Failure(e), client, request, jingle_elt, session)
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1339 return
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1340
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1341 dlist = defer.DeferredList(defers, fireOnOneErrback=True)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1342 dlist.addCallback(self._on_session_cb, client, request, jingle_elt, session)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1343 dlist.addErrback(self._on_session_cb, client, request, jingle_elt, session)
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
1344
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1345 async def on_transport_replace(self, client, request, jingle_elt, session):
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1346 """A transport change is requested
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1347
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1348 The request is parsed, and jingle_handler is called on concerned transport plugin(s)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1349 @param client: %(doc_client)s
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1350 @param request(domish.Element): full <iq> request
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1351 @param jingle_elt(domish.Element): the <jingle> element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1352 @param session(dict): session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1353 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1354 log.debug("Other peer wants to replace the transport")
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1355 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1356 self._parse_elements(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1357 jingle_elt, session, request, client, with_application=False
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1358 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1359 except exceptions.CancelError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1360 defer.returnValue(None)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1361
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1362 client.send(xmlstream.toResponse(request, "result"))
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1363
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1364 content_name = None
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1365 to_replace = []
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1366
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1367 for content_name, content_data in session["contents"].items():
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1368 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1369 transport_elt = content_data.pop("transport_elt")
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1370 except KeyError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1371 continue
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1372 transport_ns = transport_elt.uri
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1373 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1374 transport = self._transports[transport_ns]
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1375 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1376 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1377 "Other peer want to replace current transport with an unknown one: {}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1378 transport_ns
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1379 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1380 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1381 content_name = None
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1382 break
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1383 to_replace.append((content_name, content_data, transport, transport_elt))
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1384
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1385 if content_name is None:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1386 # wa can't accept the replacement
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1387 iq_elt, reject_jingle_elt = self._build_jingle_elt(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1388 client, session, XEP_0166.A_TRANSPORT_REJECT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1389 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1390 for child in jingle_elt.children:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1391 reject_jingle_elt.addChild(child)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1392
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1393 iq_elt.send()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1394 defer.returnValue(None)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1395
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1396 # at this point, everything is alright and we can replace the transport(s)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1397 # this is similar to an session-accept action, but for transports only
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1398 iq_elt, accept_jingle_elt = self._build_jingle_elt(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1399 client, session, XEP_0166.A_TRANSPORT_ACCEPT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1400 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1401 for content_name, content_data, transport, transport_elt in to_replace:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1402 # we can now actually replace the transport
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1403 await utils.as_deferred(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1404 content_data["transport"].handler.jingle_handler,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1405 client, XEP_0166.A_DESTROY, session, content_name, None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1406 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1407 content_data["transport"] = transport
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1408 content_data["transport_data"].clear()
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1409 # and build the element
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1410 content_elt = accept_jingle_elt.addElement("content")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1411 content_elt["name"] = content_name
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1412 content_elt["creator"] = content_data["creator"]
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1413 # we notify the transport and insert its <transport/> in the answer
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1414 accept_transport_elt = await utils.as_deferred(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1415 transport.handler.jingle_handler,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1416 client, XEP_0166.A_TRANSPORT_REPLACE, session, content_name, transport_elt
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1417 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1418 content_elt.addChild(accept_transport_elt)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1419 # there is no confirmation needed here, so we can directly prepare it
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1420 await utils.as_deferred(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1421 transport.handler.jingle_handler,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1422 client, XEP_0166.A_PREPARE_RESPONDER, session, content_name, None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1423 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1424
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1425 iq_elt.send()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1426
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1427 def on_transport_accept(self, client, request, jingle_elt, session):
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1428 """Method called once transport replacement is accepted
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1429
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1430 @param client: %(doc_client)s
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1431 @param request(domish.Element): full <iq> request
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1432 @param jingle_elt(domish.Element): the <jingle> element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1433 @param session(dict): session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1434 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1435 log.debug("new transport has been accepted")
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1436
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1437 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1438 self._parse_elements(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1439 jingle_elt, session, request, client, with_application=False
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1440 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1441 except exceptions.CancelError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1442 return
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1443
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1444 # at this point we can send the <iq/> result to confirm reception of the request
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1445 client.send(xmlstream.toResponse(request, "result"))
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1446
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1447 negociate_defers = []
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1448 negociate_defers = self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1449 client, XEP_0166.A_TRANSPORT_ACCEPT, session, app_method_name=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1450 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1451
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1452 negociate_dlist = defer.DeferredList(negociate_defers)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1453
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1454 # after negociations we start the transfer
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1455 negociate_dlist.addCallback(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1456 lambda __: self._call_plugins(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1457 client, XEP_0166.A_START, session, app_method_name=None, elements=False
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1458 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1459 )
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1460
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3969
diff changeset
1461 def on_transport_reject(self, client, request, jingle_elt, session):
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1462 """Method called when a transport replacement is refused
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1463
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1464 @param client: %(doc_client)s
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1465 @param request(domish.Element): full <iq> request
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1466 @param jingle_elt(domish.Element): the <jingle> element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1467 @param session(dict): session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1468 """
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1469 # XXX: for now, we terminate the session in case of transport-reject
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1470 # this behaviour may change in the future
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1471 self.terminate(client, "failed-transport", session)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
1472
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1473 def on_transport_info(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1474 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1475 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1476 request: domish.Element,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1477 jingle_elt: domish.Element,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1478 session: dict
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1479 ) -> None:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1480 """Method called when a transport-info action is received from other peer
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1481
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1482 The request is parsed, and jingle_handler is called on concerned transport
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1483 plugin(s)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1484 @param client: %(doc_client)s
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1485 @param request: full <iq> request
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1486 @param jingle_elt: the <jingle> element
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1487 @param session: session data
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1488 """
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1489 log.debug(f"Jingle session {session['id']} has been accepted")
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1490
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1491 try:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1492 parsed_contents = self._parse_elements(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1493 jingle_elt, session, request, client, with_application=False,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1494 store_in_session=False
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1495 )
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1496 except exceptions.CancelError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1497 return
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1498
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1499 # The parsing was OK, we send the <iq> result
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1500 client.send(xmlstream.toResponse(request, "result"))
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1501
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1502 for content_name, content_data in session["contents"].items():
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1503 try:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1504 transport_elt = parsed_contents[content_name]["transport_elt"]
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1505 except KeyError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1506 continue
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1507 else:
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1508 utils.as_deferred(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1509 content_data["transport"].handler.jingle_handler,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1510 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1511 XEP_0166.A_TRANSPORT_INFO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1512 session,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1513 content_name,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1514 transport_elt,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1515 )
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
1516
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1517
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1518 @implementer(iwokkel.IDisco)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1519 class XEP_0166_handler(xmlstream.XMPPHandler):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1520
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1521 def __init__(self, plugin_parent):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1522 self.plugin_parent = plugin_parent
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1524 def connectionInitialized(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1525 self.xmlstream.addObserver(
3969
8e7d5796fb23 plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents: 3527
diff changeset
1526 JINGLE_REQUEST, self.plugin_parent._on_jingle_request, client=self.parent
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1527 )
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1528
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1529 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1530 return [disco.DiscoFeature(NS_JINGLE)]
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1531
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1532 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
1533 return []