annotate libervia/backend/plugins/plugin_xep_0096.py @ 4340:ea72364131d5 default tip @

doc (components): Update Email Gateway documentation: A section has been added to explain how attachments are handled. fix 453
author Goffi <goffi@goffi.org>
date Tue, 03 Dec 2024 00:53:18 +0100
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
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(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
70 "si_file_send",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
71 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
72 in_sign="sssss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
73 out_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
74 method=self._file_send,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
77 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
78 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
79
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 def unload(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
81 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
82
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
83 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
84 """Send a bad-request error
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 8
diff changeset
85
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
86 @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
87 @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
88 """
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
89 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
90 log.warning(message)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 self._si.sendError(client, iq_elt, "bad-request")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
92
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
93 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
94 """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
95
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 @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
97 @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
98 - 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
99 - 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
100 - 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
101 """
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
102 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
103 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
104 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
105 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
106 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
107 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
108 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
109 range_ = True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
110
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
111 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 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
113 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
114 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
115
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 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 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
118 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
119 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
120
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 if range_offset != 0 or range_length != file_size:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 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
123
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 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
125
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
126 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
127 """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
128
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 @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
130 @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
131 @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
132 @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
133 """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
134 log.info(_("XEP-0096 file transfer requested"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 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
136
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
137 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
138 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
139 except StopIteration:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
140 return self._bad_request(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 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
142 )
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
143
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
144 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
145 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
146 except exceptions.NotFound:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
147 return self._bad_request(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 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
149 )
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
150
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
151 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
152 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
153 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
154 except (KeyError, ValueError):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
155 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
156
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
157 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
158 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
159
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
161 "File proposed: name=[{name}] size={size}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 name=filename, size=file_size
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
165
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 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
167 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
168 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 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
170
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
171 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
172 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
173 except ValueError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
174 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
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 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 stream_method = self.host.plugins["XEP-0020"].negotiate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 feature_elt, "stream-method", self.managed_stream_m, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 )
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
180 except KeyError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
181 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
182
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 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
184 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
185 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
186 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
187 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
188 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 log.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
190 "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
191 )
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
192 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
193 log.warning("Can't find a valid stream method")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 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
195 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
196
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 # 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
198 data = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 "name": filename,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 "peer_jid": peer_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 "size": file_size,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 "date": file_date,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 "hash": file_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 "desc": file_desc,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 "range": range_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 "range_offset": range_offset,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 "range_length": range_length,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 "si_id": si_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 "progress_id": si_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 "stream_method": stream_method,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 "stream_plugin": plugin,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 }
0
goffi@necton2
parents:
diff changeset
213
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
214 d = defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
215 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
216 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
217 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
218
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
219 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
220 """Called on confirmation answer
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
221
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
222 @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
223 @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
224 @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
225 """
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 if not accepted:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
227 log.info("File transfer declined")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 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
229 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
230 # 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
231 # 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
232 # 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
233 # 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
234 # 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
235 # 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
236 # 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
237 # 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
238 # 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
239 # 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
240 # 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
241 # 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
242 # 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
243 # 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
244 # 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
245 # 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
246 # 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
247 # 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
248 # return
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
249
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
250 # 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
251 # range_offset = file_obj.tell()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
252 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
253 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
254 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
255 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
256 d.addErrback(self._transfer_eb, client, data)
0
goffi@necton2
parents:
diff changeset
257
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
258 # 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
259 feature_elt = self.host.plugins["XEP-0020"].choose_option(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
260 {"stream-method": data["stream_method"]}, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
261 )
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
262 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
263 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
264 # 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
265 # 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
266 # 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
267 # #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
268 # misc_elts.append(range_elt)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
269 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
270
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
271 def _transfer_cb(self, __, client, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
272 """Called by the stream method when transfer successfuly finished
0
goffi@necton2
parents:
diff changeset
273
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
274 @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
275 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 # TODO: check hash
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 data["stream_object"].close()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
278 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
279
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
280 def _transfer_eb(self, failure, client, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
281 """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
282
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
283 @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
284 @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
285 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
286 log.warning(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
287 "Transfer {si_id} failed: {reason}".format(reason=str(failure.value), **data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
289 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
290
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
291 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
292 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
293 return self.file_send(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
294 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
295 )
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
296
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
297 def file_send(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
298 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
299 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
300 peer_jid: jid.JID,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
301 filepath: str,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
302 name: str | None = None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
303 desc: str | None = None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
304 extra: dict | None = None,
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
305 ) -> dict:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
306 """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
307
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
308 @param peer_jid: recipient
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
309 @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
310 @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
311 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
312 @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
313 @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
314 @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
315 transfer
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
316 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
317 feature_elt = self.host.plugins["XEP-0020"].propose_features(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 {"stream-method": self.managed_stream_m}, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
319 )
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
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 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
322
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
323 statinfo = os.stat(filepath)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 file_elt = domish.Element((SI_PROFILE, "file"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 file_elt["name"] = name or os.path.basename(filepath)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 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
327 size = statinfo.st_size
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
328 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
329 if desc:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 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
331 file_transfer_elts.append(file_elt)
0
goffi@necton2
parents:
diff changeset
332
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
333 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
334
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
335 sid, offer_d = self._si.propose_stream(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
336 client, peer_jid, SI_PROFILE, feature_elt, file_transfer_elts
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
337 )
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
338 args = [filepath, sid, size, client]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
339 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
340 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
341
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
342 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
343 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
344
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 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
346 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
347 except exceptions.NotFound:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
348 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
349 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
350
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
351 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
352 feature_elt, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
353 )
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
354 try:
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
355 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
356 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
357 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
358 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
359
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 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
361 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
362 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
363 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
364 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
365 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
366
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
367 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
368 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
369 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
370 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
371 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
372 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
373 return
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
374
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 stream_object = stream.FileStreamObject(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
376 self.host, client, filepath, uid=sid, size=size
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
377 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
378 d = plugin.start_stream(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
379 client, stream_object, client.jid, jid.JID(iq_elt["from"]), sid
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
380 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
381 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
382 d.addErrback(self._send_eb, client, sid, stream_object)
0
goffi@necton2
parents:
diff changeset
383
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
384 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
385 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
386 stanza_err = failure.value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
387 if stanza_err.code == "403" and stanza_err.condition == "forbidden":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
388 from_s = stanza_err.stanza["from"]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
389 log.info("File transfer refused by {}".format(from_s))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
390 msg = D_("The contact {} has refused your file").format(from_s)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
391 title = D_("File refused")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
392 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
393 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
394 log.warning(_("Error during file transfer"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
395 msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
396 "Something went wrong during the file transfer session initialisation: {reason}"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
397 ).format(reason=str(stanza_err))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
398 title = D_("File transfer error")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
399 xml_tools.quick_note(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
400 self.host, client, msg, title, C.XMLUI_DATA_LVL_ERROR
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
401 )
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
402 elif failure.check(exceptions.DataError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
403 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
404 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
405 log.error("Error while proposing stream: {}".format(failure))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
406
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
407 def _send_cb(self, __, client, sid, stream_object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
408 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
409 _("transfer {sid} successfuly finished [{profile}]").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
410 sid=sid, profile=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
411 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
412 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
413 stream_object.close()
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 57
diff changeset
414
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
415 def _send_eb(self, failure, client, sid, stream_object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
416 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
417 _("transfer {sid} failed [{profile}]: {reason}").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
418 sid=sid, profile=client.profile, reason=str(failure.value)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
419 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
420 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
421 stream_object.close()