Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0166.py @ 2315:8d9bd5d77336
jp (arg_tools): moved get_cmd_choices, get_use_args and escape to a new arg_tools module, so they can be used in other commands than shell
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Jul 2017 21:45:14 +0200 |
parents | 33c8c4973743 |
children | 8b37a62336c3 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for Jingle (XEP-0166) |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _, D_ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.tools import xml_tools |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 log = getLogger(__name__) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core import exceptions |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.words.protocols.jabber import jid |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from twisted.internet import defer |
1617
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
28 from twisted.internet import reactor |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
29 from wokkel import disco, iwokkel |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from twisted.words.protocols.jabber import error |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from twisted.words.protocols.jabber import xmlstream |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
32 from twisted.python import failure |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from collections import namedtuple |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 import uuid |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 import time |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from zope.interface import implements |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 IQ_SET = '/iq[@type="set"]' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 NS_JINGLE = "urn:xmpp:jingle:1" |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
43 NS_JINGLE_ERROR = "urn:xmpp:jingle:errors:1" |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 JINGLE_REQUEST = IQ_SET + '/jingle[@xmlns="' + NS_JINGLE + '"]' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 STATE_PENDING = "PENDING" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 STATE_ACTIVE = "ACTIVE" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 STATE_ENDED = "ENDED" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 CONFIRM_TXT = D_("{entity} want to start a jingle session with you, do you accept ?") |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
51 C.PI_NAME: "Jingle", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
52 C.PI_IMPORT_NAME: "XEP-0166", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
53 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
54 C.PI_PROTOCOLS: ["XEP-0166"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
55 C.PI_MAIN: "XEP_0166", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
56 C.PI_HANDLER: "yes", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
57 C.PI_DESCRIPTION: _("""Implementation of Jingle""") |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
61 ApplicationData = namedtuple('ApplicationData', ('namespace', 'handler')) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 TransportData = namedtuple('TransportData', ('namespace', 'handler', 'priority')) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 class XEP_0166(object): |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
66 ROLE_INITIATOR = "initiator" |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
67 ROLE_RESPONDER = "responder" |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 TRANSPORT_DATAGRAM='UDP' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 TRANSPORT_STREAMING='TCP' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 REASON_SUCCESS='success' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 REASON_DECLINE='decline' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 REASON_FAILED_APPLICATION='failed-application' |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 REASON_FAILED_TRANSPORT='failed-transport' |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
74 REASON_CONNECTIVITY_ERROR='connectivity-error' |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 A_SESSION_INITIATE = "session-initiate" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 A_SESSION_ACCEPT = "session-accept" |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 A_SESSION_TERMINATE = "session-terminate" |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
78 A_SESSION_INFO = "session-info" |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
79 A_TRANSPORT_REPLACE = "transport-replace" |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
80 A_TRANSPORT_ACCEPT = "transport-accept" |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
81 A_TRANSPORT_REJECT = "transport-reject" |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
82 A_TRANSPORT_INFO = "transport-info" |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 # non standard actions |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 A_PREPARE_INITIATOR = "prepare-initiator" # initiator must prepare tranfer |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 A_PREPARE_RESPONDER = "prepare-responder" # responder must prepare tranfer |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 A_ACCEPTED_ACK = "accepted-ack" # session accepted ack has been received from initiator |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 A_START = "start" # application can start |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
88 A_DESTROY = "destroy" # called when a transport is destroyed (e.g. because it is remplaced). Used to do cleaning operations |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 def __init__(self, host): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 log.info(_("plugin Jingle initialization")) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 self.host = host |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 self._applications = {} # key: namespace, value: application data |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 self._transports = {} # key: namespace, value: transport data |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 # we also keep transports by type, they are then sorted by priority |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self._type_transports = { XEP_0166.TRANSPORT_DATAGRAM: [], |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 XEP_0166.TRANSPORT_STREAMING: [], |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
100 def profileConnected(self, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 client.jingle_sessions = {} # key = sid, value = session_data |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
103 def getHandler(self, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 return XEP_0166_handler(self) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 def _delSession(self, client, sid): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 del client.jingle_sessions[sid] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 log.debug(u"Jingle session id [{}] is unknown, nothing to delete".format(sid)) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 log.debug(u"Jingle session id [{}] deleted".format(sid)) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 ## helpers methods to build stanzas ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 def _buildJingleElt(self, client, session, action): |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
117 iq_elt = client.IQ('set') |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 iq_elt['from'] = client.jid.full() |
1567
268fda4236ca
plugins XE0166, XEP-0234, XEP-0260, XEP-0261: renamed session key managing other peer's jid to "peer_jid" instead of "to_jid"
Goffi <goffi@goffi.org>
parents:
1556
diff
changeset
|
119 iq_elt['to'] = session['peer_jid'].full() |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 jingle_elt = iq_elt.addElement("jingle", NS_JINGLE) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 jingle_elt["sid"] = session['id'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 jingle_elt['action'] = action |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 return iq_elt, jingle_elt |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
125 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
|
126 """Send error stanza |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 @param error_condition: one of twisted.words.protocols.jabber.error.STANZA_CONDITIONS keys |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 @param sid(unicode,None): jingle session id, or None, if session must not be destroyed |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 @param request(domish.Element): original request |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
131 @param jingle_condition(None, unicode): if not None, additional jingle-specific error information |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 @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
|
133 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 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
|
135 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
|
136 if jingle_condition is not None: |
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
137 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
|
138 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
|
139 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 log.warning(u"Error while managing jingle session, cancelling: {condition}".format(error_condition)) |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
141 client.send(iq_elt) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 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
|
144 """Terminate the session |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 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
|
147 @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
|
148 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
|
149 @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
|
150 @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
|
151 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 if isinstance(reason, basestring): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 reason_elt.addElement(reason) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 for elt in reason: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 reason_elt.addChild(elt) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 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
|
161 d = iq_elt.send() |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 return d |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 ## errors which doesn't imply a stanza sending ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
166 def _iqError(self, failure_, sid, client): |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 """Called when we got an <iq/> error |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
169 @param failure_(failure.Failure): the exceptions raised |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 @param sid(unicode): jingle session id |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 @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
|
172 """ |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
173 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
|
174 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 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
|
177 """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
|
178 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 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
|
180 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
|
181 @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
|
182 @param sid(unicode): jingle session id |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 @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
|
184 @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
|
185 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 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
|
187 if isinstance(fail, exceptions.DataError): |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
188 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
|
189 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 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
|
191 self._delSession(client, sid) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 raise fail |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 ## 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
|
195 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 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
|
197 """Register an application plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 @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
|
200 @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
|
201 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
|
202 - 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
|
203 - 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
|
204 - 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
|
205 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
|
206 - 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
|
207 - 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
|
208 - 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
|
209 called on several action to negociate the application or transport |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
210 - jingleTerminate: called on session terminate, with reason_elt |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
211 May be used to clean session |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 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
|
214 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
|
215 self._applications[namespace] = ApplicationData(namespace=namespace, handler=handler) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
216 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
|
217 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 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
|
219 """Register a transport plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 @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
|
222 @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
|
223 @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
|
224 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
|
225 - 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
|
226 - 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
|
227 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
|
228 @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
|
229 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
239 @defer.inlineCallbacks |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
240 def transportReplace(self, transport_ns, session, content_name, profile=C.PROF_KEY_NONE): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
241 """Replace a transport |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
242 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
243 @param transport_ns(unicode): namespace of the new transport to use |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
244 @param session(dict): jingle session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
245 @param content_name(unicode): name of the content |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
246 @param profile: %(doc_profile)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
247 """ |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
248 # XXX: for now we replace the transport before receiving confirmation from other peer |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
249 # this is acceptable because we terminate the session if transport is rejected. |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
250 # this behavious may change in the future. |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
251 client = self.host.getClient(profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
252 content_data= session['contents'][content_name] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
253 transport_data = content_data['transport_data'] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
254 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
255 transport = self._transports[transport_ns] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
256 except KeyError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
257 raise exceptions.InternalError(u"Unkown transport") |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
258 yield content_data['transport'].handler.jingleHandler(XEP_0166.A_DESTROY, session, content_name, None, profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
259 content_data['transport'] = transport |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
260 transport_data.clear() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
261 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
262 iq_elt, jingle_elt = self._buildJingleElt(client, session, XEP_0166.A_TRANSPORT_REPLACE) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
263 content_elt = jingle_elt.addElement('content') |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
264 content_elt['name'] = content_name |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
265 content_elt['creator'] = content_data['creator'] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
266 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
267 transport_elt = transport.handler.jingleSessionInit(session, content_name, profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
268 content_elt.addChild(transport_elt) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
269 iq_elt.send() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
270 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
271 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
|
272 """Build an element according to requested action |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
273 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
274 @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
|
275 session-* actions are not managed here |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
276 transport-replace is managed in the dedicated [transportReplace] method |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
277 @param session(dict): jingle session data |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
278 @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
|
279 @param profile: %(doc_profile)s |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
280 @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
|
281 """ |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
282 client = self.host.getClient(profile) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
283 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
284 # 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
|
285 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
|
286 # 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
|
287 content_data= session['contents'][content_name] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
288 content_elt = jingle_elt.addElement('content') |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
289 content_elt['name'] = content_name |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
290 content_elt['creator'] = content_data['creator'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
291 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
292 if action == XEP_0166.A_TRANSPORT_INFO: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
293 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
|
294 transport_elt['sid'] = content_data['transport_data']['sid'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
295 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
296 raise exceptions.InternalError(u"unmanaged action {}".format(action)) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
297 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
298 return iq_elt, context_elt |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
299 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
300 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
|
301 """Build a session-info action |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
302 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
303 @param session(dict): jingle session data |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
304 @param profile: %(doc_profile)s |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
305 @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
|
306 """ |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
307 client = self.host.getClient(profile) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
308 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
|
309 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 @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
|
311 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
|
312 """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
|
313 |
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
|
314 @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
|
315 @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
|
316 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
|
317 - 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
|
318 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
|
319 - 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
|
320 default to TRANSPORT_STREAMING |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 - name(unicode): name of the content |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
322 - 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
|
323 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
|
324 - 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
|
325 - 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
|
326 @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
|
327 @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
|
328 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 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
|
330 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
|
331 initiator = client.jid |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 sid = unicode(uuid.uuid4()) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 # 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
|
334 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
|
335 'state': STATE_PENDING, |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 'initiator': initiator, |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
337 '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
|
338 '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
|
339 'started': time.time(), |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 'contents': {} |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 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
|
343 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
|
344 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 contents_dict = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 for content in contents: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 # 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
|
349 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
|
350 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
351 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
|
352 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 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
|
354 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 # and the transport plugin |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 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
|
357 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
358 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
|
359 except IndexError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 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
|
361 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 # we build the session data |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
363 content_data = {'application': application, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
364 'application_data': {}, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
365 'transport': transport, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
366 'transport_data': {}, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
367 'creator': XEP_0166.ROLE_INITIATOR, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
368 '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
|
369 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 content_name = content['name'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 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
|
374 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 # 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
|
380 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
|
381 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
|
382 content_elt['name'] = content_name |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
383 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
384 content_elt['senders'] = content['senders'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
385 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
386 pass |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 # then the description element |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 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
|
390 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
|
391 app_kwargs['profile'] = profile |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
392 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
|
393 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
|
394 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 # and the transport one |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
396 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
|
397 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
|
398 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 d = iq_elt.send() |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 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
|
401 yield d |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 |
1617
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
403 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
|
404 """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
|
405 |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
406 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
|
407 """ |
d05f9179fe22
plugin XEP-0166: added delayedContentTerminate to terminate a content inside a handler
Goffi <goffi@goffi.org>
parents:
1616
diff
changeset
|
408 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
|
409 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 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
|
411 """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
|
412 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 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
|
414 @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
|
415 @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
|
416 @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
|
417 @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
|
418 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 contents = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 del contents[content_name] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 if not contents: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 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
|
423 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 ## 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
|
425 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
426 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
|
427 """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
|
428 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
|
429 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
|
430 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 ## jingle events ## |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 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
|
434 """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
|
435 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 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
|
437 according to current state |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 @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
|
439 @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
|
440 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 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
|
442 request.handled = True |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 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
|
444 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 # 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
|
446 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 sid = jingle_elt['sid'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 if not sid: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 raise KeyError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 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
|
452 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
|
453 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 # then the action |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 action = jingle_elt['action'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 if not action: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 raise KeyError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 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
|
462 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
|
463 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 |
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
|
465 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
|
466 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 # 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
|
468 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 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
|
470 except KeyError: |
1615
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
471 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
|
472 log.warning(u"Received request for an unknown session id: {}".format(sid)) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
473 self.sendError('item-not-found', None, request, 'unknown-session', profile=profile) |
1615
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
474 return |
a1e5bcd9a6eb
jingle XEP-0166: fixed session creation on non session-initiate actions
Goffi <goffi@goffi.org>
parents:
1614
diff
changeset
|
475 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 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
|
477 '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
|
478 'initiator': peer_jid, |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
479 '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
|
480 '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
|
481 'started': time.time(), |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 } |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 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
|
487 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 if session['id'] != sid: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 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
|
490 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
|
491 raise exceptions.InternalError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 self.onSessionAccept(client, request, jingle_elt, session) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
499 elif action == XEP_0166.A_SESSION_INFO: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
500 self.onSessionInfo(client, request, jingle_elt, session) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
501 elif action == XEP_0166.A_TRANSPORT_INFO: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
502 self.onTransportInfo(client, request, jingle_elt, session) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
503 elif action == XEP_0166.A_TRANSPORT_REPLACE: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
504 self.onTransportReplace(client, request, jingle_elt, session) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
505 elif action == XEP_0166.A_TRANSPORT_ACCEPT: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
506 self.onTransportAccept(client, request, jingle_elt, session) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
507 elif action == XEP_0166.A_TRANSPORT_REJECT: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
508 self.onTransportReject(client, request, jingle_elt, session) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 else: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
510 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
|
511 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 ## Actions callbacks ## |
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 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
|
515 """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
|
516 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 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
|
518 @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
|
519 @param session(dict): session data |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
520 @param request(domish.Element): the whole request |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
521 @param client: %(doc_client)s |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
522 @param new(bool): True if the content is new and must be created, |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 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
|
524 @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
|
525 @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
|
526 @param with_transport(bool): if True, raise an error if there is no <transport> element else ignore it |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
527 @raise exceptions.CancelError: the error is treated and the calling method can cancel the treatment (i.e. return) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 contents_dict = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 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
|
531 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
532 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
|
533 name = content_elt['name'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 if new: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
536 # 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
|
537 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
|
538 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
|
539 raise exceptions.CancelError |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
540 content_data = contents_dict[name] = {'creator': creator, |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
541 'senders': content_elt.attributes.get('senders', 'both'), |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
542 } |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
543 else: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 # 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
|
545 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
546 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
|
547 except KeyError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 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
|
549 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
|
550 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
551 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 # application |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
553 if with_application: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
554 desc_elt = content_elt.description |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
555 if not desc_elt: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
556 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
|
557 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
559 if new: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
560 # 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
|
561 app_ns = desc_elt.uri |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
562 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
|
563 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
|
564 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
566 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
567 application = self._applications[app_ns] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
568 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
569 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
|
570 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
|
571 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
573 content_data['application'] = application |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
574 content_data['application_data'] = {} |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
575 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
576 # 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
|
577 if 'desc_elt' in content_data: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
578 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
|
579 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
580 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
|
581 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 # transport |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
583 if with_transport: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
584 transport_elt = content_elt.transport |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
585 if not transport_elt: |
1614
1ced93821c35
plugin XEP-0166: sendError now manage jingle conditions
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
586 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
|
587 raise exceptions.CancelError |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
589 if new: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
590 # 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
|
591 transport_ns = transport_elt.uri |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
592 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
|
593 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
|
594 raise exceptions.CancelError |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
595 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
596 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
597 transport = self._transports[transport_ns] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
598 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
599 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
|
600 content_data['transport'] = transport |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
601 content_data['transport_data'] = {} |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
602 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
603 # 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
|
604 if 'transport_elt' in content_data: |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
605 raise exceptions.InternalError(u"transport_elt should not exist at this point") |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
606 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
607 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
|
608 |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
609 def _ignore(self, action, session, content_name, elt, profile): |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
610 """Dummy method used when not exception must be raised if a method is not implemented in _callPlugins |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
611 |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
612 must be used as app_default_cb and/or transp_default_cb |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
613 """ |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
614 return elt |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
615 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 """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
|
620 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
621 @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
|
622 @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
|
623 @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
|
624 None to ignore |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 @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
|
626 None to ignore |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 @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
|
628 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
|
629 @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
|
630 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
|
631 @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
|
632 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
|
633 @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
|
634 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) |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
635 @param force_element(None, domish.Element, object): if elements is False, it is used as element parameter |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
636 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
|
637 @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
|
638 @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
|
639 @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
|
640 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 contents_dict = session['contents'] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 defers_list = [] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 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
|
644 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
|
645 (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
|
646 (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
|
647 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
|
648 continue |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
649 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
650 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
|
651 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 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
|
653 except AttributeError: |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
654 if default_cb is None: |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
655 raise exceptions.NotFound(u'{} not implemented !'.format(method_name)) |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
656 else: |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 method = default_cb |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
658 if elements: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
659 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
|
660 else: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
661 elt = force_element |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
662 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
|
663 defers_list.append(d) |
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 return defers_list |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 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
|
668 """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
|
669 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 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
|
671 (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
|
672 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
|
673 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
|
674 @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
|
675 @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
|
676 @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
|
677 @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
|
678 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 if 'contents' in session: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 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
|
681 session['contents'] = contents_dict = {} |
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 try: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
684 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
|
685 except exceptions.CancelError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
687 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 if not contents_dict: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 # 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
|
690 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
|
691 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 # at this point we can send the <iq/> result to confirm reception of the request |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
694 client.send(xmlstream.toResponse(request, 'result')) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
695 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
696 # 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
|
697 # 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
|
698 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
|
699 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
700 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
|
701 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
|
702 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
|
703 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 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
|
705 """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
|
706 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
707 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
|
708 @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
|
709 @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
|
710 @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
|
711 @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
|
712 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
713 confirmed = all(confirm_results) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
714 if not confirmed: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
715 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
|
716 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
717 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
|
718 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
|
719 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
720 # contents |
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 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
|
723 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
|
724 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
725 defers_list = [] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
726 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
727 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
|
728 content_elt = jingle_elt.addElement('content') |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
729 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
|
730 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
|
731 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
732 application = content_data['application'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
733 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
|
734 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
735 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
|
736 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
|
737 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
|
738 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
|
739 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
740 transport = content_data['transport'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
741 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
|
742 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 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
|
747 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 def changeState(dummy, session): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
752 session['state'] = STATE_ACTIVE |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
753 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
754 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
|
755 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
|
756 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
|
757 return d_list |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
759 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
|
760 # 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
|
761 log.debug("Jingle Session {} terminated".format(session['id'])) |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
762 try: |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
763 reason_elt = jingle_elt.elements(NS_JINGLE, 'reason').next() |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
764 except StopIteration: |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
765 log.warning(u"Not reason given for session termination") |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
766 reason_elt = jingle_elt.addElement('reason') |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
767 |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
768 terminate_defers = self._callPlugins(XEP_0166.A_SESSION_TERMINATE, session, 'jingleTerminate', 'jingleTerminate', self._ignore, self._ignore, elements=False, force_element=reason_elt, profile=client.profile) |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
769 terminate_dlist = defer.DeferredList(terminate_defers) |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
770 |
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
771 terminate_dlist.addCallback(lambda dummy: self._delSession(client, session['id'])) |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
772 client.send(xmlstream.toResponse(request, 'result')) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
773 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
774 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
|
775 """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
|
776 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
777 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
|
778 @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
|
779 @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
|
780 @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
|
781 @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
|
782 """ |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
783 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
|
784 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
785 try: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
786 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
|
787 except exceptions.CancelError: |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
788 return |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
789 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
790 # at this point we can send the <iq/> result to confirm reception of the request |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
791 client.send(xmlstream.toResponse(request, 'result')) |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
792 # and change the state |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
793 session['state'] = STATE_ACTIVE |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
794 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 negociate_defers = [] |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
796 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
|
797 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
798 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
|
799 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
800 # 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
|
801 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
|
802 |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
803 def _onSessionCb(self, result, client, request, jingle_elt, session): |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
804 client.send(xmlstream.toResponse(request, 'result')) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
805 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
806 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
|
807 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
|
808 # 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
|
809 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
|
810 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
811 def onSessionInfo(self, client, request, jingle_elt, session): |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
812 """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
|
813 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
814 This method is only called for initiator |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
815 @param client: %(doc_client)s |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
816 @param request(domish.Element): full <iq> request |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
817 @param jingle_elt(domish.Element): the <jingle> element |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
818 @param session(dict): session data |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
819 """ |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
820 if not jingle_elt.children: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
821 # this is a session ping, see XEP-0166 §6.8 |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
822 client.send(xmlstream.toResponse(request, 'result')) |
1616
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
823 return |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
824 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
825 try: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
826 # 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
|
827 # 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
|
828 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
|
829 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
|
830 except exceptions.NotFound as e: |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
831 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
|
832 return |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
833 |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
834 dlist = defer.DeferredList(defers, fireOnOneErrback=True) |
1e05b776a55b
plugin XEP-0166: session-info action handling
Goffi <goffi@goffi.org>
parents:
1615
diff
changeset
|
835 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
|
836 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
|
837 |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
838 @defer.inlineCallbacks |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
839 def onTransportReplace(self, client, request, jingle_elt, session): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
840 """A transport change is requested |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
841 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
842 The request is parsed, and jingleHandler is called on concerned transport plugin(s) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
843 @param client: %(doc_client)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
844 @param request(domish.Element): full <iq> request |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
845 @param jingle_elt(domish.Element): the <jingle> element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
846 @param session(dict): session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
847 """ |
1754
f4e9f2f7fe0f
plugin XEP-0166: jingleTerminate is called (if present) on applications and transports plugins on session-terminate action, can be used to do some cleaning
Goffi <goffi@goffi.org>
parents:
1630
diff
changeset
|
848 log.debug(u"Other peer wants to replace the transport") |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
849 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
850 self._parseElements(jingle_elt, session, request, client, with_application=False) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
851 except exceptions.CancelError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
852 defer.returnValue(None) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
853 |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
854 client.send(xmlstream.toResponse(request, 'result')) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
855 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
856 content_name = None |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
857 to_replace = [] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
858 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
859 for content_name, content_data in session['contents'].iteritems(): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
860 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
861 transport_elt = content_data.pop('transport_elt') |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
862 except KeyError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
863 continue |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
864 transport_ns = transport_elt.uri |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
865 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
866 transport = self._transports[transport_ns] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
867 except KeyError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
868 log.warning(u"Other peer want to replace current transport with an unknown one: {}".format(transport_ns)) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
869 content_name = None |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
870 break |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
871 to_replace.append((content_name, content_data, transport, transport_elt)) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
872 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
873 if content_name is None: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
874 # wa can't accept the replacement |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
875 iq_elt, reject_jingle_elt = self._buildJingleElt(client, session, XEP_0166.A_TRANSPORT_REJECT) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
876 for child in jingle_elt.children: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
877 reject_jingle_elt.addChild(child) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
878 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
879 iq_elt.send() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
880 defer.returnValue(None) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
881 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
882 # at this point, everything is alright and we can replace the transport(s) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
883 # this is similar to an session-accept action, but for transports only |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
884 iq_elt, accept_jingle_elt = self._buildJingleElt(client, session, XEP_0166.A_TRANSPORT_ACCEPT) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
885 for content_name, content_data, transport, transport_elt in to_replace: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
886 # we can now actually replace the transport |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
887 yield content_data['transport'].handler.jingleHandler(XEP_0166.A_DESTROY, session, content_name, None, client.profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
888 content_data['transport'] = transport |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
889 content_data['transport_data'].clear() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
890 # and build the element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
891 content_elt = accept_jingle_elt.addElement('content') |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
892 content_elt['name'] = content_name |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
893 content_elt['creator'] = content_data['creator'] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
894 # we notify the transport and insert its <transport/> in the answer |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
895 accept_transport_elt = yield transport.handler.jingleHandler(XEP_0166.A_TRANSPORT_REPLACE, session, content_name, transport_elt, client.profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
896 content_elt.addChild(accept_transport_elt) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
897 # there is no confirmation needed here, so we can directly prepare it |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
898 yield transport.handler.jingleHandler(XEP_0166.A_PREPARE_RESPONDER, session, content_name, None, client.profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
899 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
900 iq_elt.send() |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
901 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
902 def onTransportAccept(self, client, request, jingle_elt, session): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
903 """Method called once transport replacement is accepted |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
904 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
905 @param client: %(doc_client)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
906 @param request(domish.Element): full <iq> request |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
907 @param jingle_elt(domish.Element): the <jingle> element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
908 @param session(dict): session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
909 """ |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
910 log.debug(u"new transport has been accepted") |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
911 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
912 try: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
913 self._parseElements(jingle_elt, session, request, client, with_application=False) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
914 except exceptions.CancelError: |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
915 return |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
916 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
917 # at this point we can send the <iq/> result to confirm reception of the request |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
918 client.send(xmlstream.toResponse(request, 'result')) |
1630
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
919 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
920 negociate_defers = [] |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
921 negociate_defers = self._callPlugins(XEP_0166.A_TRANSPORT_ACCEPT, session, app_method_name=None, profile=client.profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
922 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
923 negociate_dlist = defer.DeferredList(negociate_defers) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
924 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
925 # after negociations we start the transfer |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
926 negociate_dlist.addCallback(lambda dummy: self._callPlugins(XEP_0166.A_START, session, app_method_name=None, elements=False, profile=client.profile)) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
927 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
928 def onTransportReject(self, client, request, jingle_elt, session): |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
929 """Method called when a transport replacement is refused |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
930 |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
931 @param client: %(doc_client)s |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
932 @param request(domish.Element): full <iq> request |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
933 @param jingle_elt(domish.Element): the <jingle> element |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
934 @param session(dict): session data |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
935 """ |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
936 # XXX: for now, we terminate the session in case of transport-reject |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
937 # this behaviour may change in the future |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
938 self.terminate('failed-transport', session, client.profile) |
c25f63215632
plugin XEP-0166: transport replacement:
Goffi <goffi@goffi.org>
parents:
1617
diff
changeset
|
939 |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
940 def onTransportInfo(self, client, request, jingle_elt, session): |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
941 """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
|
942 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
943 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
|
944 @param client: %(doc_client)s |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
945 @param request(domish.Element): full <iq> request |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
946 @param jingle_elt(domish.Element): the <jingle> element |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
947 @param session(dict): session data |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
948 """ |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
949 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
|
950 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
951 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
952 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
|
953 except exceptions.CancelError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
954 return |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
955 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
956 # The parsing was OK, we send the <iq> result |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
957 client.send(xmlstream.toResponse(request, 'result')) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
958 |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
959 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
|
960 try: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
961 transport_elt = content_data.pop('transport_elt') |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
962 except KeyError: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
963 continue |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
964 else: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1523
diff
changeset
|
965 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
|
966 |
1523
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
967 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
968 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
|
969 implements(iwokkel.IDisco) |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
970 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
971 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
|
972 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
|
973 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
974 def connectionInitialized(self): |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
975 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
|
976 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
977 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
|
978 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
|
979 |
0209f8d35873
plugin XEP-0166: (jingle) first draft. Not all actions are managed yet
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
980 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
|
981 return [] |