Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0166.py @ 4023:78b5f356900c
component AP gateway: handle attachments
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 23 Mar 2023 15:42:21 +0100 |
parents | 8e7d5796fb23 |
children | 524856bd7b19 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
3 # SàT plugin for Jingle (XEP-0166) |
3479 | 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 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
20 from collections import namedtuple |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
21 import time |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
22 from typing import Any, Dict, Tuple |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
23 import uuid |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
24 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
25 from twisted.internet import defer |
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
26 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
|
27 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
|
28 from twisted.words.protocols.jabber import jid |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
29 from twisted.words.protocols.jabber import error |
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
30 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
|
31 from twisted.words.xish import domish |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
32 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
|
33 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
|
34 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
35 from sat.core import exceptions |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 from sat.core.constants import Const as C |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
37 from sat.core.core_types import SatXMPPEntity |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
38 from sat.core.i18n import D_, _ |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 from sat.core.log import getLogger |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 from sat.tools import xml_tools |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
41 from sat.tools import utils |
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
42 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 log = getLogger(__name__) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 IQ_SET = '/iq[@type="set"]' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 NS_JINGLE = "urn:xmpp:jingle:1" |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
49 NS_JINGLE_ERROR = "urn:xmpp:jingle:errors:1" |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 JINGLE_REQUEST = IQ_SET + '/jingle[@xmlns="' + NS_JINGLE + '"]' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 STATE_PENDING = "PENDING" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 STATE_ACTIVE = "ACTIVE" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 STATE_ENDED = "ENDED" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 CONFIRM_TXT = D_("{entity} want to start a jingle session with you, do you accept ?") |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 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
|
65 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 ApplicationData = namedtuple("ApplicationData", ("namespace", "handler")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 TransportData = namedtuple("TransportData", ("namespace", "handler", "priority")) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
72 class XEP_0166: |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
73 namespace = NS_JINGLE |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
74 ROLE_INITIATOR = "initiator" |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
75 ROLE_RESPONDER = "responder" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 TRANSPORT_DATAGRAM = "UDP" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 TRANSPORT_STREAMING = "TCP" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 REASON_SUCCESS = "success" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 REASON_DECLINE = "decline" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 REASON_FAILED_APPLICATION = "failed-application" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 REASON_FAILED_TRANSPORT = "failed-transport" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 REASON_CONNECTIVITY_ERROR = "connectivity-error" |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 A_SESSION_INITIATE = "session-initiate" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 A_SESSION_ACCEPT = "session-accept" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 A_SESSION_TERMINATE = "session-terminate" |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
86 A_SESSION_INFO = "session-info" |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
87 A_TRANSPORT_REPLACE = "transport-replace" |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
88 A_TRANSPORT_ACCEPT = "transport-accept" |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
89 A_TRANSPORT_REJECT = "transport-reject" |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
90 A_TRANSPORT_INFO = "transport-info" |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 # non standard actions |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 A_PREPARE_INITIATOR = "prepare-initiator" # initiator must prepare tranfer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 A_PREPARE_RESPONDER = "prepare-responder" # responder must prepare tranfer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 A_ACCEPTED_ACK = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 "accepted-ack" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 ) # session accepted ack has been received from initiator |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 A_START = "start" # application can start |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 A_DESTROY = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 "destroy" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 ) # called when a transport is destroyed (e.g. because it is remplaced). Used to do cleaning operations |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 def __init__(self, host): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 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
|
104 self.host = host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 self._applications = {} # key: namespace, value: application data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 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
|
107 # 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
|
108 self._type_transports = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 XEP_0166.TRANSPORT_DATAGRAM: [], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 XEP_0166.TRANSPORT_STREAMING: [], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 } |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
113 def profileConnected(self, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 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
|
115 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
116 def getHandler(self, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 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
|
118 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 def _delSession(self, client, sid): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 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
|
122 except KeyError: |
3040 | 123 log.debug( |
124 f"Jingle session id {sid!r} is unknown, nothing to delete " | |
125 f"[{client.profile}]") | |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 else: |
3040 | 127 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
|
128 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 ## 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
|
130 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 def _buildJingleElt(self, client, session, action): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 iq_elt = client.IQ("set") |
2927
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
133 iq_elt["from"] = session['local_jid'].full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 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
|
135 jingle_elt = iq_elt.addElement("jingle", NS_JINGLE) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 jingle_elt["sid"] = session["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 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
|
138 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
|
139 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
140 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
|
141 """Send error stanza |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 @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
|
144 @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
|
145 @param request(domish.Element): original request |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
146 @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
|
147 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 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
|
149 if jingle_condition is not None: |
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
150 iq_elt.error.addElement((NS_JINGLE_ERROR, jingle_condition)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 if error.STANZA_CONDITIONS[error_condition]["type"] == "cancel" and sid: |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 self._delSession(client, sid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 log.warning( |
3028 | 154 "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
|
155 condition=error_condition |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 ) |
3040 | 158 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
|
159 |
2487
ed1d71b91b29
plugin XEP-0166: added errback to terminate, which only logs issues
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
160 def _terminateEb(self, failure_): |
3028 | 161 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
|
162 |
3527
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
163 def terminate(self, client, reason, session, text=None): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 """Terminate the session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 send the session-terminate action, and delete the session data |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 @param reason(unicode, list[domish.Element]): if unicode, will be transformed to an element |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if a list of element, add them as children of the <reason/> element |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 @param session(dict): data of the session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 iq_elt, jingle_elt = self._buildJingleElt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 client, session, XEP_0166.A_SESSION_TERMINATE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 reason_elt = jingle_elt.addElement("reason") |
3028 | 175 if isinstance(reason, str): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 reason_elt.addElement(reason) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 for elt in reason: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 reason_elt.addChild(elt) |
3527
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
180 if text is not None: |
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
181 reason_elt.addElement("text", content=text) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
182 self._delSession(client, session["id"]) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 d = iq_elt.send() |
2487
ed1d71b91b29
plugin XEP-0166: added errback to terminate, which only logs issues
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
184 d.addErrback(self._terminateEb) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 return d |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 ## 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
|
188 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
189 def _iqError(self, failure_, sid, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 """Called when we got an <iq/> error |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
192 @param failure_(failure.Failure): the exceptions raised |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 @param sid(unicode): jingle session id |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 log.warning( |
3028 | 196 "Error while sending jingle <iq/> stanza: {failure_}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 failure_=failure_.value |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
3040 | 202 def _jingleErrorCb(self, failure_, session, request, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 """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
|
204 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 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
|
206 exceptions.DataError raise a bad-request condition |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 @param fail(failure.Failure): the exceptions raised |
3040 | 208 @param session(dict): data of the session |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 @param request(domsih.Element): jingle request |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 @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
|
211 """ |
3040 | 212 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
|
213 if isinstance(failure_.value, defer.FirstError): |
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
214 failure_ = failure_.value.subFailure.value |
3040 | 215 if isinstance(failure_, exceptions.DataError): |
3527
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
216 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
|
217 elif isinstance(failure_, error.StanzaError): |
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
218 return self.terminate(client, self.REASON_FAILED_APPLICATION, session, |
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
219 text=str(failure_)) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 else: |
3040 | 221 log.error(f"Unmanaged jingle exception: {failure_}") |
3527
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
222 return self.terminate(client, self.REASON_FAILED_APPLICATION, session, |
bbf92ef05f38
plugin XEP-0166, XEP-0234: better management of `terminate`:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
223 text=str(failure_)) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 ## 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
|
226 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 def registerApplication(self, namespace, handler): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 """Register an application plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 @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
|
231 @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
|
232 May have the following methods: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 - requestConfirmation(session, desc_elt, client): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 - 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
|
235 - 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
|
236 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
|
237 - if not present, a generic accept dialog will be used |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
238 - jingleSessionInit(client, self, session, content_name[, *args, **kwargs]): must return the domish.Element used for initial content |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
239 - jingleHandler(client, self, action, session, content_name, transport_elt): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 called on several action to negociate the application or transport |
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
|
241 - jingleTerminate: called on session terminate, with reason_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
|
242 May be used to clean session |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 if namespace in self._applications: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 raise exceptions.ConflictError( |
3028 | 246 "Trying to register already registered namespace {}".format(namespace) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 self._applications[namespace] = ApplicationData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 namespace=namespace, handler=handler |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 ) |
3028 | 251 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
|
252 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 def registerTransport(self, namespace, transport_type, handler, priority=0): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 """Register a transport plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 @param namespace(unicode): the XML namespace used for this transport |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 @param transport_type(unicode): type of transport to use (see XEP-0166 §8) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 @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
|
259 Must have the following methods: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
260 - jingleSessionInit(client, self, session, content_name[, *args, **kwargs]): must return the domish.Element used for initial content |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
261 - jingleHandler(client, self, action, session, content_name, transport_elt): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 called on several action to negociate the application or transport |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 @param priority(int): priority of this transport |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 assert transport_type in ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 XEP_0166.TRANSPORT_DATAGRAM, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 XEP_0166.TRANSPORT_STREAMING, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 if namespace in self._transports: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 raise exceptions.ConflictError( |
3028 | 271 "Trying to register already registered namespace {}".format(namespace) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 transport_data = TransportData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 namespace=namespace, handler=handler, priority=priority |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 self._type_transports[transport_type].append(transport_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 self._type_transports[transport_type].sort( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 key=lambda transport_data: transport_data.priority, reverse=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 self._transports[namespace] = transport_data |
3028 | 281 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
|
282 |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
283 @defer.inlineCallbacks |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
284 def transportReplace(self, client, transport_ns, session, content_name): |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
285 """Replace a transport |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
286 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
287 @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
|
288 @param session(dict): jingle session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
289 @param content_name(unicode): name of the content |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
290 """ |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
291 # 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
|
292 # 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
|
293 # this behavious may change in the future. |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 transport_data = content_data["transport_data"] |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
296 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
297 transport = self._transports[transport_ns] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
298 except KeyError: |
3028 | 299 raise exceptions.InternalError("Unkown transport") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
300 yield content_data["transport"].handler.jingleHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 client, XEP_0166.A_DESTROY, session, content_name, None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
302 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
303 content_data["transport"] = transport |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
304 transport_data.clear() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
305 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
306 iq_elt, jingle_elt = self._buildJingleElt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
307 client, session, XEP_0166.A_TRANSPORT_REPLACE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
308 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 content_elt = jingle_elt.addElement("content") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 content_elt["name"] = content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 content_elt["creator"] = content_data["creator"] |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
312 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
313 transport_elt = transport.handler.jingleSessionInit(client, session, content_name) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
314 content_elt.addChild(transport_elt) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
315 iq_elt.send() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
316 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
317 def buildAction(self, client, action, session, content_name): |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
318 """Build an element according to requested action |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
319 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
320 @param action(unicode): a jingle action (see XEP-0166 §7.2), |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
321 session-* actions are not managed here |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
322 transport-replace is managed in the dedicated [transportReplace] method |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
323 @param session(dict): jingle session data |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
324 @param content_name(unicode): name of the content |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
325 @return (tuple[domish.Element, domish.Element]): parent <iq> element, <transport> or <description> element, according to action |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
326 """ |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
327 # we first build iq, jingle and content element which are the same in every cases |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
328 iq_elt, jingle_elt = self._buildJingleElt(client, session, action) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
329 # 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
|
330 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 content_elt = jingle_elt.addElement("content") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 content_elt["name"] = content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
333 content_elt["creator"] = content_data["creator"] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
334 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
335 if action == XEP_0166.A_TRANSPORT_INFO: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
336 context_elt = transport_elt = content_elt.addElement( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 "transport", content_data["transport"].namespace |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
339 transport_elt["sid"] = content_data["transport_data"]["sid"] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
340 else: |
3028 | 341 raise exceptions.InternalError("unmanaged action {}".format(action)) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
342 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
343 return iq_elt, context_elt |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
344 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
345 def buildSessionInfo(self, client, session): |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
346 """Build a session-info action |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
347 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
348 @param session(dict): jingle session data |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
349 @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
|
350 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
351 return self._buildJingleElt(client, session, XEP_0166.A_SESSION_INFO) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
352 |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
353 def getApplication(self, namespace: str) -> object: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
354 """Retreive application corresponding to a namespace |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
355 |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
356 @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
|
357 """ |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
358 try: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
359 return self._applications[namespace] |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
360 except KeyError: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
361 raise exceptions.NotFound( |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
362 f"No application registered for {namespace}" |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
363 ) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
364 |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
365 def getContentData(self, content: dict) -> Tuple[object, list, dict, str]: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
366 """"Retrieve application and its argument from content""" |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
367 app_ns = content["app_ns"] |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
368 try: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
369 application = self.getApplication(app_ns) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
370 except exceptions.NotFound as e: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
371 raise exceptions.InternalError(str(e)) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
372 app_args = content.get("app_args", []) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
373 app_kwargs = content.get("app_kwargs", {}) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
374 try: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
375 content_name = content["name"] |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
376 except KeyError: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
377 content_name = content["name"] = str(uuid.uuid4()) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
378 return application, app_args, app_kwargs, content_name |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
379 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
380 async def initiate(self, client, peer_jid, contents, encrypted=False): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 """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
|
382 |
1567
268fda4236ca
plugins XE0166, XEP-0234, XEP-0260, XEP-0261: renamed session key managing other peer's jid to "peer_jid" instead of "to_jid"
Goffi <goffi@goffi.org>
parents:
1556
diff
changeset
|
383 @param peer_jid(jid.JID): jid to establith session with |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 @param contents(list[dict]): list of contents to use: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 The dict must have the following keys: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 - app_ns(unicode): namespace of the application |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 the following keys are optional: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 - transport_type(unicode): type of transport to use (see XEP-0166 §8) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 default to TRANSPORT_STREAMING |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 - name(unicode): name of the content |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
391 - senders(unicode): One of XEP_0166.ROLE_INITIATOR, XEP_0166.ROLE_RESPONDER, both or none |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
392 default 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
|
393 - 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
|
394 - 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
|
395 @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
|
396 to all content data of session |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
397 @return (unicode): jingle session id |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
399 assert contents # there must be at least one content |
2927
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
400 if (peer_jid == client.jid |
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
401 or client.is_component and peer_jid.host == client.jid.host): |
3028 | 402 raise ValueError(_("You can't do a jingle session with yourself")) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 initiator = client.jid |
3028 | 404 sid = str(uuid.uuid4()) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 # TODO: session cleaning after timeout ? |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
406 session = client.jingle_sessions[sid] = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
407 "id": sid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
408 "state": STATE_PENDING, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 "initiator": initiator, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
410 "role": XEP_0166.ROLE_INITIATOR, |
2927
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
411 "local_jid": client.jid, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 "peer_jid": peer_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 "started": time.time(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 "contents": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 } |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
416 |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
417 if not await self.host.trigger.asyncPoint( |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
418 "XEP-0166_initiate", |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
419 client, session, contents |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
420 ): |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
421 return |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
422 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
423 iq_elt, jingle_elt = self._buildJingleElt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
424 client, session, XEP_0166.A_SESSION_INITIATE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 jingle_elt["initiator"] = initiator.full() |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 contents_dict = session["contents"] |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 for content in contents: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 # we get the application plugin |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
432 application, app_args, app_kwargs, content_name = self.getContentData(content) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 # and the transport plugin |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 transport_type = content.get("transport_type", XEP_0166.TRANSPORT_STREAMING) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
437 transport = self._type_transports[transport_type][0] |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 except IndexError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
439 raise exceptions.InternalError( |
3028 | 440 "No transport registered for {}".format(transport_type) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
441 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
442 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 # we build the session data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
444 content_data = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
445 "application": application, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
446 "application_data": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
447 "transport": transport, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
448 "transport_data": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
449 "creator": XEP_0166.ROLE_INITIATOR, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 "senders": content.get("senders", "both"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
451 } |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
452 if content_name in contents_dict: |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
453 raise exceptions.InternalError( |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
454 "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
|
455 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 contents_dict[content_name] = content_data |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 # we construct the content element |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
459 content_elt = jingle_elt.addElement("content") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
460 content_elt["creator"] = content_data["creator"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
461 content_elt["name"] = content_name |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
462 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
463 content_elt["senders"] = content["senders"] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
464 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
465 pass |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 # then the description element |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
468 desc_elt = await utils.asDeferred( |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
469 application.handler.jingleSessionInit, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
470 client, session, content_name, *app_args, **app_kwargs |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
471 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 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
|
473 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 # and the transport one |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
475 transport_elt = await utils.asDeferred( |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
476 transport.handler.jingleSessionInit, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
477 client, session, content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
478 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 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
|
480 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
481 if not await self.host.trigger.asyncPoint( |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
482 "XEP-0166_initiate_elt_built", |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
483 client, session, iq_elt, jingle_elt |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
484 ): |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
485 return |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
486 if encrypted: |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 "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
|
491 ) |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
492 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
493 try: |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
494 await iq_elt.send() |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
495 except Exception as e: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
496 failure_ = failure.Failure(e) |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
497 self._iqError(failure_, sid, client) |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
498 raise failure_ |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 |
1617
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
500 def delayedContentTerminate(self, *args, **kwargs): |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
501 """Put contentTerminate in queue but don't execute immediately |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
502 |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
503 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
|
504 """ |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
505 reactor.callLater(0, self.contentTerminate, *args, **kwargs) |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
506 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
507 def contentTerminate(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
|
508 """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
|
509 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 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
|
511 @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
|
512 @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
|
513 @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
|
514 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
515 contents = session["contents"] |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 del contents[content_name] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 if not contents: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
518 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
|
519 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 ## 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
|
521 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
522 def jingleRequestConfirmationDefault( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
523 self, client, action, session, content_name, desc_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
524 ): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 """This method request confirmation for a jingle session""" |
3028 | 526 log.debug("Using generic jingle confirmation method") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
527 return xml_tools.deferConfirm( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
528 self.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
529 _(CONFIRM_TXT).format(entity=session["peer_jid"].full()), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
530 _("Confirm Jingle session"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
531 profile=client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
532 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
533 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 ## jingle events ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
536 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
|
537 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
|
538 |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
539 async def on_jingle_request( |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
540 self, |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
541 client: SatXMPPEntity, |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
542 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
|
543 ) -> None: |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 """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
|
545 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
546 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
|
547 according to current state |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 @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
|
549 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 request.handled = True |
3028 | 551 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
|
552 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 # 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
|
554 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
555 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
|
556 if not sid: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
557 raise KeyError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 except KeyError: |
3028 | 559 log.warning("Received jingle request has no sid attribute") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
560 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
|
561 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
563 # then the action |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
565 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
|
566 if not action: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 raise KeyError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 except KeyError: |
3028 | 569 log.warning("Received jingle request has no action") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
570 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
|
571 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
573 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
|
574 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 # 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
|
576 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 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
|
578 except KeyError: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
579 if action == XEP_0166.A_SESSION_INITIATE: |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
580 pass |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
581 elif action == XEP_0166.A_SESSION_TERMINATE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
582 log.debug( |
3028 | 583 "ignoring session terminate action (inexisting session id): {request_id} [{profile}]".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
584 request_id=sid, profile=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
585 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
586 ) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
587 return |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
588 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
589 log.warning( |
3028 | 590 "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
|
591 request_id=sid, profile=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
592 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
593 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
594 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
|
595 return |
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
596 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
597 session = client.jingle_sessions[sid] = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
598 "id": sid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
599 "state": STATE_PENDING, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
600 "initiator": peer_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
601 "role": XEP_0166.ROLE_RESPONDER, |
2927
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
602 # we store local_jid using request['to'] because for a component the jid |
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
603 # used may not be client.jid (if a local part is used). |
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
604 "local_jid": jid.JID(request['to']), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
605 "peer_jid": peer_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
606 "started": time.time(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
607 } |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
608 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
609 if session["peer_jid"] != peer_jid: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
610 log.warning( |
3028 | 611 "sid conflict ({}), the jid doesn't match. Can be a collision, a hack attempt, or a bad sid generation".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
612 sid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
613 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
614 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
615 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
|
616 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
617 if session["id"] != sid: |
3028 | 618 log.error("session id doesn't match") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
619 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
|
620 raise exceptions.InternalError |
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 if action == XEP_0166.A_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
|
623 await self.onSessionInitiate(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
|
624 elif action == XEP_0166.A_SESSION_TERMINATE: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 self.onSessionTerminate(client, request, jingle_elt, session) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
626 elif action == XEP_0166.A_SESSION_ACCEPT: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 self.onSessionAccept(client, request, jingle_elt, session) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
628 elif action == XEP_0166.A_SESSION_INFO: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
629 self.onSessionInfo(client, request, jingle_elt, session) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
630 elif action == XEP_0166.A_TRANSPORT_INFO: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
631 self.onTransportInfo(client, request, jingle_elt, session) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
632 elif action == XEP_0166.A_TRANSPORT_REPLACE: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
633 self.onTransportReplace(client, request, jingle_elt, session) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
634 elif action == XEP_0166.A_TRANSPORT_ACCEPT: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
635 self.onTransportAccept(client, request, jingle_elt, session) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
636 elif action == XEP_0166.A_TRANSPORT_REJECT: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
637 self.onTransportReject(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
|
638 else: |
3028 | 639 raise exceptions.InternalError("Unknown action {}".format(action)) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 ## Actions callbacks ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
643 def _parseElements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
644 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
645 jingle_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
646 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
647 request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
648 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
649 new=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
650 creator=ROLE_INITIATOR, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
651 with_application=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
652 with_transport=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
653 ): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
654 """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
|
655 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 after the parsing, contents_dict will containt handlers, "desc_elt" and "transport_elt" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 @param jingle_elt(domish.Element): parent <jingle> element, containing one or more <content> |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
658 @param session(dict): session data |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
659 @param request(domish.Element): the whole request |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
660 @param client: %(doc_client)s |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
661 @param new(bool): 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
|
662 else the content must exists, and session data will be filled |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
663 @param creator(unicode): only used if new is True: creating pear (see § 7.3) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
664 @param with_application(bool): if True, raise an error if there is no <description> element else ignore it |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
665 @param with_transport(bool): if True, raise an error if there is no <transport> element else ignore it |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
666 @raise exceptions.CancelError: the error is treated and the calling method can 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
|
667 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
668 contents_dict = session["contents"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
669 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
|
670 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
671 for content_elt in content_elts: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
672 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
|
673 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 if new: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 # 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
|
676 if not name or name in contents_dict: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
677 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
|
678 raise exceptions.CancelError |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
679 content_data = contents_dict[name] = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
680 "creator": creator, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
681 "senders": content_elt.attributes.get("senders", "both"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
682 } |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 # 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
|
685 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 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
|
687 except KeyError: |
3028 | 688 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
|
689 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
|
690 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 # application |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
693 if with_application: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
694 desc_elt = content_elt.description |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
695 if not desc_elt: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
696 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
|
697 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
698 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
699 if new: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
700 # 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
|
701 app_ns = desc_elt.uri |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
702 if not app_ns or app_ns == NS_JINGLE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
703 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
|
704 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
706 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
707 application = self._applications[app_ns] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
708 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
709 log.warning( |
3028 | 710 "Unmanaged application namespace [{}]".format(app_ns) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
711 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
712 self.sendError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
713 client, "service-unavailable", session["id"], request |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
714 ) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
715 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
716 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
717 content_data["application"] = application |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
718 content_data["application_data"] = {} |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
719 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
720 # 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
|
721 if "desc_elt" in content_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
722 raise exceptions.InternalError( |
3028 | 723 "desc_elt should not exist at this point" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
724 ) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
725 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
726 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
|
727 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
728 # transport |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
729 if with_transport: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
730 transport_elt = content_elt.transport |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
731 if not transport_elt: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
732 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
|
733 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
734 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
735 if new: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
736 # 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
|
737 transport_ns = transport_elt.uri |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
738 if not app_ns or app_ns == NS_JINGLE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
739 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
|
740 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
742 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
743 transport = self._transports[transport_ns] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
744 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
745 raise exceptions.InternalError( |
3028 | 746 "No transport registered for namespace {}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
747 transport_ns |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
748 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
749 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
750 content_data["transport"] = transport |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
751 content_data["transport_data"] = {} |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
752 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
753 # 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
|
754 if "transport_elt" in content_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
755 raise exceptions.InternalError( |
3028 | 756 "transport_elt should not exist at this point" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
757 ) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
758 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
759 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
|
760 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
761 def _ignore(self, client, action, session, content_name, 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
|
762 """Dummy method used when not exception must be raised if a method is not implemented in _callPlugins |
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
|
763 |
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
|
764 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
|
765 """ |
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
|
766 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
|
767 |
3040 | 768 def _callPlugins(self, client, action, session, app_method_name="jingleHandler", |
769 transp_method_name="jingleHandler", app_default_cb=None, | |
770 transp_default_cb=None, delete=True, elements=True, | |
771 force_element=None): | |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
772 """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
|
773 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
774 @param action(unicode): jingle action name |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
775 @param session(dict): jingle session data |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
776 @param app_method_name(unicode, None): name of the method to call for applications |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
777 None to ignore |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
778 @param transp_method_name(unicode, None): name of the method to call for transports |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
779 None to ignore |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
780 @param app_default_cb(callable, None): default callback to use if plugin has not app_method_name |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
781 None to raise an exception instead |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
782 @param transp_default_cb(callable, None): default callback to use if plugin has not transp_method_name |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
783 None to raise an exception instead |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
784 @param delete(bool): if True, remove desc_elt and transport_elt from session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
785 ignored if elements is False |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
786 @param elements(bool): True if elements(desc_elt and tranport_elt) must be managed |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
787 must be True if _callPlugins is used in a request, and False if it used after a request |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
788 (i.e. on <iq> result or error) |
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
|
789 @param force_element(None, domish.Element, object): 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
|
790 else it is ignored |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
791 @return (list[defer.Deferred]): list of launched Deferred |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
792 @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
|
793 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
794 contents_dict = session["contents"] |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 defers_list = [] |
3028 | 796 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
|
797 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
|
798 (app_method_name, "application", app_default_cb, "desc_elt"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
799 (transp_method_name, "transport", transp_default_cb, "transport_elt"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
800 ): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
801 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
|
802 continue |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
803 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
804 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
|
805 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
806 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
|
807 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
|
808 if default_cb is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
809 raise exceptions.NotFound( |
3028 | 810 "{} not implemented !".format(method_name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
811 ) |
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
|
812 else: |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
813 method = default_cb |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
814 if elements: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
815 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
|
816 else: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
817 elt = force_element |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
818 d = utils.asDeferred( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
819 method, client, action, session, content_name, elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
820 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
821 defers_list.append(d) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
822 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
823 return defers_list |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
824 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
825 async def onSessionInitiate( |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
826 self, |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
827 client: SatXMPPEntity, |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
828 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
|
829 jingle_elt: domish.Element, |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
830 session: Dict[str, Any] |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
831 ) -> None: |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
832 """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
|
833 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
834 The "jingleRequestConfirmation" method of each application will be called |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
835 (or self.jingleRequestConfirmationDefault if the former doesn't exist). |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
836 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
|
837 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
|
838 @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
|
839 @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
|
840 @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
|
841 @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
|
842 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
843 if "contents" in session: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
844 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
845 "Contents dict should not already exist at this point" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
846 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
847 session["contents"] = contents_dict = {} |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
848 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
849 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
850 self._parseElements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
851 jingle_elt, session, request, client, True, XEP_0166.ROLE_INITIATOR |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
852 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
853 except exceptions.CancelError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
854 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
855 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
856 if not contents_dict: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
857 # there MUST be at least one content |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
858 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
|
859 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
860 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
861 # 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
|
862 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
|
863 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
864 |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
865 if not await self.host.trigger.asyncPoint( |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
866 "XEP-0166_on_session_initiate", |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
867 client, session, request, jingle_elt |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
868 ): |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
869 return |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
870 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
871 # 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
|
872 # and if all are accepted, we can accept the session |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
873 confirm_defers = self._callPlugins( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
874 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
875 XEP_0166.A_SESSION_INITIATE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
876 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
877 "jingleRequestConfirmation", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
878 None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
879 self.jingleRequestConfirmationDefault, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
880 delete=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
881 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
882 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
883 confirm_dlist = defer.gatherResults(confirm_defers) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
884 confirm_dlist.addCallback(self._confirmationCb, session, jingle_elt, client) |
3040 | 885 confirm_dlist.addErrback(self._jingleErrorCb, session, request, client) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
886 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
887 def _confirmationCb(self, confirm_results, session, jingle_elt, client): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
888 """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
|
889 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
890 This method is only called for the responder |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
891 @param confirm_results(list[bool]): all True if session is accepted |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
892 @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
|
893 @param jingle_elt(domish.Element): jingle data of this session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
894 @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
|
895 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
896 confirmed = all(confirm_results) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
897 if not confirmed: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
898 return self.terminate(client, XEP_0166.REASON_DECLINE, session) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
899 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
900 iq_elt, jingle_elt = self._buildJingleElt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
901 client, session, XEP_0166.A_SESSION_ACCEPT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
902 ) |
2927
69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents:
2920
diff
changeset
|
903 jingle_elt["responder"] = session['local_jid'].full() |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
904 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
905 # contents |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
906 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
907 def addElement(domish_elt, content_elt): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
908 content_elt.addChild(domish_elt) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
909 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
910 defers_list = [] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
911 |
3028 | 912 for content_name, content_data in session["contents"].items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
913 content_elt = jingle_elt.addElement("content") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
914 content_elt["creator"] = XEP_0166.ROLE_INITIATOR |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
915 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
|
916 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
917 application = content_data["application"] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
918 app_session_accept_cb = application.handler.jingleHandler |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
919 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
920 app_d = utils.asDeferred( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
921 app_session_accept_cb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
922 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
923 XEP_0166.A_SESSION_INITIATE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
924 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
925 content_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
926 content_data.pop("desc_elt"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
927 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
928 app_d.addCallback(addElement, content_elt) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
929 defers_list.append(app_d) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
930 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
931 transport = content_data["transport"] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
932 transport_session_accept_cb = transport.handler.jingleHandler |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
933 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
934 transport_d = utils.asDeferred( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
935 transport_session_accept_cb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
936 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
937 XEP_0166.A_SESSION_INITIATE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
938 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
939 content_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
940 content_data.pop("transport_elt"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
941 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
942 transport_d.addCallback(addElement, content_elt) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
943 defers_list.append(transport_d) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
944 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
945 d_list = defer.DeferredList(defers_list) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
946 d_list.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
947 lambda __: self._callPlugins( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
948 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
949 XEP_0166.A_PREPARE_RESPONDER, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
950 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
951 app_method_name=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
952 elements=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
953 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
954 ) |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
955 d_list.addCallback(lambda __: iq_elt.send()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
956 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
957 def changeState(__, session): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
958 session["state"] = STATE_ACTIVE |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
959 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
960 d_list.addCallback(changeState, session) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
961 d_list.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
962 lambda __: self._callPlugins( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
963 client, XEP_0166.A_ACCEPTED_ACK, session, elements=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
964 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
965 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
966 d_list.addErrback(self._iqError, session["id"], client) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
967 return d_list |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
968 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
969 def onSessionTerminate(self, client, request, jingle_elt, session): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
970 # TODO: check reason, display a message to user if needed |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
971 log.debug("Jingle Session {} terminated".format(session["id"])) |
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
|
972 try: |
3028 | 973 reason_elt = next(jingle_elt.elements(NS_JINGLE, "reason")) |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
974 except StopIteration: |
3028 | 975 log.warning("No reason given for session termination") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
976 reason_elt = jingle_elt.addElement("reason") |
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
|
977 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
978 terminate_defers = self._callPlugins( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
979 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
980 XEP_0166.A_SESSION_TERMINATE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
981 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
982 "jingleTerminate", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
983 "jingleTerminate", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
984 self._ignore, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
985 self._ignore, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
986 elements=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
987 force_element=reason_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
988 ) |
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
|
989 terminate_dlist = defer.DeferredList(terminate_defers) |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
990 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
991 terminate_dlist.addCallback(lambda __: self._delSession(client, session["id"])) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
992 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
|
993 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
994 def onSessionAccept(self, client, request, jingle_elt, session): |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
995 """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
|
996 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
997 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
|
998 @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
|
999 @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
|
1000 @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
|
1001 @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
|
1002 """ |
3028 | 1003 log.debug("Jingle session {} has been accepted".format(session["id"])) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1004 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1005 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1006 self._parseElements(jingle_elt, session, request, client) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1007 except exceptions.CancelError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1008 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1009 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1010 # 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
|
1011 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
|
1012 # and change the state |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1013 session["state"] = STATE_ACTIVE |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1014 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1015 negociate_defers = [] |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2487
diff
changeset
|
1016 negociate_defers = self._callPlugins(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
|
1017 |
3040 | 1018 negociate_dlist = defer.gatherResults(negociate_defers) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1019 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1020 # after negociations we start the transfer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1021 negociate_dlist.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1022 lambda __: self._callPlugins( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1023 client, XEP_0166.A_START, session, app_method_name=None, elements=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1024 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1025 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1026 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1027 def _onSessionCb(self, result, client, request, jingle_elt, session): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1028 client.send(xmlstream.toResponse(request, "result")) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1029 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1030 def _onSessionEb(self, failure_, client, request, jingle_elt, session): |
3028 | 1031 log.error("Error while handling onSessionInfo: {}".format(failure_.value)) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1032 # XXX: only error managed so far, maybe some applications/transports need more |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1033 self.sendError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1034 client, "feature-not-implemented", None, request, "unsupported-info" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1035 ) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1036 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1037 def onSessionInfo(self, client, request, jingle_elt, session): |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1038 """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
|
1039 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1040 This method is only called for initiator |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1041 @param client: %(doc_client)s |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1042 @param request(domish.Element): full <iq> request |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1043 @param jingle_elt(domish.Element): the <jingle> element |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1044 @param session(dict): session data |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1045 """ |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1046 if not jingle_elt.children: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1047 # 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
|
1048 client.send(xmlstream.toResponse(request, "result")) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1049 return |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1050 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1051 try: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1052 # XXX: session-info is most likely only used for application, so we don't call transport plugins |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1053 # if a future transport use it, this behaviour must be adapted |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1054 defers = self._callPlugins( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1055 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1056 XEP_0166.A_SESSION_INFO, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1057 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1058 "jingleSessionInfo", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1059 None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1060 elements=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1061 force_element=jingle_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1062 ) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1063 except exceptions.NotFound as e: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1064 self._onSessionEb(failure.Failure(e), client, request, jingle_elt, session) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1065 return |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1066 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1067 dlist = defer.DeferredList(defers, fireOnOneErrback=True) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1068 dlist.addCallback(self._onSessionCb, client, request, jingle_elt, session) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1069 dlist.addErrback(self._onSessionCb, client, request, jingle_elt, session) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
1070 |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1071 @defer.inlineCallbacks |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1072 def onTransportReplace(self, client, request, jingle_elt, session): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1073 """A transport change is requested |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1074 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1075 The request is parsed, and jingleHandler is called on concerned transport plugin(s) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1076 @param client: %(doc_client)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1077 @param request(domish.Element): full <iq> request |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1078 @param jingle_elt(domish.Element): the <jingle> element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1079 @param session(dict): session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1080 """ |
3028 | 1081 log.debug("Other peer wants to replace the transport") |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1082 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1083 self._parseElements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1084 jingle_elt, session, request, client, with_application=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1085 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1086 except exceptions.CancelError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1087 defer.returnValue(None) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1088 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1089 client.send(xmlstream.toResponse(request, "result")) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1090 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1091 content_name = None |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1092 to_replace = [] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1093 |
3028 | 1094 for content_name, content_data in session["contents"].items(): |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1095 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1096 transport_elt = content_data.pop("transport_elt") |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1097 except KeyError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1098 continue |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1099 transport_ns = transport_elt.uri |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1100 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1101 transport = self._transports[transport_ns] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1102 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1103 log.warning( |
3028 | 1104 "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
|
1105 transport_ns |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1106 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1107 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1108 content_name = None |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1109 break |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1110 to_replace.append((content_name, content_data, transport, transport_elt)) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1111 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1112 if content_name is None: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1113 # wa can't accept the replacement |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1114 iq_elt, reject_jingle_elt = self._buildJingleElt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1115 client, session, XEP_0166.A_TRANSPORT_REJECT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1116 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1117 for child in jingle_elt.children: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1118 reject_jingle_elt.addChild(child) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1119 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1120 iq_elt.send() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1121 defer.returnValue(None) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1122 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1123 # 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
|
1124 # this is similar to an session-accept action, but for transports only |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1125 iq_elt, accept_jingle_elt = self._buildJingleElt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1126 client, session, XEP_0166.A_TRANSPORT_ACCEPT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1127 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1128 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
|
1129 # we can now actually replace the transport |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1130 yield content_data["transport"].handler.jingleHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1131 client, XEP_0166.A_DESTROY, session, content_name, None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1132 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1133 content_data["transport"] = transport |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1134 content_data["transport_data"].clear() |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1135 # and build the element |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1136 content_elt = accept_jingle_elt.addElement("content") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1137 content_elt["name"] = content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1138 content_elt["creator"] = content_data["creator"] |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1139 # we notify the transport and insert its <transport/> in the answer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1140 accept_transport_elt = yield transport.handler.jingleHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1141 client, XEP_0166.A_TRANSPORT_REPLACE, session, content_name, transport_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1142 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1143 content_elt.addChild(accept_transport_elt) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1144 # there is no confirmation needed here, so we can directly prepare it |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1145 yield transport.handler.jingleHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1146 client, XEP_0166.A_PREPARE_RESPONDER, session, content_name, None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1147 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1148 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1149 iq_elt.send() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1150 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1151 def onTransportAccept(self, client, request, jingle_elt, session): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1152 """Method called once transport replacement is accepted |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1153 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1154 @param client: %(doc_client)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1155 @param request(domish.Element): full <iq> request |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1156 @param jingle_elt(domish.Element): the <jingle> element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1157 @param session(dict): session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1158 """ |
3028 | 1159 log.debug("new transport has been accepted") |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1160 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1161 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1162 self._parseElements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1163 jingle_elt, session, request, client, with_application=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1164 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1165 except exceptions.CancelError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1166 return |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1167 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1168 # 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
|
1169 client.send(xmlstream.toResponse(request, "result")) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1170 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1171 negociate_defers = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1172 negociate_defers = self._callPlugins( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1173 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
|
1174 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1175 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1176 negociate_dlist = defer.DeferredList(negociate_defers) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1177 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1178 # after negociations we start the transfer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1179 negociate_dlist.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1180 lambda __: self._callPlugins( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1181 client, XEP_0166.A_START, session, app_method_name=None, elements=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1182 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1183 ) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1184 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1185 def onTransportReject(self, client, request, jingle_elt, session): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1186 """Method called when a transport replacement is refused |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1187 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1188 @param client: %(doc_client)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1189 @param request(domish.Element): full <iq> request |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1190 @param jingle_elt(domish.Element): the <jingle> element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1191 @param session(dict): session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1192 """ |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1193 # 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
|
1194 # this behaviour may change in the future |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1195 self.terminate(client, "failed-transport", session) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
1196 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1197 def onTransportInfo(self, client, request, jingle_elt, session): |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1198 """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
|
1199 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1200 The request is parsed, and jingleHandler is called on concerned transport plugin(s) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1201 @param client: %(doc_client)s |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1202 @param request(domish.Element): full <iq> request |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1203 @param jingle_elt(domish.Element): the <jingle> element |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1204 @param session(dict): session data |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1205 """ |
3028 | 1206 log.debug("Jingle session {} has been accepted".format(session["id"])) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1207 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1208 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1209 self._parseElements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1210 jingle_elt, session, request, client, with_application=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1211 ) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1212 except exceptions.CancelError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1213 return |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1214 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1215 # The parsing was OK, we send the <iq> result |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1216 client.send(xmlstream.toResponse(request, "result")) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1217 |
3028 | 1218 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
|
1219 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1220 transport_elt = content_data.pop("transport_elt") |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1221 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1222 continue |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1223 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1224 content_data["transport"].handler.jingleHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1225 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1226 XEP_0166.A_TRANSPORT_INFO, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1227 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1228 content_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1229 transport_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1230 ) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
1231 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1232 |
3028 | 1233 @implementer(iwokkel.IDisco) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1234 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
|
1235 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1236 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
|
1237 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
|
1238 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1239 def connectionInitialized(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1240 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
|
1241 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
|
1242 ) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1243 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1244 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
|
1245 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
|
1246 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1247 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
|
1248 return [] |