annotate src/plugins/plugin_xep_0166.py @ 2489:e2a7bb875957

plugin pipe/stream, file transfert: refactoring and improvments: this is a big patch as things had to be changed at the same time. - changed methods using profile argument to use client instead - move SatFile in a new tools.stream module, has it should be part of core, not a plugin - new IStreamProducer interface, to handler starting a pull producer - new FileStreamObject which create a stream producer/consumer from a SatFile - plugin pipe is no more using unix named pipe, as it complicate the thing, special care need to be taken to not block, and it's generally not necessary. Instead a socket is now used, so the plugin has been renomed to jingle stream. - bad connection/error should be better handler in jingle stream plugin, and code should not block anymore - jp pipe commands have been updated accordingly fix bug 237
author Goffi <goffi@goffi.org>
date Thu, 08 Feb 2018 00:37:42 +0100
parents ed1d71b91b29
children 7ad5f2c4e34a
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
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
25 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
26 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
27 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
28 from twisted.internet import reactor
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
29 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
30 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
31 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
32 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
33 from collections import namedtuple
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
34 import uuid
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
35 import time
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
36
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
37 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
38
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",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
54 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
55 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
56 C.PI_HANDLER: "yes",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
57 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
58 }
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
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
61 ApplicationData = namedtuple('ApplicationData', ('namespace', 'handler'))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
62 TransportData = namedtuple('TransportData', ('namespace', 'handler', 'priority'))
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
63
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 class XEP_0166(object):
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
66 ROLE_INITIATOR = "initiator"
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
67 ROLE_RESPONDER = "responder"
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
68 TRANSPORT_DATAGRAM='UDP'
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
69 TRANSPORT_STREAMING='TCP'
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
70 REASON_SUCCESS='success'
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
71 REASON_DECLINE='decline'
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
72 REASON_FAILED_APPLICATION='failed-application'
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
73 REASON_FAILED_TRANSPORT='failed-transport'
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
74 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
75 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
76 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
77 A_SESSION_TERMINATE = "session-terminate"
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
78 A_SESSION_INFO = "session-info"
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
79 A_TRANSPORT_REPLACE = "transport-replace"
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
80 A_TRANSPORT_ACCEPT = "transport-accept"
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
81 A_TRANSPORT_REJECT = "transport-reject"
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
82 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
83 # non standard actions
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
84 A_PREPARE_INITIATOR = "prepare-initiator" # initiator must prepare tranfer
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
85 A_PREPARE_RESPONDER = "prepare-responder" # responder must prepare tranfer
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
86 A_ACCEPTED_ACK = "accepted-ack" # session accepted ack has been received from initiator
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
87 A_START = "start" # application can start
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
88 A_DESTROY = "destroy" # 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
89
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
90 def __init__(self, host):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
91 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
92 self.host = host
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self._applications = {} # key: namespace, value: application data
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self._transports = {} # key: namespace, value: transport data
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
95 # we also keep transports by type, they are then sorted by priority
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self._type_transports = { XEP_0166.TRANSPORT_DATAGRAM: [],
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
97 XEP_0166.TRANSPORT_STREAMING: [],
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
98 }
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
99
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
100 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
101 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
102
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
103 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
104 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
105
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
106 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
107 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
108 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
109 except KeyError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
110 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
111 else:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
112 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
113
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
114 ## 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
115
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
116 def _buildJingleElt(self, client, session, action):
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
117 iq_elt = client.IQ('set')
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
118 iq_elt['from'] = client.jid.full()
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
119 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
120 jingle_elt = iq_elt.addElement("jingle", NS_JINGLE)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
121 jingle_elt["sid"] = session['id']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
122 jingle_elt['action'] = action
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
123 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
124
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
125 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
126 """Send error stanza
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
127
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
128 @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
129 @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
130 @param request(domish.Element): original request
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
131 @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
132 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
133 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
134 if jingle_condition is not None:
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
135 iq_elt.error.addElement((NS_JINGLE_ERROR, jingle_condition))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
136 if error.STANZA_CONDITIONS[error_condition]['type'] == 'cancel' and sid:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
137 self._delSession(client, sid)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
138 log.warning(u"Error while managing jingle session, cancelling: {condition}".format(error_condition))
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
139 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
140
2487
ed1d71b91b29 plugin XEP-0166: added errback to terminate, which only logs issues
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
141 def _terminateEb(self, failure_):
ed1d71b91b29 plugin XEP-0166: added errback to terminate, which only logs issues
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
142 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
143
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
144 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
145 """Terminate the session
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
146
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
147 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
148 @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
149 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
150 @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
151 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
152 iq_elt, jingle_elt = self._buildJingleElt(client, session, 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
153 reason_elt = jingle_elt.addElement('reason')
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
154 if isinstance(reason, basestring):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
155 reason_elt.addElement(reason)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
156 else:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
157 for elt in reason:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
158 reason_elt.addChild(elt)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
159 self._delSession(client, session['id'])
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
160 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
161 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
162 return d
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
163
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
164 ## 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
165
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
166 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
167 """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
168
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
169 @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
170 @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
171 """
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
172 log.warning(u"Error while sending jingle <iq/> stanza: {failure_}".format(failure_=failure_.value))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self._delSession(client, sid)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
174
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
175 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
176 """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
177
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
178 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
179 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
180 @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
181 @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
182 @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
183 @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
184 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
185 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
186 if isinstance(fail, exceptions.DataError):
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
187 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
188 else:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
189 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
190 self._delSession(client, sid)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
191 raise fail
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
192
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
193 ## 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
194
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
195 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
196 """Register an application plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
197
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
198 @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
199 @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
200 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
201 - 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
202 - 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
203 - 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
204 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
205 - 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
206 - 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
207 - 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
208 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
209 - 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
210 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
211 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
212 if namespace in self._applications:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
213 raise exceptions.ConflictError(u"Trying to register already registered namespace {}".format(namespace))
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
214 self._applications[namespace] = ApplicationData(namespace=namespace, handler=handler)
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
215 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
216
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
217 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
218 """Register a transport plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
219
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
220 @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
221 @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
222 @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
223 Must have the following methods:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
224 - 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
225 - 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
226 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
227 @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
228 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
229 assert transport_type in (XEP_0166.TRANSPORT_DATAGRAM, XEP_0166.TRANSPORT_STREAMING)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
230 if namespace in self._transports:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
231 raise exceptions.ConflictError(u"Trying to register already registered namespace {}".format(namespace))
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
232 transport_data = TransportData(namespace=namespace, handler=handler, priority=priority)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
233 self._type_transports[transport_type].append(transport_data)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
234 self._type_transports[transport_type].sort(key=lambda transport_data: transport_data.priority, reverse=True)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
235 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
236 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
237
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
238 @defer.inlineCallbacks
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
239 def transportReplace(self, client, transport_ns, session, content_name):
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
240 """Replace a transport
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
241
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
242 @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
243 @param session(dict): jingle session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
244 @param content_name(unicode): name of the content
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
245 """
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
246 # 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
247 # 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
248 # this behavious may change in the future.
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
249 content_data= session['contents'][content_name]
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
250 transport_data = content_data['transport_data']
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
251 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
252 transport = self._transports[transport_ns]
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
253 except KeyError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
254 raise exceptions.InternalError(u"Unkown transport")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
255 yield content_data['transport'].handler.jingleHandler(client, XEP_0166.A_DESTROY, session, content_name, None)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
256 content_data['transport'] = transport
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
257 transport_data.clear()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
258
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
259 iq_elt, jingle_elt = self._buildJingleElt(client, session, XEP_0166.A_TRANSPORT_REPLACE)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
260 content_elt = jingle_elt.addElement('content')
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
261 content_elt['name'] = content_name
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
262 content_elt['creator'] = content_data['creator']
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
263
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
264 transport_elt = transport.handler.jingleSessionInit(client, session, content_name)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
265 content_elt.addChild(transport_elt)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
266 iq_elt.send()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
267
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
268 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
269 """Build an element according to requested action
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
270
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
271 @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
272 session-* actions are not managed here
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
273 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
274 @param session(dict): jingle session data
1614
1ced93821c35 plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents: 1585
diff changeset
275 @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
276 @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
277 """
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
278 # 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
279 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
280 # 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
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
281 content_data= session['contents'][content_name]
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
282 content_elt = jingle_elt.addElement('content')
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
283 content_elt['name'] = content_name
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
284 content_elt['creator'] = content_data['creator']
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
285
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
286 if action == XEP_0166.A_TRANSPORT_INFO:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
287 context_elt = transport_elt = content_elt.addElement('transport', content_data['transport'].namespace)
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
288 transport_elt['sid'] = content_data['transport_data']['sid']
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
289 else:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
290 raise exceptions.InternalError(u"unmanaged action {}".format(action))
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
291
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
292 return iq_elt, context_elt
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
293
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
294 def buildSessionInfo(self, client, session):
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
295 """Build a session-info action
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
296
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
297 @param session(dict): jingle session data
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
298 @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
299 """
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
300 return self._buildJingleElt(client, session, XEP_0166.A_SESSION_INFO)
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
301
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
302 @defer.inlineCallbacks
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
303 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
304 """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
305
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
306 @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
307 @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
308 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
309 - 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
310 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
311 - 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
312 default to TRANSPORT_STREAMING
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
313 - name(unicode): name of the content
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
314 - 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
315 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
316 - 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
317 - 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
318 @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
319 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
320 assert contents # there must be at least one content
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
321 initiator = client.jid
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
322 sid = unicode(uuid.uuid4())
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
323 # TODO: session cleaning after timeout ?
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
324 session = client.jingle_sessions[sid] = {'id': sid,
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
325 'state': STATE_PENDING,
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
326 'initiator': initiator,
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
327 'role': XEP_0166.ROLE_INITIATOR,
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
328 'peer_jid': peer_jid,
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
329 'started': time.time(),
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
330 'contents': {}
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
331 }
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
332 iq_elt, jingle_elt = self._buildJingleElt(client, session, 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
333 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
334
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
335 contents_dict = session['contents']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
336
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
337 for content in contents:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
338 # we get the application plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
339 app_ns = content['app_ns']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
340 try:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
341 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
342 except KeyError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
343 raise exceptions.InternalError(u"No application registered for {}".format(app_ns))
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
344
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
345 # and the transport plugin
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
346 transport_type = content.get('transport_type', XEP_0166.TRANSPORT_STREAMING)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
347 try:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
348 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
349 except IndexError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
350 raise exceptions.InternalError(u"No transport registered for {}".format(transport_type))
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
351
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
352 # we build the session data
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
353 content_data = {'application': application,
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
354 'application_data': {},
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
355 'transport': transport,
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
356 'transport_data': {},
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
357 'creator': XEP_0166.ROLE_INITIATOR,
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
358 'senders': content.get('senders', 'both'),
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
359 }
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
360 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
361 content_name = content['name']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
362 except KeyError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
363 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
364 else:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
365 if content_name in contents_dict:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
366 raise exceptions.InternalError('There is already a content with this name')
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
367 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
368
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
369 # we construct the content element
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
370 content_elt = jingle_elt.addElement('content')
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
371 content_elt['creator'] = content_data['creator']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
372 content_elt['name'] = content_name
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
373 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
374 content_elt['senders'] = content['senders']
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
375 except KeyError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
376 pass
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
377
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
378 # then the description element
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
379 app_args = content.get('app_args', [])
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
380 app_kwargs = content.get('app_kwargs', {})
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
381 desc_elt = yield application.handler.jingleSessionInit(client, session, content_name, *app_args, **app_kwargs)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
382 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
383
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
384 # and the transport one
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
385 transport_elt = yield transport.handler.jingleSessionInit(client, session, content_name)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
386 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
387
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
388 d = iq_elt.send()
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
389 d.addErrback(self._iqError, sid, client)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
390 yield d
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
391
1617
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
392 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
393 """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
394
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
395 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
396 """
d05f9179fe22 plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents: 1616
diff changeset
397 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
398
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
399 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
400 """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
401
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
402 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
403 @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
404 @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
405 @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
406 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
407 contents = session['contents']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
408 del contents[content_name]
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
409 if not contents:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
410 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
411
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
412 ## 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
413
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
414 def jingleRequestConfirmationDefault(self, client, action, session, content_name, desc_elt):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
415 """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
416 log.debug(u"Using generic jingle confirmation method")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
417 return xml_tools.deferConfirm(self.host, _(CONFIRM_TXT).format(entity=session['peer_jid'].full()), _('Confirm Jingle session'), profile=client.profile)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
418
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
419 ## jingle events ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
420
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
421 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
422 """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
423
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
424 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
425 according to current state
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
426 @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
427 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
428 request.handled = True
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
429 jingle_elt = request.elements(NS_JINGLE, 'jingle').next()
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
430
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
431 # 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
432 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
433 sid = jingle_elt['sid']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
434 if not sid:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
435 raise KeyError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
436 except KeyError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
437 log.warning(u"Received jingle request has no sid attribute")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
438 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
439 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
440
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
441 # then the action
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
442 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
443 action = jingle_elt['action']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
444 if not action:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
445 raise KeyError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
446 except KeyError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
447 log.warning(u"Received jingle request has no action")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
448 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
449 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
450
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
451 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
452
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
453 # 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
454 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
455 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
456 except KeyError:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
457 if action == XEP_0166.A_SESSION_INITIATE:
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
458 pass
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
459 elif action == XEP_0166.A_SESSION_TERMINATE:
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
460 log.debug(u"ignoring session terminate action (inexisting session id): {request_id} [{profile}]".format(
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
461 request_id=sid,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
462 profile = client.profile))
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
463 return
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
464 else:
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
465 log.warning(u"Received request for an unknown session id: {request_id} [{profile}]".format(
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
466 request_id=sid,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
467 profile = client.profile))
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
468 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
469 return
a1e5bcd9a6eb jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents: 1614
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 session = client.jingle_sessions[sid] = {'id': sid,
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
472 'state': STATE_PENDING,
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
473 'initiator': peer_jid,
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
474 'role': XEP_0166.ROLE_RESPONDER,
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
475 'peer_jid': peer_jid,
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
476 'started': time.time(),
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
477 }
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
478 else:
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
479 if session['peer_jid'] != peer_jid:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
480 log.warning(u"sid conflict ({}), the jid doesn't match. Can be a collision, a hack attempt, or a bad sid generation".format(sid))
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
481 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
482 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
483 if session['id'] != sid:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
484 log.error(u"session id doesn't match")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
485 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
486 raise exceptions.InternalError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
487
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
488 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
489 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
490 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
491 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
492 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
493 self.onSessionAccept(client, request, jingle_elt, session)
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
494 elif action == XEP_0166.A_SESSION_INFO:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
495 self.onSessionInfo(client, request, jingle_elt, session)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
496 elif action == XEP_0166.A_TRANSPORT_INFO:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
497 self.onTransportInfo(client, request, jingle_elt, session)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
498 elif action == XEP_0166.A_TRANSPORT_REPLACE:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
499 self.onTransportReplace(client, request, jingle_elt, session)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
500 elif action == XEP_0166.A_TRANSPORT_ACCEPT:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
501 self.onTransportAccept(client, request, jingle_elt, session)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
502 elif action == XEP_0166.A_TRANSPORT_REJECT:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
503 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
504 else:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
505 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
506
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
507 ## Actions callbacks ##
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
508
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
509 def _parseElements(self, jingle_elt, session, request, client, new=False, creator=ROLE_INITIATOR, with_application=True, with_transport=True):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
510 """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
511
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
512 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
513 @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
514 @param session(dict): session data
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
515 @param request(domish.Element): the whole request
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
516 @param client: %(doc_client)s
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
517 @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
518 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
519 @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
520 @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
521 @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
522 @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
523 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
524 contents_dict = session['contents']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
525 content_elts = jingle_elt.elements(NS_JINGLE, 'content')
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
526
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
527 for content_elt in content_elts:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
528 name = content_elt['name']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
529
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
530 if new:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
531 # 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
532 if not name or name in contents_dict:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
533 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
534 raise exceptions.CancelError
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
535 content_data = contents_dict[name] = {'creator': creator,
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
536 'senders': content_elt.attributes.get('senders', 'both'),
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
537 }
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
538 else:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
539 # 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
540 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
541 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
542 except KeyError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
543 log.warning(u"Other peer try to access an unknown content")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
544 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
545 raise exceptions.CancelError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
546
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
547 # application
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
548 if with_application:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
549 desc_elt = content_elt.description
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
550 if not desc_elt:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
551 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
552 raise exceptions.CancelError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
553
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
554 if new:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
555 # 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
556 app_ns = desc_elt.uri
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
557 if not app_ns or app_ns == NS_JINGLE:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
558 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
559 raise exceptions.CancelError
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
560
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
561 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
562 application = self._applications[app_ns]
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
563 except KeyError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
564 log.warning(u"Unmanaged application namespace [{}]".format(app_ns))
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
565 self.sendError(client, 'service-unavailable', session['id'], request)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
566 raise exceptions.CancelError
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
567
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
568 content_data['application'] = application
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
569 content_data['application_data'] = {}
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
570 else:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
571 # the content exists, we check that we have not a former desc_elt
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
572 if 'desc_elt' in content_data:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
573 raise exceptions.InternalError(u"desc_elt should not exist at this point")
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
574
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
575 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
576
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
577 # transport
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
578 if with_transport:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
579 transport_elt = content_elt.transport
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
580 if not transport_elt:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
581 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
582 raise exceptions.CancelError
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
583
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
584 if new:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
585 # 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
586 transport_ns = transport_elt.uri
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
587 if not app_ns or app_ns == NS_JINGLE:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
588 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
589 raise exceptions.CancelError
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
590
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
591 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
592 transport = self._transports[transport_ns]
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
593 except KeyError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
594 raise exceptions.InternalError(u"No transport registered for namespace {}".format(transport_ns))
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
595 content_data['transport'] = transport
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
596 content_data['transport_data'] = {}
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
597 else:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
598 # the content exists, we check that we have not a former transport_elt
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
599 if 'transport_elt' in content_data:
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
600 raise exceptions.InternalError(u"transport_elt should not exist at this point")
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
601
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
602 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
603
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
604 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
605 """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
606
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
607 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
608 """
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
609 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
610
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
611 def _callPlugins(self, client, action, session, app_method_name='jingleHandler',
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
612 transp_method_name='jingleHandler',
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
613 app_default_cb=None, transp_default_cb=None, delete=True,
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
614 elements=True, force_element=None):
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
615 """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
616
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
617 @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
618 @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
619 @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
620 None to ignore
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
621 @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
622 None to ignore
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
623 @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
624 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
625 @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
626 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
627 @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
628 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
629 @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
630 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
631 (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
632 @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
633 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
634 @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
635 @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
636 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
637 contents_dict = session['contents']
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
638 defers_list = []
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
639 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
640 for method_name, handler_key, default_cb, elt_name in (
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
641 (app_method_name, 'application', app_default_cb, 'desc_elt'),
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
642 (transp_method_name, 'transport', transp_default_cb, 'transport_elt')):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
643 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
644 continue
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
645
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
646 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
647 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
648 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
649 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
650 if default_cb is None:
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
651 raise exceptions.NotFound(u'{} not implemented !'.format(method_name))
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
652 else:
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
653 method = default_cb
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
654 if elements:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
655 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
656 else:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
657 elt = force_element
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
658 d = defer.maybeDeferred(method, client, action, session, content_name, elt)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
659 defers_list.append(d)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
660
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
661 return defers_list
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
662
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
663 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
664 """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
665
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
666 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
667 (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
668 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
669 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
670 @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
671 @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
672 @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
673 @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
674 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
675 if 'contents' in session:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
676 raise exceptions.InternalError("Contents dict should not already exist at this point")
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
677 session['contents'] = contents_dict = {}
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
678
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
679 try:
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
680 self._parseElements(jingle_elt, session, request, client, True, XEP_0166.ROLE_INITIATOR)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
681 except exceptions.CancelError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
682 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
683
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
684 if not contents_dict:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
685 # there MUST be at least one content
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
686 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
687 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
688
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
689 # at this point we can send the <iq/> result to confirm reception of the request
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
690 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
691
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
692 # 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
693 # and if all are accepted, we can accept the session
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
694 confirm_defers = self._callPlugins(client, XEP_0166.A_SESSION_INITIATE, session, 'jingleRequestConfirmation', None, self.jingleRequestConfirmationDefault, delete=False)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
695
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
696 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
697 confirm_dlist.addCallback(self._confirmationCb, session, jingle_elt, client)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
698 confirm_dlist.addErrback(self._jingleErrorCb, session['id'], request, client)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
699
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
700 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
701 """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
702
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
703 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
704 @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
705 @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
706 @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
707 @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
708 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
709 confirmed = all(confirm_results)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
710 if not confirmed:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
711 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
712
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
713 iq_elt, jingle_elt = self._buildJingleElt(client, session, 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
714 jingle_elt['responder'] = client.jid.full()
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
715
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
716 # contents
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
717
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
718 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
719 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
720
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
721 defers_list = []
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
722
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
723 for content_name, content_data in session['contents'].iteritems():
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
724 content_elt = jingle_elt.addElement('content')
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
725 content_elt['creator'] = XEP_0166.ROLE_INITIATOR
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
726 content_elt['name'] = content_name
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
727
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
728 application = content_data['application']
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
729 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
730
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
731 app_d = defer.maybeDeferred(app_session_accept_cb, client,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
732 XEP_0166.A_SESSION_INITIATE, session, content_name, content_data.pop('desc_elt'))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
733 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
734 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
735
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
736 transport = content_data['transport']
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
737 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
738
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
739 transport_d = defer.maybeDeferred(transport_session_accept_cb, client,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
740 XEP_0166.A_SESSION_INITIATE, session, content_name, content_data.pop('transport_elt'))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
741 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
742 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
743
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
744 d_list = defer.DeferredList(defers_list)
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
745 d_list.addCallback(lambda dummy: self._callPlugins(client, XEP_0166.A_PREPARE_RESPONDER, session, app_method_name=None, elements=False))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
746 d_list.addCallback(lambda dummy: iq_elt.send())
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
747 def changeState(dummy, session):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
748 session['state'] = STATE_ACTIVE
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
749
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
750 d_list.addCallback(changeState, session)
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
751 d_list.addCallback(lambda dummy: self._callPlugins(client, XEP_0166.A_ACCEPTED_ACK, session, elements=False))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
752 d_list.addErrback(self._iqError, session['id'], client)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
753 return d_list
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
754
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
755 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
756 # TODO: check reason, display a message to user if needed
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
757 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
758 try:
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
759 reason_elt = jingle_elt.elements(NS_JINGLE, 'reason').next()
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
760 except StopIteration:
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
761 log.warning(u"Not reason given for session termination")
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
762 reason_elt = jingle_elt.addElement('reason')
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
763
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
764 terminate_defers = self._callPlugins(client, XEP_0166.A_SESSION_TERMINATE, session, 'jingleTerminate', 'jingleTerminate', self._ignore, self._ignore, elements=False, force_element=reason_elt)
1754
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
765 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
766
f4e9f2f7fe0f plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents: 1630
diff changeset
767 terminate_dlist.addCallback(lambda dummy: self._delSession(client, session['id']))
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
768 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
769
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
770 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
771 """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
772
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
773 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
774 @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
775 @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
776 @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
777 @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
778 """
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
779 log.debug(u"Jingle session {} has been accepted".format(session['id']))
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
780
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
781 try:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
782 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
783 except exceptions.CancelError:
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
784 return
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
785
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
786 # at this point we can send the <iq/> result to confirm reception of the request
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
787 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
788 # and change the state
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
789 session['state'] = STATE_ACTIVE
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
790
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
791 negociate_defers = []
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
792 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
793
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
794 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
795
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
796 # after negociations we start the transfer
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
797 negociate_dlist.addCallback(lambda dummy: self._callPlugins(client, XEP_0166.A_START, session, app_method_name=None, elements=False))
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
798
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
799 def _onSessionCb(self, result, client, request, jingle_elt, session):
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
800 client.send(xmlstream.toResponse(request, 'result'))
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
801
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
802 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
803 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
804 # XXX: only error managed so far, maybe some applications/transports need more
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
805 self.sendError(client, 'feature-not-implemented', None, request, 'unsupported-info')
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
806
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
807 def onSessionInfo(self, client, request, jingle_elt, session):
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
808 """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
809
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
810 This method is only called for initiator
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
811 @param client: %(doc_client)s
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
812 @param request(domish.Element): full <iq> request
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
813 @param jingle_elt(domish.Element): the <jingle> element
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
814 @param session(dict): session data
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
815 """
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
816 if not jingle_elt.children:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
817 # this is a session ping, see XEP-0166 §6.8
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
818 client.send(xmlstream.toResponse(request, 'result'))
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
819 return
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
820
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
821 try:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
822 # 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
823 # if a future transport use it, this behaviour must be adapted
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
824 defers = self._callPlugins(client, XEP_0166.A_SESSION_INFO, session, 'jingleSessionInfo', None,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
825 elements=False, force_element=jingle_elt)
1616
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
826 except exceptions.NotFound as e:
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
827 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
828 return
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
829
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
830 dlist = defer.DeferredList(defers, fireOnOneErrback=True)
1e05b776a55b plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents: 1615
diff changeset
831 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
832 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
833
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
834 @defer.inlineCallbacks
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
835 def onTransportReplace(self, client, request, jingle_elt, session):
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
836 """A transport change is requested
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
837
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
838 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
839 @param client: %(doc_client)s
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
840 @param request(domish.Element): full <iq> request
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
841 @param jingle_elt(domish.Element): the <jingle> element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
842 @param session(dict): session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
843 """
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
844 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
845 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
846 self._parseElements(jingle_elt, session, request, client, with_application=False)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
847 except exceptions.CancelError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
848 defer.returnValue(None)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
849
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
850 client.send(xmlstream.toResponse(request, 'result'))
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
851
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
852 content_name = None
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
853 to_replace = []
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
854
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
855 for content_name, content_data in session['contents'].iteritems():
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
856 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
857 transport_elt = content_data.pop('transport_elt')
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
858 except KeyError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
859 continue
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
860 transport_ns = transport_elt.uri
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
861 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
862 transport = self._transports[transport_ns]
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
863 except KeyError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
864 log.warning(u"Other peer want to replace current transport with an unknown one: {}".format(transport_ns))
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
865 content_name = None
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
866 break
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
867 to_replace.append((content_name, content_data, transport, transport_elt))
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
868
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
869 if content_name is None:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
870 # wa can't accept the replacement
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
871 iq_elt, reject_jingle_elt = self._buildJingleElt(client, session, XEP_0166.A_TRANSPORT_REJECT)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
872 for child in jingle_elt.children:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
873 reject_jingle_elt.addChild(child)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
874
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
875 iq_elt.send()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
876 defer.returnValue(None)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
877
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
878 # 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
879 # this is similar to an session-accept action, but for transports only
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
880 iq_elt, accept_jingle_elt = self._buildJingleElt(client, session, XEP_0166.A_TRANSPORT_ACCEPT)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
881 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
882 # we can now actually replace the transport
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
883 yield content_data['transport'].handler.jingleHandler(client, XEP_0166.A_DESTROY, session, content_name, None)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
884 content_data['transport'] = transport
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
885 content_data['transport_data'].clear()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
886 # and build the element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
887 content_elt = accept_jingle_elt.addElement('content')
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
888 content_elt['name'] = content_name
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
889 content_elt['creator'] = content_data['creator']
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
890 # we notify the transport and insert its <transport/> in the answer
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
891 accept_transport_elt = yield transport.handler.jingleHandler(client, XEP_0166.A_TRANSPORT_REPLACE, session, content_name, transport_elt)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
892 content_elt.addChild(accept_transport_elt)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
893 # there is no confirmation needed here, so we can directly prepare it
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
894 yield transport.handler.jingleHandler(client, XEP_0166.A_PREPARE_RESPONDER, session, content_name, None)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
895
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
896 iq_elt.send()
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
897
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
898 def onTransportAccept(self, client, request, jingle_elt, session):
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
899 """Method called once transport replacement is accepted
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
900
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
901 @param client: %(doc_client)s
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
902 @param request(domish.Element): full <iq> request
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
903 @param jingle_elt(domish.Element): the <jingle> element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
904 @param session(dict): session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
905 """
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
906 log.debug(u"new transport has been accepted")
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
907
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
908 try:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
909 self._parseElements(jingle_elt, session, request, client, with_application=False)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
910 except exceptions.CancelError:
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
911 return
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
912
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
913 # at this point we can send the <iq/> result to confirm reception of the request
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
914 client.send(xmlstream.toResponse(request, 'result'))
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
915
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
916 negociate_defers = []
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
917 negociate_defers = self._callPlugins(client, XEP_0166.A_TRANSPORT_ACCEPT, session, app_method_name=None)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
918
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
919 negociate_dlist = defer.DeferredList(negociate_defers)
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
920
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
921 # after negociations we start the transfer
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
922 negociate_dlist.addCallback(lambda dummy: self._callPlugins(client, XEP_0166.A_START, session, app_method_name=None, elements=False))
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
923
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
924 def onTransportReject(self, client, request, jingle_elt, session):
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
925 """Method called when a transport replacement is refused
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
926
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
927 @param client: %(doc_client)s
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
928 @param request(domish.Element): full <iq> request
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
929 @param jingle_elt(domish.Element): the <jingle> element
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
930 @param session(dict): session data
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
931 """
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
932 # 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
933 # this behaviour may change in the future
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
934 self.terminate(client, 'failed-transport', session)
1630
c25f63215632 plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents: 1617
diff changeset
935
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
936 def onTransportInfo(self, client, request, jingle_elt, session):
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
937 """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
938
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
939 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
940 @param client: %(doc_client)s
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
941 @param request(domish.Element): full <iq> request
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
942 @param jingle_elt(domish.Element): the <jingle> element
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
943 @param session(dict): session data
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
944 """
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
945 log.debug(u"Jingle session {} has been accepted".format(session['id']))
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
946
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
947 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
948 self._parseElements(jingle_elt, session, request, client, with_application=False)
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
949 except exceptions.CancelError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
950 return
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
951
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
952 # The parsing was OK, we send the <iq> result
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
953 client.send(xmlstream.toResponse(request, 'result'))
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
954
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
955 for content_name, content_data in session['contents'].iteritems():
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
956 try:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
957 transport_elt = content_data.pop('transport_elt')
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
958 except KeyError:
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
959 continue
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
960 else:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
961 content_data['transport'].handler.jingleHandler(client, XEP_0166.A_TRANSPORT_INFO, session, content_name, transport_elt)
1556
cbfbe028d099 plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents: 1523
diff changeset
962
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
963
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
964 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
965 implements(iwokkel.IDisco)
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
966
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
967 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
968 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
969
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
970 def connectionInitialized(self):
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2487
diff changeset
971 self.xmlstream.addObserver(JINGLE_REQUEST, self.plugin_parent._onJingleRequest, client=self.parent)
1523
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
972
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
973 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
974 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
975
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
976 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
0209f8d35873 plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff changeset
977 return []