annotate libervia/backend/plugins/plugin_xep_0096.py @ 4077:d6837db456fd

refactoring: fix names in doc following modules hierarchy refactoring
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 17:38:37 +0200
parents 4b842c1fb686
children e11b13418ba6
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
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.tools import xml_tools
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.tools import stream
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
31
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
32 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
33
0
goffi@necton2
parents:
diff changeset
34
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
35 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
36 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
37 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
38 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
39
0
goffi@necton2
parents:
diff changeset
40 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2046
diff changeset
41 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
42 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
43 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
44 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
45 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
46 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
47 C.PI_HANDLER: "no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 C.PI_DESCRIPTION: _("""Implementation of SI File Transfer"""),
0
goffi@necton2
parents:
diff changeset
49 }
goffi@necton2
parents:
diff changeset
50
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
51
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
52 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
53 # 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
54 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
55 human_name = D_("Stream Initiation")
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
56
0
goffi@necton2
parents:
diff changeset
57 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
58 log.info(_("Plugin XEP_0096 initialization"))
0
goffi@necton2
parents:
diff changeset
59 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 self.managed_stream_m = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 self.host.plugins["XEP-0065"].NAMESPACE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 self.host.plugins["XEP-0047"].NAMESPACE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 ] # 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
64 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
65 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
66 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
67 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
68 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
69 "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
70 )
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
71
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
72 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
73 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
74
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
75 def unload(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
76 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
77
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
78 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
79 """Send a bad-request error
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 8
diff changeset
80
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
81 @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
82 @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
83 """
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 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
85 log.warning(message)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 self._si.sendError(client, iq_elt, "bad-request")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
87
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
88 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
89 """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
90
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 @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
92 @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
93 - 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
94 - 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
95 - 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
96 """
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
97 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
98 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
99 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
100 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
101 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
102 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
103 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
104 range_ = True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
105
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
106 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 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
108 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
109 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
110
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_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
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_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
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 if range_offset != 0 or range_length != file_size:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 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
118
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 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
120
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
121 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
122 """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
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 @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
125 @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
126 @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
127 @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
128 """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
129 log.info(_("XEP-0096 file transfer requested"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 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
131
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 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
133 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
134 except StopIteration:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
135 return self._bad_request(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 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
137 )
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
138
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 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
140 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
141 except exceptions.NotFound:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
142 return self._bad_request(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 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
144 )
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
145
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 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
147 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
148 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
149 except (KeyError, ValueError):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
150 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
151
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 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
153 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
154
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
156 "File proposed: name=[{name}] size={size}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 name=filename, size=file_size
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
160
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
161 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
162 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
163 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 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
165
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:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
167 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
168 except ValueError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
169 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
170
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
171 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 stream_method = self.host.plugins["XEP-0020"].negotiate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 feature_elt, "stream-method", self.managed_stream_m, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 )
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
175 except KeyError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
176 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
177
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 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
179 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
180 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
181 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
182 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
183 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 log.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
185 "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
186 )
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
187 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
188 log.warning("Can't find a valid stream method")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 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
190 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
191
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 # 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
193 data = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 "name": filename,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 "peer_jid": peer_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 "size": file_size,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 "date": file_date,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 "hash": file_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 "desc": file_desc,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 "range": range_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 "range_offset": range_offset,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 "range_length": range_length,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 "si_id": si_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 "progress_id": si_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 "stream_method": stream_method,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 "stream_plugin": plugin,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 }
0
goffi@necton2
parents:
diff changeset
208
3528
849374e59178 component file sharing: quotas implementation:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
209 d = defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
210 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
211 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
212 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
213
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
214 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
215 """Called on confirmation answer
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
216
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
217 @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
218 @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
219 @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
220 """
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 if not accepted:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
222 log.info("File transfer declined")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 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
224 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
225 # 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
226 # 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
227 # 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
228 # 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
229 # 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
230 # 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
231 # 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
232 # 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
233 # 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
234 # 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
235 # 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
236 # 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
237 # 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
238 # 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
239 # 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
240 # 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
241 # 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
242 # 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
243 # return
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
244
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
245 # 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
246 # range_offset = file_obj.tell()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
247 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
248 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
249 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
250 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
251 d.addErrback(self._transfer_eb, client, data)
0
goffi@necton2
parents:
diff changeset
252
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253 # 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
254 feature_elt = self.host.plugins["XEP-0020"].choose_option(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 {"stream-method": data["stream_method"]}, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 )
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
257 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
258 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
259 # 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
260 # 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
261 # 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
262 # #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
263 # misc_elts.append(range_elt)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
264 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
265
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
266 def _transfer_cb(self, __, client, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
267 """Called by the stream method when transfer successfuly finished
0
goffi@necton2
parents:
diff changeset
268
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
269 @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
270 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 # TODO: check hash
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 data["stream_object"].close()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
273 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
274
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
275 def _transfer_eb(self, failure, client, data):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
276 """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
277
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
278 @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
279 @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
280 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
281 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
282 "Transfer {si_id} failed: {reason}".format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
283 reason=str(failure.value), **data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
284 )
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 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
287
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
288 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
289 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
290 return self.file_send(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 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
292 )
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
293
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
294 def file_send(self, client, peer_jid, filepath, name=None, desc=None, extra=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
295 """Send a file using XEP-0096
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
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
297 @param peer_jid(jid.JID): recipient
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
298 @param filepath(str): absolute path to the file to send
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
299 @param name(unicode): name of the file to send
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
300 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
301 @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
302 @param extra: not used here
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
303 @return: an unique id to identify the transfer
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
304 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
305 feature_elt = self.host.plugins["XEP-0020"].propose_features(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
306 {"stream-method": self.managed_stream_m}, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 )
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
308
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 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
310
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 statinfo = os.stat(filepath)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 file_elt = domish.Element((SI_PROFILE, "file"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313 file_elt["name"] = name or os.path.basename(filepath)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
314 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
315 size = statinfo.st_size
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316 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
317 if desc:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 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
319 file_transfer_elts.append(file_elt)
0
goffi@necton2
parents:
diff changeset
320
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 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
322
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
323 sid, offer_d = self._si.propose_stream(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 client, peer_jid, SI_PROFILE, feature_elt, file_transfer_elts
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 )
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
326 args = [filepath, sid, size, client]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
327 offer_d.addCallbacks(self._file_cb, self._file_eb, args, None, args)
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
328 return 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
329
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
330 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
331 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
332
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
333 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
334 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
335 except exceptions.NotFound:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
336 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
337 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
338
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
339 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
340 feature_elt, namespace=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
341 )
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
342 try:
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
343 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
344 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
345 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
346 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
347
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
348 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
349 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
350 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
351 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
352 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
353 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
354
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
355 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
356 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
357 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
358 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
359 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
360 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
361 return
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
362
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
363 stream_object = stream.FileStreamObject(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
364 self.host, client, filepath, uid=sid, size=size
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
365 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
366 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
367 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
368 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
369 d.addErrback(self._send_eb, client, sid, stream_object)
0
goffi@necton2
parents:
diff changeset
370
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
371 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
372 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
373 stanza_err = failure.value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
374 if stanza_err.code == "403" and stanza_err.condition == "forbidden":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 from_s = stanza_err.stanza["from"]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
376 log.info("File transfer refused by {}".format(from_s))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
377 msg = D_("The contact {} has refused your file").format(from_s)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
378 title = D_("File refused")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
379 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
380 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
381 log.warning(_("Error during file transfer"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
382 msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
383 "Something went wrong during the file transfer session initialisation: {reason}"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
384 ).format(reason=str(stanza_err))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
385 title = D_("File transfer error")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
386 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
387 elif failure.check(exceptions.DataError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
388 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
389 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
390 log.error("Error while proposing stream: {}".format(failure))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
391
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
392 def _send_cb(self, __, client, sid, stream_object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
393 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
394 _("transfer {sid} successfuly finished [{profile}]").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
395 sid=sid, profile=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
396 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
397 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
398 stream_object.close()
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 57
diff changeset
399
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3528
diff changeset
400 def _send_eb(self, failure, client, sid, stream_object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
401 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
402 _("transfer {sid} failed [{profile}]: {reason}").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
403 sid=sid, profile=client.profile, reason=str(failure.value)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
404 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
405 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
406 stream_object.close()