annotate libervia/backend/plugins/plugin_xep_0261.py @ 4309:b56b1eae7994

component email gateway: add multicasting: XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033 metadata are converted to suitable Email headers and vice versa. Email address and JID are both supported, and delivery is done by the gateway when suitable on incoming messages. rel 450
author Goffi <goffi@goffi.org>
date Thu, 26 Sep 2024 16:12:01 +0200
parents 0d7bb4df2343
children
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)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 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
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.log import getLogger
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 from libervia.backend.plugins.plugin_xep_0166.models import BaseTransportHandler
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
24
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 log = getLogger(__name__)
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from wokkel import disco, iwokkel
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
27 from zope.interface import implementer
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.words.xish import domish
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import uuid
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 try:
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from twisted.words.protocols.xmlstream import XMPPHandler
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 except ImportError:
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from wokkel.subprotocols import XMPPHandler
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 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
38
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
40 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
41 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
42 C.PI_TYPE: "XEP",
2504
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
43 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
44 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
45 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
46 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
47 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 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
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
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
52 class XEP_0261(BaseTransportHandler):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 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
54
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 def __init__(self, host):
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 log.info(_("plugin Jingle In-Band Bytestreams"))
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 self._j = host.plugins["XEP-0166"] # shortcut to access jingle
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 self._ibb = host.plugins["XEP-0047"] # and in-band bytestream
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
60 self._j.register_transport(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 ) # must be the lowest priority
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
64 def get_handler(self, client):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 return XEP_0261_handler()
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
67 def jingle_session_init(self, client, session, content_name):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 transport_elt = domish.Element((NS_JINGLE_IBB, "transport"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 content_data = session["contents"][content_name]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 transport_data = content_data["transport_data"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 transport_data["block_size"] = self._ibb.BLOCK_SIZE
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
72 transport_elt["block-size"] = str(transport_data["block_size"])
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
73 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
74 return transport_elt
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
76 def jingle_handler(self, client, action, session, content_name, transport_elt):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 content_data = session["contents"][content_name]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 transport_data = content_data["transport_data"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 if action in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 self._j.A_SESSION_ACCEPT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 self._j.A_ACCEPTED_ACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 self._j.A_TRANSPORT_ACCEPT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 ):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 pass
1631
25906c0dbc63 plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents: 1571
diff changeset
85 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
86 transport_data["sid"] = transport_elt["sid"]
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 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
88 local_jid = session["local_jid"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 peer_jid = session["peer_jid"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 sid = transport_data["sid"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 stream_object = content_data["stream_object"]
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if action == self._j.A_START:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 block_size = transport_data["block_size"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
94 d = self._ibb.start_stream(
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
95 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
96 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 d.chainDeferred(content_data["finished_d"])
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 d = self._ibb.create_session(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
100 client, stream_object, local_jid, peer_jid, sid
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
101 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 d.chainDeferred(content_data["finished_d"])
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
104 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
105 return transport_elt
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
108 @implementer(iwokkel.IDisco)
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 class XEP_0261_handler(XMPPHandler):
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 return [disco.DiscoFeature(NS_JINGLE_IBB)]
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
1527
bfef1934a8f3 plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 return []