annotate libervia/backend/plugins/plugin_xep_0096.py @ 4241:898db6daf0d0

core: Jingle Remote Control implementation: This is an implementation of the protoXEP that will be submitted to XSF. It handle establishment of a remote control session, and the management of A/V calls with XEP-0167. rel 436
author Goffi <goffi@goffi.org>
date Sat, 11 May 2024 13:52:43 +0200
parents e11b13418ba6
children 0d7bb4df2343
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
0
goffi@necton2
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing xep-0096
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3449
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
19
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
20 import os
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
21 from twisted.words.xish import domish
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
22 from twisted.words.protocols.jabber import jid
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
23 from twisted.words.protocols.jabber import error
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
24 from twisted.internet import defer
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.i18n import _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 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
27 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.core import exceptions
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
29 from libervia.backend.core.xmpp import SatXMPPEntity
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.tools import xml_tools
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
31 from libervia.backend.tools import stream
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
32
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
33 log = getLogger(__name__)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
34
0
goffi@necton2
parents:
diff changeset
35
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
36 NS_SI_FT = "http://jabber.org/protocol/si/profile/file-transfer"
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 8
diff changeset
37 IQ_SET = '/iq[@type="set"]'
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
38 SI_PROFILE_NAME = "file-transfer"
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
39 SI_PROFILE = "http://jabber.org/protocol/si/profile/" + SI_PROFILE_NAME
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 8
diff changeset
40
0
goffi@necton2
parents:
diff changeset
41 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
42 C.PI_NAME: "XEP-0096 Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
43 C.PI_IMPORT_NAME: "XEP-0096",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
44 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
45 C.PI_PROTOCOLS: ["XEP-0096"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
46 C.PI_DEPENDENCIES: ["XEP-0020", "XEP-0095", "XEP-0065", "XEP-0047", "FILE"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
47 C.PI_MAIN: "XEP_0096",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
48 C.PI_HANDLER: "no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 C.PI_DESCRIPTION: _("""Implementation of SI File Transfer"""),
0
goffi@necton2
parents:
diff changeset
50 }
goffi@necton2
parents:
diff changeset
51
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
52
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
53 class XEP_0096(object):
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: 1583
diff changeset
54 # TODO: call self._f.unregister when unloading order will be managing (i.e. when depenencies will be unloaded at the end)
3449
893582c2d983 plugin XEP-0096: fix plugin following changes in `plugin_misc_file`
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
55 name = PLUGIN_INFO[C.PI_NAME]
893582c2d983 plugin XEP-0096: fix plugin following changes in `plugin_misc_file`
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
56 human_name = D_("Stream Initiation")
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
57
0
goffi@necton2
parents:
diff changeset
58 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
59 log.info(_("Plugin XEP_0096 initialization"))
0
goffi@necton2
parents:
diff changeset
60 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 self.managed_stream_m = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 self.host.plugins["XEP-0065"].NAMESPACE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 self.host.plugins["XEP-0047"].NAMESPACE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 ] # Stream methods managed
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
65 self._f = self.host.plugins["FILE"]
3449
893582c2d983 plugin XEP-0096: fix plugin following changes in `plugin_misc_file`
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
66 self._f.register(self)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
67 self._si = self.host.plugins["XEP-0095"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
68 self._si.register_si_profile(SI_PROFILE_NAME, self._transfer_request)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
69 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
70 "si_file_send", ".plugin", in_sign="sssss", out_sign="s", method=self._file_send
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
72
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
73 async def can_handle_file_send(self, client, peer_jid, filepath):
3449
893582c2d983 plugin XEP-0096: fix plugin following changes in `plugin_misc_file`
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
74 return await self.host.hasFeature(client, NS_SI_FT, peer_jid)
893582c2d983 plugin XEP-0096: fix plugin following changes in `plugin_misc_file`
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
75
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
76 def unload(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
77 self._si.unregister_si_profile(SI_PROFILE_NAME)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
78
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
79 def _bad_request(self, client, iq_elt, message=None):
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
80 """Send a bad-request error
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 8
diff changeset
81
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
82 @param iq_elt(domish.Element): initial <IQ> element of the SI request
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
83 @param message(None, unicode): informational message to display in the logs
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
84 """
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
85 if message is not None:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
86 log.warning(message)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 self._si.sendError(client, iq_elt, "bad-request")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
88
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
89 def _parse_range(self, parent_elt, file_size):
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
90 """find and parse <range/> element
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
91
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
92 @param parent_elt(domish.Element): direct parent of the <range/> element
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
93 @return (tuple[bool, int, int]): a tuple with
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
94 - True if range is required
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
95 - range_offset
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
96 - range_length
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
97 """
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
98 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
99 range_elt = next(parent_elt.elements(NS_SI_FT, "range"))
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
100 except StopIteration:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
101 range_ = False
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
102 range_offset = None
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
103 range_length = None
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
104 else:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
105 range_ = True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
106
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
107 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 range_offset = int(range_elt["offset"])
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
109 except KeyError:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
110 range_offset = 0
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
111
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
112 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 range_length = int(range_elt["length"])
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
114 except KeyError:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
115 range_length = file_size
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
116
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
117 if range_offset != 0 or range_length != file_size:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 raise NotImplementedError # FIXME
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
119
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
120 return range_, range_offset, range_length
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
121
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
122 def _transfer_request(self, client, iq_elt, si_id, si_mime_type, si_elt):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
123 """Called when a file transfer is requested
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
124
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
125 @param iq_elt(domish.Element): initial <IQ> element of the SI request
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
126 @param si_id(unicode): Stream Initiation session id
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
127 @param si_mime_type("unicode"): Mime type of the file (or default "application/octet-stream" if unknown)
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
128 @param si_elt(domish.Element): request
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
129 """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
130 log.info(_("XEP-0096 file transfer requested"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 peer_jid = jid.JID(iq_elt["from"])
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
132
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
133 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
134 file_elt = next(si_elt.elements(NS_SI_FT, "file"))
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
135 except StopIteration:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
136 return self._bad_request(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 client, iq_elt, "No <file/> element found in SI File Transfer request"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
139
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
140 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
141 feature_elt = self.host.plugins["XEP-0020"].get_feature_elt(si_elt)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
142 except exceptions.NotFound:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
143 return self._bad_request(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 client, iq_elt, "No <feature/> element found in SI File Transfer request"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
146
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
147 try:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
148 filename = file_elt["name"]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
149 file_size = int(file_elt["size"])
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
150 except (KeyError, ValueError):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
151 return self._bad_request(client, iq_elt, "Malformed SI File Transfer request")
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
152
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
153 file_date = file_elt.getAttribute("date")
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
154 file_hash = file_elt.getAttribute("hash")
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
155
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
157 "File proposed: name=[{name}] size={size}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 name=filename, size=file_size
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
161
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
162 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
163 file_desc = str(next(file_elt.elements(NS_SI_FT, "desc")))
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
164 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 file_desc = ""
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
166
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
167 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
168 range_, range_offset, range_length = self._parse_range(file_elt, file_size)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
169 except ValueError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
170 return self._bad_request(client, iq_elt, "Malformed SI File Transfer request")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
171
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
172 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 stream_method = self.host.plugins["XEP-0020"].negotiate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 feature_elt, "stream-method", self.managed_stream_m, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
176 except KeyError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
177 return self._bad_request(client, iq_elt, "No stream method found")
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
178
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
179 if stream_method:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
180 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
181 plugin = self.host.plugins["XEP-0065"]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
182 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
183 plugin = self.host.plugins["XEP-0047"]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
184 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 log.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
186 "Unknown stream method, this should not happen at this stage, cancelling transfer"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 )
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
188 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
189 log.warning("Can't find a valid stream method")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 self._si.sendError(client, iq_elt, "not-acceptable")
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
191 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
192
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 # if we are here, the transfer can start, we just need user's agreement
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 data = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 "name": filename,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 "peer_jid": peer_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 "size": file_size,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 "date": file_date,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 "hash": file_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 "desc": file_desc,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 "range": range_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 "range_offset": range_offset,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 "range_length": range_length,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 "si_id": si_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 "progress_id": si_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 "stream_method": stream_method,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 "stream_plugin": plugin,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 }
0
goffi@necton2
parents:
diff changeset
209
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
210 d = defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
211 self._f.get_dest_dir(client, peer_jid, data, data, stream_object=True)
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
212 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
213 d.addCallback(self.confirmation_cb, client, iq_elt, data)
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
214
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
215 def confirmation_cb(self, accepted, client, iq_elt, data):
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
216 """Called on confirmation answer
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
217
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
218 @param accepted(bool): True if file transfer is accepted
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
219 @param iq_elt(domish.Element): initial SI request
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
220 @param data(dict): session data
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
221 """
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
222 if not accepted:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
223 log.info("File transfer declined")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 self._si.sendError(client, iq_elt, "forbidden")
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
225 return
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
226 # data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
227 # can_range = data['can_range'] == "True"
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
228 # range_offset = 0
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
229 # if timeout.active():
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
230 # timeout.cancel()
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
231 # try:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
232 # dest_path = frontend_data['dest_path']
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
233 # except KeyError:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
234 # log.error(_('dest path not found in frontend_data'))
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
235 # del client._xep_0096_waiting_for_approval[sid]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
236 # return
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
237 # if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
238 # plugin = self.host.plugins["XEP-0065"]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
239 # elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
240 # plugin = self.host.plugins["XEP-0047"]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
241 # else:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
242 # log.error(_("Unknown stream method, this should not happen at this stage, cancelling transfer"))
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
243 # del client._xep_0096_waiting_for_approval[sid]
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
244 # return
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
245
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
246 # file_obj = self._getFileObject(dest_path, can_range)
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
247 # range_offset = file_obj.tell()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
248 d = data["stream_plugin"].create_session(
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
249 client, data["stream_object"], client.jid, data["peer_jid"], data["si_id"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
250 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
251 d.addCallback(self._transfer_cb, client, data)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
252 d.addErrback(self._transfer_eb, client, data)
0
goffi@necton2
parents:
diff changeset
253
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 # we can send the iq result
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
255 feature_elt = self.host.plugins["XEP-0020"].choose_option(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 {"stream-method": data["stream_method"]}, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
257 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
258 misc_elts = []
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
259 misc_elts.append(domish.Element((SI_PROFILE, "file")))
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
260 # if can_range:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
261 # range_elt = domish.Element((None, "range"))
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
262 # range_elt['offset'] = str(range_offset)
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
263 # #TODO: manage range length
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
264 # misc_elts.append(range_elt)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
265 self._si.accept_stream(client, iq_elt, feature_elt, misc_elts)
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
266
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
267 def _transfer_cb(self, __, client, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
268 """Called by the stream method when transfer successfuly finished
0
goffi@necton2
parents:
diff changeset
269
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
270 @param data: session data
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
271 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 # TODO: check hash
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
273 data["stream_object"].close()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
274 log.info("Transfer {si_id} successfuly finished".format(**data))
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
275
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
276 def _transfer_eb(self, failure, client, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
277 """Called when something went wrong with the transfer
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
278
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
279 @param id: stream id
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
280 @param data: session data
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
281 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
282 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
283 "Transfer {si_id} failed: {reason}".format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
284 reason=str(failure.value), **data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
285 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
286 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 data["stream_object"].close()
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
288
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
289 def _file_send(self, peer_jid_s, filepath, name, desc, profile=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
290 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
291 return self.file_send(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 client, jid.JID(peer_jid_s), filepath, name or None, desc or None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
294
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
295 def file_send(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
296 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
297 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
298 peer_jid: jid.JID,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
299 filepath: str,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
300 name: str|None = None,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
301 desc: str|None = None,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
302 extra: dict|None = None
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
303 ) -> dict:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
304 """Send a file using XEP-0096.
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
305
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
306 @param peer_jid: recipient
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
307 @param filepath: absolute path to the file to send
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
308 @param name: name of the file to send
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
309 name must not contain "/" characters
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
310 @param desc: description of the file
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
311 @param extra: not used here
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
312 @return: a dict with the key "progress" containing an unique id to identify the
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
313 transfer
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
314 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
315 feature_elt = self.host.plugins["XEP-0020"].propose_features(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316 {"stream-method": self.managed_stream_m}, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
317 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
318
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
319 file_transfer_elts = []
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
320
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
321 statinfo = os.stat(filepath)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 file_elt = domish.Element((SI_PROFILE, "file"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 file_elt["name"] = name or os.path.basename(filepath)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 assert "/" not in file_elt["name"]
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
325 size = statinfo.st_size
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 file_elt["size"] = str(size)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
327 if desc:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
328 file_elt.addElement("desc", content=desc)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
329 file_transfer_elts.append(file_elt)
0
goffi@necton2
parents:
diff changeset
330
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 file_transfer_elts.append(domish.Element((None, "range")))
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
332
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
333 sid, offer_d = self._si.propose_stream(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
334 client, peer_jid, SI_PROFILE, feature_elt, file_transfer_elts
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 )
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
336 args = [filepath, sid, size, client]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
337 offer_d.addCallbacks(self._file_cb, self._file_eb, args, None, args)
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
338 return {"progress": sid}
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
339
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
340 def _file_cb(self, result_tuple, filepath, sid, size, client):
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
341 iq_elt, si_elt = result_tuple
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
342
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
343 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
344 feature_elt = self.host.plugins["XEP-0020"].get_feature_elt(si_elt)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
345 except exceptions.NotFound:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
346 log.warning("No <feature/> element found in result while expected")
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
347 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
348
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
349 choosed_options = self.host.plugins["XEP-0020"].get_choosed_options(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
350 feature_elt, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
351 )
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
352 try:
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
353 stream_method = choosed_options["stream-method"]
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
354 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
355 log.warning("No stream method choosed")
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
356 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
357
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
358 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
359 file_elt = next(si_elt.elements(NS_SI_FT, "file"))
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
360 except StopIteration:
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
361 pass
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
362 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
363 range_, range_offset, range_length = self._parse_range(file_elt, size)
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
364
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
365 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
366 plugin = self.host.plugins["XEP-0065"]
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
367 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
368 plugin = self.host.plugins["XEP-0047"]
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
369 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
370 log.warning("Invalid stream method received")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
371 return
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
372
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
373 stream_object = stream.FileStreamObject(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
374 self.host, client, filepath, uid=sid, size=size
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
376 d = plugin.start_stream(client, stream_object, client.jid,
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
377 jid.JID(iq_elt["from"]), sid)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
378 d.addCallback(self._send_cb, client, sid, stream_object)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
379 d.addErrback(self._send_eb, client, sid, stream_object)
0
goffi@necton2
parents:
diff changeset
380
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
381 def _file_eb(self, failure, filepath, sid, size, client):
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
382 if failure.check(error.StanzaError):
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
383 stanza_err = failure.value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
384 if stanza_err.code == "403" and stanza_err.condition == "forbidden":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
385 from_s = stanza_err.stanza["from"]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
386 log.info("File transfer refused by {}".format(from_s))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
387 msg = D_("The contact {} has refused your file").format(from_s)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
388 title = D_("File refused")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
389 xml_tools.quick_note(self.host, client, msg, title, C.XMLUI_DATA_LVL_INFO)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
390 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
391 log.warning(_("Error during file transfer"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
392 msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
393 "Something went wrong during the file transfer session initialisation: {reason}"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
394 ).format(reason=str(stanza_err))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
395 title = D_("File transfer error")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
396 xml_tools.quick_note(self.host, client, msg, title, C.XMLUI_DATA_LVL_ERROR)
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
397 elif failure.check(exceptions.DataError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
398 log.warning("Invalid stanza received")
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
399 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
400 log.error("Error while proposing stream: {}".format(failure))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
401
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
402 def _send_cb(self, __, client, sid, stream_object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
403 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
404 _("transfer {sid} successfuly finished [{profile}]").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
405 sid=sid, profile=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
406 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
407 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
408 stream_object.close()
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 57
diff changeset
409
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
410 def _send_eb(self, failure, client, sid, stream_object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
411 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
412 _("transfer {sid} failed [{profile}]: {reason}").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
413 sid=sid, profile=client.profile, reason=str(failure.value)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
415 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
416 stream_object.close()