annotate sat/plugins/plugin_xep_0261.py @ 3320:bb92085720c8

plugin XEP-0329: implemented ways to get/set affiliations: PubSub-like affiliations can now be get/set using non standard methods. This has been done to prepare the move to a pubsub based file sharing system.
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:12:44 +0200
parents 559a625a236b
children be6d91572633
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for Jingle (XEP-0261)
3136
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
21 from sat.core.constants import Const as C
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from wokkel import disco, iwokkel
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
26 from zope.interface import implementer
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.xish import domish
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import uuid
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 try:
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from twisted.words.protocols.xmlstream import XMPPHandler
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 except ImportError:
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from wokkel.subprotocols import XMPPHandler
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 NS_JINGLE_IBB = "urn:xmpp:jingle:transports:ibb:1"
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
39 C.PI_NAME: "Jingle In-Band Bytestreams",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
40 C.PI_IMPORT_NAME: "XEP-0261",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
41 C.PI_TYPE: "XEP",
2504
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
42 C.PI_MODES: C.PLUG_MODE_BOTH,
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
43 C.PI_PROTOCOLS: ["XEP-0261"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0047"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
45 C.PI_MAIN: "XEP_0261",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
46 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 C.PI_DESCRIPTION: _("""Implementation of Jingle In-Band Bytestreams"""),
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 }
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class XEP_0261(object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 NAMESPACE = NS_JINGLE_IBB # used by XEP-0260 plugin for transport-replace
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def __init__(self, host):
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 log.info(_("plugin Jingle In-Band Bytestreams"))
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 self._j = host.plugins["XEP-0166"] # shortcut to access jingle
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 self._ibb = host.plugins["XEP-0047"] # and in-band bytestream
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 self._j.registerTransport(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 ) # must be the lowest priority
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
63 def getHandler(self, client):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 return XEP_0261_handler()
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
66 def jingleSessionInit(self, client, session, content_name):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 transport_elt = domish.Element((NS_JINGLE_IBB, "transport"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 content_data = session["contents"][content_name]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 transport_data = content_data["transport_data"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 transport_data["block_size"] = self._ibb.BLOCK_SIZE
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
71 transport_elt["block-size"] = str(transport_data["block_size"])
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
72 transport_elt["sid"] = transport_data["sid"] = str(uuid.uuid4())
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 return transport_elt
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
75 def jingleHandler(self, client, action, session, content_name, transport_elt):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 content_data = session["contents"][content_name]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 transport_data = content_data["transport_data"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 if action in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 self._j.A_SESSION_ACCEPT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 self._j.A_ACCEPTED_ACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 self._j.A_TRANSPORT_ACCEPT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 ):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 pass
1631
25906c0dbc63 plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents: 1571
diff changeset
84 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 transport_data["sid"] = transport_elt["sid"]
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER):
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
87 local_jid = session["local_jid"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 peer_jid = session["peer_jid"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 sid = transport_data["sid"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 stream_object = content_data["stream_object"]
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 if action == self._j.A_START:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 block_size = transport_data["block_size"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 d = self._ibb.startStream(
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
94 client, stream_object, local_jid, peer_jid, sid, block_size
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 d.chainDeferred(content_data["finished_d"])
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 else:
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
98 d = self._ibb.createSession(
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
99 client, stream_object, local_jid, peer_jid, sid)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 d.chainDeferred(content_data["finished_d"])
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
102 log.warning("FIXME: unmanaged action {}".format(action))
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 return transport_elt
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
106 @implementer(iwokkel.IDisco)
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 class XEP_0261_handler(XMPPHandler):
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 return [disco.DiscoFeature(NS_JINGLE_IBB)]
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 return []