Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0166.py @ 1619:3ec7511dbf28
plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Nov 2015 19:51:52 +0100 |
parents | d05f9179fe22 |
children | c25f63215632 |
rev | line source |
---|---|
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
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) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
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 = { |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 "name": "Jingle", |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 "import_name": "XEP-0166", |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 "type": "XEP", |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 "protocols": ["XEP-0166"], |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 "main": "XEP_0166", |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 "handler": "yes", |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 "description": _("""Implementation of Jingle""") |
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' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 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
|
75 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
|
76 A_SESSION_TERMINATE = "session-terminate" |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
77 A_SESSION_INFO = "session-info" |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
78 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
|
79 # non standard actions |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 A_START = "start" # application can start |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 def __init__(self, host): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 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
|
87 self.host = host |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 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
|
89 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
|
90 # 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
|
91 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
|
92 XEP_0166.TRANSPORT_STREAMING: [], |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def profileConnected(self, profile): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 client = self.host.getClient(profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 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
|
98 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 def getHandler(self, profile): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 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
|
101 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 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
|
103 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 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
|
105 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 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
|
107 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 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
|
109 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 ## 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
|
111 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 def _buildJingleElt(self, client, session, action): |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 jingle_elt['action'] = action |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 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
|
120 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
121 def sendError(self, error_condition, sid, request, jingle_condition=None, profile=C.PROF_KEY_NONE): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 """Send error stanza |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 @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
|
125 @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
|
126 @param request(domish.Element): original request |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
127 @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
|
128 @param profile: %(doc_profile)s |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 client = self.host.getClient(profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 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
|
132 if jingle_condition is not None: |
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
133 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
|
134 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
|
135 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 log.warning(u"Error while managing jingle session, cancelling: {condition}".format(error_condition)) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 client.xmlstream.send(iq_elt) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 def terminate(self, reason, session, profile): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 """Terminate the session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 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
|
143 @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
|
144 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
|
145 @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
|
146 @param profile: %(doc_profile)s |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 client = self.host.getClient(profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 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
|
150 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
|
151 if isinstance(reason, basestring): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 reason_elt.addElement(reason) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 for elt in reason: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 reason_elt.addChild(elt) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 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
|
157 d = iq_elt.send() |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 return d |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 ## 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
|
161 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
162 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
|
163 """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
|
164 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
165 @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
|
166 @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
|
167 @param profile: %(doc_client)s |
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 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
|
170 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 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
|
173 """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
|
174 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 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
|
176 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
|
177 @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
|
178 @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
|
179 @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
|
180 @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
|
181 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 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
|
183 if isinstance(fail, exceptions.DataError): |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
184 self.sendError('bad-request', sid, request, profile=client.profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 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
|
187 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 raise fail |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 ## 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
|
191 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 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
|
193 """Register an application plugin |
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 @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
|
196 @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
|
197 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
|
198 - 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
|
199 - 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
|
200 - 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
|
201 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
|
202 - if not present, a generic accept dialog will be used |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 - jingleSessionInit(self, session, content_name[, *args, **kwargs], profile): must return the domish.Element used for initial content |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 - jingleHandler(self, action, session, content_name, transport_elt, profile): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 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
|
206 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 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
|
208 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
|
209 self._applications[namespace] = ApplicationData(namespace=namespace, handler=handler) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
210 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
|
211 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 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
|
213 """Register a transport plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 @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
|
216 @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
|
217 @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
|
218 Must have the following methods: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 - jingleSessionInit(self, session, content_name[, *args, **kwargs], profile): must return the domish.Element used for initial content |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 - jingleHandler(self, action, session, content_name, transport_elt, profile): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 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
|
222 @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
|
223 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
233 def buildAction(self, action, session, content_name, profile=C.PROF_KEY_NONE): |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
234 """Build an element according to requested action |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
235 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
236 @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
|
237 session-* actions are not managed here |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
238 @param session(dict): jingle session data |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
239 @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
|
240 @param profile: %(doc_profile)s |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
241 @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
|
242 """ |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
243 client = self.host.getClient(profile) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
244 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
245 # 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
|
246 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
|
247 # 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
|
248 content_data= session['contents'][content_name] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
249 content_elt = jingle_elt.addElement('content') |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
250 content_elt['name'] = content_name |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
251 content_elt['creator'] = content_data['creator'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
252 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
253 if action == XEP_0166.A_TRANSPORT_INFO: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
254 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
|
255 transport_elt['sid'] = content_data['transport_data']['sid'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
256 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
257 raise exceptions.InternalError(u"unmanaged action {}".format(action)) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
258 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
259 return iq_elt, context_elt |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
260 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
261 def buildSessionInfo(self, session, profile=C.PROF_KEY_NONE): |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
262 """Build a session-info action |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
263 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
264 @param session(dict): jingle session data |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
265 @param profile: %(doc_profile)s |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
266 @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
|
267 """ |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
268 client = self.host.getClient(profile) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
269 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
|
270 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 @defer.inlineCallbacks |
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
|
272 def initiate(self, peer_jid, contents, profile=C.PROF_KEY_NONE): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 """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
|
274 |
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
|
275 @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
|
276 @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
|
277 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
|
278 - 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
|
279 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
|
280 - 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
|
281 default to TRANSPORT_STREAMING |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 - name(unicode): name of the content |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
283 - 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
|
284 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
|
285 - 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
|
286 - app_kwargs(dict): keyword 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
|
287 @param profile: %(doc_profile)s |
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
|
288 @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
|
289 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 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
|
291 client = self.host.getClient(profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 initiator = client.jid |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 sid = unicode(uuid.uuid4()) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 # 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
|
295 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
|
296 'state': STATE_PENDING, |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 'initiator': initiator, |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
298 '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
|
299 '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
|
300 'started': time.time(), |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 'contents': {} |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 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
|
304 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
|
305 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 contents_dict = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 for content in contents: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 # 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
|
310 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
|
311 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
312 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
|
313 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 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
|
315 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 # and the transport plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 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
|
318 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
319 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
|
320 except IndexError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 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
|
322 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 # we build the session data |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
324 content_data = {'application': application, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
325 'application_data': {}, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
326 'transport': transport, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
327 'transport_data': {}, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
328 'creator': XEP_0166.ROLE_INITIATOR, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
329 '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
|
330 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 content_name = content['name'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 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
|
335 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 # 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
|
341 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
|
342 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
|
343 content_elt['name'] = content_name |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
344 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
345 content_elt['senders'] = content['senders'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
346 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
347 pass |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 # then the description element |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 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
|
351 app_kwargs = content.get('app_kwargs', {}) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 app_kwargs['profile'] = profile |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
353 desc_elt = yield application.handler.jingleSessionInit(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
|
354 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
|
355 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 # and the transport one |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
357 transport_elt = yield transport.handler.jingleSessionInit(session, content_name, profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 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
|
359 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 d = iq_elt.send() |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 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
|
362 yield d |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 |
1617
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
364 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
|
365 """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
|
366 |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
367 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
|
368 """ |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
369 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
|
370 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 def contentTerminate(self, session, content_name, reason=REASON_SUCCESS, profile=C.PROF_KEY_NONE): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 """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
|
373 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 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
|
375 @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
|
376 @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
|
377 @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
|
378 @param profile: %(doc_profile)s |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 contents = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 del contents[content_name] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 if not contents: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 self.terminate(reason, session, profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 ## 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
|
386 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
387 def jingleRequestConfirmationDefault(self, action, session, content_name, desc_elt, profile): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 """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
|
389 log.debug(u"Using generic jingle confirmation method") |
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
|
390 return xml_tools.deferConfirm(self.host, _(CONFIRM_TXT).format(entity=session['peer_jid'].full()), _('Confirm Jingle session'), profile=profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 ## jingle events ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 def _onJingleRequest(self, request, profile): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 """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
|
396 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 The request will the be dispatched to appropriate method |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 according to current state |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 @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
|
400 @para profile: %(doc_profile)s |
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 client = self.host.getClient(profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 request.handled = True |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 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
|
405 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 # 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
|
407 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 sid = jingle_elt['sid'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 if not sid: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 raise KeyError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 log.warning(u"Received jingle request has no sid attribute") |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
413 self.sendError('bad-request', None, request, profile=profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 # then the action |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 action = jingle_elt['action'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 if not action: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 raise KeyError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 log.warning(u"Received jingle request has no action") |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
423 self.sendError('bad-request', None, request, profile=profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 |
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
|
426 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
|
427 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 # 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
|
429 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 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
|
431 except KeyError: |
1615
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
432 if action != XEP_0166.A_SESSION_INITIATE: |
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
433 log.warning(u"Received request for an unknown session id: {}".format(sid)) |
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
434 self.sendError('not-acceptable', None, request, profile=profile) |
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
435 return |
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
436 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 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
|
438 '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
|
439 'initiator': peer_jid, |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
440 '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
|
441 '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
|
442 'started': time.time(), |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 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
|
445 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
|
446 log.warning(u"sid conflict ({}), the jid doesn't match. Can be a collision, a hack attempt, or a bad sid generation".format(sid)) |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
447 self.sendError('service-unavailable', sid, request, profile=profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 if session['id'] != sid: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 log.error(u"session id doesn't match") |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
451 self.sendError('service-unavailable', sid, request, profile=profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 raise exceptions.InternalError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 self.onSessionAccept(client, request, jingle_elt, session) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
460 elif action == XEP_0166.A_SESSION_INFO: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
461 self.onSessionInfo(client, request, jingle_elt, session) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
462 elif action == XEP_0166.A_TRANSPORT_INFO: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
463 self.onTransportInfo(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
|
464 else: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
465 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
|
466 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 ## Actions callbacks ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
469 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
|
470 """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
|
471 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 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
|
473 @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
|
474 @param session(dict): session data |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
475 @param request(domish.Element): the whole request |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
476 @param client: %(doc_client)s |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 @param new(bool): if new the content is new and must be created, |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 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
|
479 @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
|
480 @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
|
481 @param with_transport(bool): if True, raise an error if there is no <transport> element else ignore it |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 @raise exceptions.CancelError: the error is treated the calling method can cancel the treatment (i.e. return) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 contents_dict = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 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
|
486 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 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
|
488 name = content_elt['name'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 if new: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 # 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
|
492 if not name or name in contents_dict: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
493 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 raise exceptions.CancelError |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
495 content_data = contents_dict[name] = {'creator': creator, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
496 'senders': content_elt.attributes.get('senders', 'both'), |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
497 } |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 # 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
|
500 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 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
|
502 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 log.warning(u"Other peer try to access an unknown content") |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
504 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 raise exceptions.CancelError |
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 # application |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
508 if with_application: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
509 desc_elt = content_elt.description |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
510 if not desc_elt: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
511 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
514 if new: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
515 # 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
|
516 app_ns = desc_elt.uri |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
517 if not app_ns or app_ns == NS_JINGLE: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
518 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
519 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
521 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
522 application = self._applications[app_ns] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
523 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
524 log.warning(u"Unmanaged application namespace [{}]".format(app_ns)) |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
525 self.sendError('service-unavailable', session['id'], request, profile=client.profile) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
526 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
528 content_data['application'] = application |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
529 content_data['application_data'] = {} |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
530 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
531 # 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
|
532 if 'desc_elt' in content_data: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
533 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
|
534 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
535 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
|
536 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
537 # transport |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
538 if with_transport: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
539 transport_elt = content_elt.transport |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
540 if not transport_elt: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
541 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
543 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
544 if new: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
545 # 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
|
546 transport_ns = transport_elt.uri |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
547 if not app_ns or app_ns == NS_JINGLE: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
548 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
549 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
551 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
552 transport = self._transports[transport_ns] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
553 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
554 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
|
555 content_data['transport'] = transport |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
556 content_data['transport_data'] = {} |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
557 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
558 # 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
|
559 if 'transport_elt' in content_data: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
560 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
|
561 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
562 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
|
563 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
564 def _callPlugins(self, action, session, app_method_name='jingleHandler', transp_method_name='jingleHandler', |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
565 app_default_cb=None, transp_default_cb=None, delete=True, |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
566 elements=True, force_element=None, profile=C.PROF_KEY_NONE): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 """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
|
568 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 @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
|
570 @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
|
571 @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
|
572 None to ignore |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 @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
|
574 None to ignore |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 @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
|
576 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
|
577 @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
|
578 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
|
579 @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
|
580 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
|
581 @param elements(bool): True if elements(desc_elt and tranport_elt) must be managed |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
582 must be True if _callPlugins is used in a request, and False if it used after a request (i.e. on <iq> result or error) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
583 @param force_element(None, domish.Element, object): if elements is None, it is used as element parameter |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
584 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
|
585 @param profile(unicode): %(doc_profile)s |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
586 @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
|
587 @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
|
588 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 contents_dict = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 defers_list = [] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 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
|
592 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
|
593 (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
|
594 (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
|
595 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
|
596 continue |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
597 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
598 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
|
599 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 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
|
601 except AttributeError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 if default_cb is not None: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 method = default_cb |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
604 else: |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
605 raise exceptions.NotFound(u'{} not implemented !'.format(method_name)) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
606 if elements: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
607 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
|
608 else: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
609 elt = force_element |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
610 d = defer.maybeDeferred(method, action, session, content_name, elt, profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
611 defers_list.append(d) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 return defers_list |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
615 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
|
616 """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
|
617 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 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
|
619 (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
|
620 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
|
621 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
|
622 @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
|
623 @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
|
624 @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
|
625 @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
|
626 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 if 'contents' in session: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 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
|
629 session['contents'] = contents_dict = {} |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
631 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
632 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
|
633 except exceptions.CancelError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 if not contents_dict: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
637 # there MUST be at least one content |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
638 self.sendError('bad-request', session['id'], request, profile=client.profile) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 # at this point we can send the <iq/> result to confirm reception of the request |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 client.xmlstream.send(xmlstream.toResponse(request, 'result')) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
644 # 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
|
645 # and if all are accepted, we can accept the session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
646 confirm_defers = self._callPlugins(XEP_0166.A_SESSION_INITIATE, session, 'jingleRequestConfirmation', None, self.jingleRequestConfirmationDefault, delete=False, profile=client.profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
648 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
|
649 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
|
650 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
|
651 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 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
|
653 """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
|
654 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 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
|
656 @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
|
657 @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
|
658 @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
|
659 @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
|
660 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
661 confirmed = all(confirm_results) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 if not confirmed: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
663 return self.terminate(XEP_0166.REASON_DECLINE, session, client.profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
664 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
665 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
|
666 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
|
667 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
668 # contents |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
669 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 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
|
671 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
|
672 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 defers_list = [] |
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 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
|
676 content_elt = jingle_elt.addElement('content') |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
677 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
|
678 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
|
679 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
680 application = content_data['application'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
681 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
|
682 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 app_d = defer.maybeDeferred(app_session_accept_cb, |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 XEP_0166.A_SESSION_INITIATE, session, content_name, content_data.pop('desc_elt'), client.profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
685 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
|
686 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
|
687 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
688 transport = content_data['transport'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
689 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
|
690 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 transport_d = defer.maybeDeferred(transport_session_accept_cb, |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 XEP_0166.A_SESSION_INITIATE, session, content_name, content_data.pop('transport_elt'), client.profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 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
|
694 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
|
695 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
696 d_list = defer.DeferredList(defers_list) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
697 d_list.addCallback(lambda dummy: self._callPlugins(XEP_0166.A_PREPARE_RESPONDER, session, app_method_name=None, elements=False, profile=client.profile)) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
698 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
|
699 def changeState(dummy, session): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
700 session['state'] = STATE_ACTIVE |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
701 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
702 d_list.addCallback(changeState, session) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
703 d_list.addCallback(lambda dummy: self._callPlugins(XEP_0166.A_ACCEPTED_ACK, session, elements=False, profile=client.profile)) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 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
|
705 return d_list |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
706 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
707 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
|
708 # 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
|
709 log.debug("Jingle Session {} terminated".format(session['id'])) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
710 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
|
711 client.xmlstream.send(xmlstream.toResponse(request, 'result')) |
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 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
|
714 """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
|
715 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
716 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
|
717 @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
|
718 @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
|
719 @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
|
720 @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
|
721 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
722 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
|
723 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
724 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
725 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
|
726 except exceptions.CancelError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
727 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
728 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
729 # at this point we can send the <iq/> result to confirm reception of the request |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
730 client.xmlstream.send(xmlstream.toResponse(request, 'result')) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
731 # and change the state |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
732 session['state'] = STATE_ACTIVE |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
733 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
734 negociate_defers = [] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
735 negociate_defers = self._callPlugins(XEP_0166.A_SESSION_ACCEPT, session, profile=client.profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
736 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
737 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
|
738 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
739 # after negociations we start the transfer |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
740 negociate_dlist.addCallback(lambda dummy: self._callPlugins(XEP_0166.A_START, session, app_method_name=None, elements=False, profile=client.profile)) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
742 def _onSessionCb(self, result, client, request, jingle_elt, session): |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
743 client.xmlstream.send(xmlstream.toResponse(request, 'result')) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
744 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
745 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
|
746 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
|
747 # XXX: only error managed so far, maybe some applications/transports need more |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
748 self.sendError('feature-not-implemented', None, request, 'unsupported-info', client.profile) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
749 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
750 def onSessionInfo(self, client, request, jingle_elt, session): |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
751 """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
|
752 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
753 This method is only called for initiator |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
754 @param client: %(doc_client)s |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
755 @param request(domish.Element): full <iq> request |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
756 @param jingle_elt(domish.Element): the <jingle> element |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
757 @param session(dict): session data |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
758 """ |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
759 if not jingle_elt.children: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
760 # this is a session ping, see XEP-0166 §6.8 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
761 client.xmlstream.send(xmlstream.toResponse(request, 'result')) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
762 return |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
763 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
764 try: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
765 # 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
|
766 # if a future transport use it, this behaviour must be adapted |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
767 defers = self._callPlugins(XEP_0166.A_SESSION_INFO, session, 'jingleSessionInfo', None, |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
768 elements=False, force_element=jingle_elt, profile=client.profile) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
769 except exceptions.NotFound as e: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
770 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
|
771 return |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
772 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
773 dlist = defer.DeferredList(defers, fireOnOneErrback=True) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
774 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
|
775 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
|
776 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
777 def onTransportInfo(self, client, request, jingle_elt, session): |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
778 """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
|
779 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
780 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
|
781 @param client: %(doc_client)s |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
782 @param request(domish.Element): full <iq> request |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
783 @param jingle_elt(domish.Element): the <jingle> element |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
784 @param session(dict): session data |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
785 """ |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
786 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
|
787 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
788 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
789 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
|
790 except exceptions.CancelError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
791 return |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
792 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
793 # The parsing was OK, we send the <iq> result |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
794 client.xmlstream.send(xmlstream.toResponse(request, 'result')) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
795 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
796 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
|
797 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
798 transport_elt = content_data.pop('transport_elt') |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
799 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
800 continue |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
801 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
802 content_data['transport'].handler.jingleHandler(XEP_0166.A_TRANSPORT_INFO, session, content_name, transport_elt, client.profile) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
803 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
804 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
805 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
|
806 implements(iwokkel.IDisco) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
807 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
808 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
|
809 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
|
810 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
811 def connectionInitialized(self): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
812 self.xmlstream.addObserver(JINGLE_REQUEST, self.plugin_parent._onJingleRequest, profile=self.parent.profile) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
813 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
814 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
|
815 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
|
816 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
817 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
|
818 return [] |