annotate sat/plugins/plugin_xep_0166.py @ 2624:56f94936df1e

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