annotate libervia/backend/plugins/plugin_xep_0166/__init__.py @ 4270:0d7bb4df2343

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