Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0234.py @ 4334:111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Pydantic models are used more and more in Libervia, for the bridge API, and also to
convert `domish.Element` to internal representation.
Type hints have also been added in many places.
rel 453
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Dec 2024 00:12:38 +0100 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
3 # SàT plugin for Jingle File Transfer (XEP-0234) |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
19 from collections import namedtuple |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
20 import mimetypes |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
21 import os.path |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
22 |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
23 from twisted.internet import defer |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
24 from twisted.internet import reactor |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
25 from twisted.internet import error as internet_error |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
26 from twisted.python import failure |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
27 from twisted.words.protocols.jabber import jid |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
28 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
29 from twisted.words.xish import domish |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
30 from wokkel import disco, iwokkel |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
31 from zope.interface import implementer |
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
32 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
33 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
34 from libervia.backend.core.constants import Const as C |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
35 from libervia.backend.core.core_types import SatXMPPEntity |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
36 from libervia.backend.core.i18n import D_, _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
37 from libervia.backend.core.log import getLogger |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
38 from libervia.backend.tools import xml_tools |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
39 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
40 from libervia.backend.tools import stream |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
41 from libervia.backend.tools.common import data_format, date_utils |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
42 from libervia.backend.tools.common import regex |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
43 from libervia.backend.tools.common.utils import get_human_size |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
44 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
45 from .plugin_xep_0166 import BaseApplicationHandler |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
46 |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
48 log = getLogger(__name__) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
50 NS_JINGLE_FT = "urn:xmpp:jingle:apps:file-transfer:5" |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
53 C.PI_NAME: "Jingle File Transfer", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
54 C.PI_IMPORT_NAME: "XEP-0234", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
55 C.PI_TYPE: "XEP", |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
56 C.PI_MODES: C.PLUG_MODE_BOTH, |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
57 C.PI_PROTOCOLS: ["XEP-0234"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
58 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0300", "FILE"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
59 C.PI_MAIN: "XEP_0234", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
60 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
61 C.PI_DESCRIPTION: _("""Implementation of Jingle File Transfer"""), |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 } |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
64 # TODO: use a Pydantic model for extra |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
65 EXTRA_ALLOWED = { |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
66 "path", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
67 "namespace", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
68 "file_desc", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
69 "file_hash", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
70 "hash_algo", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
71 "webrtc", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
72 "call_data", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
73 "size", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
74 "media_type", |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
75 } |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
76 Range = namedtuple("Range", ("offset", "length")) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
77 |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
79 class XEP_0234(BaseApplicationHandler): |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
80 # TODO: assure everything is closed when file is sent or session terminate is received |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
81 # TODO: call self._f.unregister when unloading order will be managing (i.e. when |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
82 # dependencies will be unloaded at the end) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
83 Range = Range # we copy the class here, so it can be used by other plugins |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
84 name = PLUGIN_INFO[C.PI_NAME] |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
85 human_name = D_("file transfer") |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 def __init__(self, host): |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 log.info(_("plugin Jingle File Transfer initialization")) |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
90 host.register_namespace("jingle-ft", NS_JINGLE_FT) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
91 self._j = host.plugins["XEP-0166"] # shortcut to access jingle |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
92 self._j.register_application(NS_JINGLE_FT, self) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 self._f = host.plugins["FILE"] |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
94 self._f.register(self, priority=10000) |
1618
0de5f210fe56
plugin XEP-0300: implemented hashing:
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
95 self._hash = self.host.plugins["XEP-0300"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
96 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
97 "file_jingle_send", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
98 ".plugin", |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
99 in_sign="ssssss", |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
100 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
101 method=self._file_send, |
3028 | 102 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
103 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
104 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
105 "file_jingle_request", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
106 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
107 in_sign="sssssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
108 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
109 method=self._file_jingle_request, |
3028 | 110 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
111 ) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
113 def get_handler(self, client): |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 return XEP_0234_handler() |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
116 def get_progress_id(self, session, content_name): |
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:
1575
diff
changeset
|
117 """Return a unique progress ID |
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:
1575
diff
changeset
|
118 |
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:
1575
diff
changeset
|
119 @param session(dict): jingle session |
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:
1575
diff
changeset
|
120 @param content_name(unicode): name of the content |
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:
1575
diff
changeset
|
121 @return (unicode): unique progress id |
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:
1575
diff
changeset
|
122 """ |
3028 | 123 return "{}_{}".format(session["id"], content_name) |
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:
1575
diff
changeset
|
124 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
125 async def can_handle_file_send(self, client, peer_jid, filepath): |
3403
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
126 if peer_jid.resource: |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
127 return await self.host.hasFeature(client, NS_JINGLE_FT, peer_jid) |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
128 else: |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
129 # if we have a bare jid, Jingle Message Initiation will be tried |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
130 return True |
404d4b29de52
plugin file, XEP-0234: registering is now done by class + use of async:
Goffi <goffi@goffi.org>
parents:
3345
diff
changeset
|
131 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
132 # generic methods |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
133 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
134 def build_file_element( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
135 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
136 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
137 name=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
138 file_hash=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
139 hash_algo=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
140 size=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
141 mime_type=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
142 desc=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
143 modified=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
144 transfer_range=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
145 path=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
146 namespace=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
147 file_elt=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
148 **kwargs, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
149 ): |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
150 """Generate a <file> element with available metadata |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
151 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
152 @param file_hash(unicode, None): hash of the file |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
153 empty string to set <hash-used/> element |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
154 @param hash_algo(unicode, None): hash algorithm used |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
155 if file_hash is None and hash_algo is set, a <hash-used/> element will be |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
156 generated |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
157 @param transfer_range(Range, None): where transfer must start/stop |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
158 @param modified(int, unicode, None): date of last modification |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
159 0 to use current date |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
160 int to use an unix timestamp |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
161 else must be an unicode string which will be used as it (it must be an XMPP |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
162 time) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
163 @param file_elt(domish.Element, None): element to use |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
164 None to create a new one |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
165 @param **kwargs: data for plugin extension (ignored by default) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
166 @return (domish.Element): generated element |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
167 @trigger XEP-0234_buildFileElement(file_elt, extra_args): can be used to extend |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
168 elements to add |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
169 """ |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
170 if file_elt is None: |
3028 | 171 file_elt = domish.Element((NS_JINGLE_FT, "file")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
172 for name, value in ( |
3028 | 173 ("name", name), |
174 ("size", size), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
175 ("media-type", mime_type), |
3028 | 176 ("desc", desc), |
177 ("path", path), | |
178 ("namespace", namespace), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
179 ): |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
180 if value is not None: |
3028 | 181 file_elt.addElement(name, content=str(value)) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
182 |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
183 if modified is not None: |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
184 if isinstance(modified, int): |
3028 | 185 file_elt.addElement("date", utils.xmpp_date(modified or None)) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
186 else: |
3028 | 187 file_elt.addElement("date", modified) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
188 elif "created" in kwargs: |
3028 | 189 file_elt.addElement("date", utils.xmpp_date(kwargs.pop("created"))) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
190 |
3028 | 191 range_elt = file_elt.addElement("range") |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
192 if transfer_range is not None: |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
193 if transfer_range.offset is not None: |
3028 | 194 range_elt["offset"] = transfer_range.offset |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
195 if transfer_range.length is not None: |
3028 | 196 range_elt["length"] = transfer_range.length |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
197 if file_hash is not None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
198 if not file_hash: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
199 file_elt.addChild(self._hash.build_hash_used_elt()) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
200 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
201 file_elt.addChild(self._hash.build_hash_elt(file_hash, hash_algo)) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
202 elif hash_algo is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
203 file_elt.addChild(self._hash.build_hash_used_elt(hash_algo)) |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
204 self.host.trigger.point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
205 "XEP-0234_buildFileElement", client, file_elt, extra_args=kwargs |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
206 ) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
207 if kwargs: |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
208 for kw in kwargs: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
209 log.debug("ignored keyword: {}".format(kw)) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
210 return file_elt |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
211 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
212 def build_file_element_from_dict(self, client, file_data, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
213 """like build_file_element but get values from a file_data dict |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
214 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
215 @param file_data(dict): metadata to use |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
216 @param **kwargs: data to override |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
217 """ |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
218 if kwargs: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
219 file_data = file_data.copy() |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
220 file_data.update(kwargs) |
3345
3dc8835d96cc
plugin XEP-0234: fixed mime type in `buildFileElementFromDict`
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
221 try: |
3dc8835d96cc
plugin XEP-0234: fixed mime type in `buildFileElementFromDict`
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
222 file_data["mime_type"] = ( |
3dc8835d96cc
plugin XEP-0234: fixed mime type in `buildFileElementFromDict`
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
223 f'{file_data.pop("media_type")}/{file_data.pop("media_subtype")}' |
3dc8835d96cc
plugin XEP-0234: fixed mime type in `buildFileElementFromDict`
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
224 ) |
3dc8835d96cc
plugin XEP-0234: fixed mime type in `buildFileElementFromDict`
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
225 except KeyError: |
3dc8835d96cc
plugin XEP-0234: fixed mime type in `buildFileElementFromDict`
Goffi <goffi@goffi.org>
parents:
3333
diff
changeset
|
226 pass |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
227 return self.build_file_element(client, **file_data) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
228 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
229 async def parse_file_element( |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
230 self, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
231 client: SatXMPPEntity, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
232 file_elt: domish.Element | None, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
233 file_data: dict | None = None, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
234 given: bool = False, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
235 parent_elt: domish.Element | None = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
236 keep_empty_range: bool = False, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
237 ) -> dict: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
238 """Parse a <file> element and updates file dictionary accordingly. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
239 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
240 @param client: The SatXMPPEntity instance. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
241 @param file_elt: The file element to parse. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
242 @param file_data: Dict where the data will be set. Data are overwritten if they |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
243 exists (see @return for details). |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
244 If None, a new dict is created. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
245 @param given: If True, prefix hash key with "given_". |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
246 @param parent_elt: Parent of the file element. If set, file_elt must not be set. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
247 @param keep_empty_range: If True, keep empty range (i.e. range when offset |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
248 and length are None). Useful to know if a peer_jid can handle range. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
249 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
250 @return: file_data which is an updated or newly created dictionary with the following keys: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
251 **name** (str) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
252 Name of the file. Defaults to "unnamed" if not provided, "--" if the name is |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
253 "..", or a sanitized version if it contains path separators. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
254 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
255 **file_hash** (str, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
256 Hash of the file. Prefixed with "given_" if `given` is True. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
257 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
258 **hash_algo** (str, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
259 Algorithm used for the file hash. |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
260 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
261 **size** (int, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
262 Size of the file in bytes. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
263 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
264 **mime_type** (str, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
265 Media type of the file. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
266 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
267 **desc** (str, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
268 Description of the file. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
269 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
270 **path** (str, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
271 Path of the file. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
272 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
273 **namespace** (str, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
274 Namespace associated with the file. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
275 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
276 **transfer_range** (Range, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
277 Range of the file transfer. Present only if offset or length are specified, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
278 or if `keep_empty_range` is True. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
279 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
280 **modified** (datetime, optional) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
281 Last modified date of the file. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
282 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
283 @trigger XEP-0234_parseFileElement(file_elt, file_data): Can be used to parse new |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
284 elements. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
285 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
286 @raise exceptions.NotFound: Raised if there is no <file> element in `parent_elt` |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
287 or if required elements are missing. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
288 @raise exceptions.DataError: Raised if `file_elt` URI is not NS_JINGLE_FT or if |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
289 the file element is invalid. |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
290 """ |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
291 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
292 if parent_elt is not None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
293 if file_elt is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
294 raise exceptions.InternalError( |
3028 | 295 "file_elt must be None if parent_elt is set" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
296 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
297 try: |
3028 | 298 file_elt = next(parent_elt.elements(NS_JINGLE_FT, "file")) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
299 except StopIteration: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
300 raise exceptions.NotFound() |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
301 else: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
302 if not file_elt or file_elt.uri != NS_JINGLE_FT: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
303 raise exceptions.DataError( |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
304 f"invalid <file> element: {file_elt.toXml() if file_elt else 'None'}" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
305 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
306 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
307 if file_data is None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
308 file_data = {} |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
309 |
3028 | 310 for name in ("name", "desc", "path", "namespace"): |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
311 try: |
3028 | 312 file_data[name] = str(next(file_elt.elements(NS_JINGLE_FT, name))) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
313 except StopIteration: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
314 pass |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
315 |
3028 | 316 name = file_data.get("name") |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
317 if name is None: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
318 file_data["name"] = "unnamed" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
319 elif name == "..": |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
320 # we don't want to go to parent dir when joining to a path |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
321 file_data["name"] = "--" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
322 elif "/" in name or "\\" in name: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
323 file_data["name"] = regex.path_escape(name) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
324 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
325 try: |
3028 | 326 file_data["mime_type"] = str( |
327 next(file_elt.elements(NS_JINGLE_FT, "media-type")) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
328 ) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
329 except StopIteration: |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
330 pass |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
331 |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
332 try: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
333 file_data["size"] = int(str(next(file_elt.elements(NS_JINGLE_FT, "size")))) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
334 except StopIteration: |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
335 pass |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
336 |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
337 try: |
3028 | 338 file_data["modified"] = date_utils.date_parse( |
339 next(file_elt.elements(NS_JINGLE_FT, "date")) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
340 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
341 except StopIteration: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
342 pass |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
343 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
344 try: |
3028 | 345 range_elt = next(file_elt.elements(NS_JINGLE_FT, "range")) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
346 except StopIteration: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
347 pass |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
348 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
349 offset = range_elt.getAttribute("offset") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
350 length = range_elt.getAttribute("length") |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
351 if offset or length or keep_empty_range: |
3028 | 352 file_data["transfer_range"] = Range(offset=offset, length=length) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
353 |
3028 | 354 prefix = "given_" if given else "" |
355 hash_algo_key, hash_key = "hash_algo", prefix + "file_hash" | |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
356 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
357 file_data[hash_algo_key], file_data[hash_key] = self._hash.parse_hash_elt( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
358 file_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
359 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
360 except exceptions.NotFound: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
361 pass |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
362 |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3303
diff
changeset
|
363 self.host.trigger.point("XEP-0234_parseFileElement", client, file_elt, file_data) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
364 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
365 return file_data |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
366 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
367 # bridge methods |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
368 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
369 def _file_send( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
370 self, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
371 peer_jid_s: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
372 filepath: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
373 name: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
374 file_desc: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
375 extra_s: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
376 profile: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
377 ) -> defer.Deferred[str]: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
378 client = self.host.get_client(profile) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
379 extra = data_format.deserialise(extra_s) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
380 d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
381 self.file_send( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
382 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
383 jid.JID(peer_jid_s), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
384 filepath, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
385 name or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
386 file_desc or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
387 extra, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
388 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
389 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
390 d.addCallback(data_format.serialise) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
391 return d |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
393 async def file_send( |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
394 self, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
395 client: SatXMPPEntity, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
396 peer_jid: jid.JID, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
397 filepath: str, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
398 name: str | None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
399 file_desc: str | None = None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
400 extra: dict | None = None, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
401 ) -> dict: |
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:
1575
diff
changeset
|
402 """Send a file using jingle file transfer |
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:
1575
diff
changeset
|
403 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
404 @param peer_jid: destinee jid |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
405 @param filepath: absolute path of the file |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
406 @param name: name of the file |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
407 @param file_desc: description of the file |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
408 @return: progress id |
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:
1575
diff
changeset
|
409 """ |
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:
1575
diff
changeset
|
410 progress_id_d = defer.Deferred() |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
411 if extra is None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
412 extra = {} |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
413 if file_desc is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
414 extra["file_desc"] = file_desc |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
415 encrypted = extra.pop("encrypted", False) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
416 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
417 content = { |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
418 "app_ns": NS_JINGLE_FT, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
419 "senders": self._j.ROLE_INITIATOR, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
420 "app_kwargs": { |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
421 "filepath": filepath, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
422 "name": name, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
423 "extra": extra, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
424 "progress_id_d": progress_id_d, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
425 }, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
426 } |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
427 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
428 await self.host.trigger.async_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
429 "XEP-0234_file_jingle_send", client, peer_jid, content |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
430 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
431 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
432 session_id = await self._j.initiate( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
433 client, peer_jid, [content], encrypted=encrypted |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
434 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
435 progress_id = await progress_id_d |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
436 return {"progress": progress_id, "session_id": session_id} |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
437 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
438 def _file_jingle_request( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
439 self, |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
440 peer_jid: str, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
441 filepath: str, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
442 name: str = "", |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
443 file_hash: str = "", |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
444 hash_algo: str = "", |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
445 extra: dict | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
446 profile: str = C.PROF_KEY_NONE, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
447 ) -> defer.Deferred[str]: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
448 client = self.host.get_client(profile) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
449 return defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
450 self.file_jingle_request( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
451 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
452 jid.JID(peer_jid), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
453 filepath, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
454 name or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
455 file_hash or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
456 hash_algo or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
457 extra or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
458 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
459 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
460 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
461 async def file_jingle_request( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
462 self, |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
463 client: SatXMPPEntity, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
464 peer_jid: jid.JID, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
465 filepath: str, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
466 name: str | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
467 file_hash: str | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
468 hash_algo: str | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
469 extra: dict | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
470 ) -> str: |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
471 """Request a file using jingle file transfer |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
472 |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
473 @param client: Profile session. |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
474 @param peer_jid: destinee jid |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
475 @param filepath: absolute path where the file will be downloaded |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
476 @param name: name of the file |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
477 @param file_hash: hash of the file |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
478 @return: progress id |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
479 """ |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
480 progress_id_d = defer.Deferred() |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
481 if extra is None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
482 extra = {} |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
483 if file_hash is not None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
484 if hash_algo is None: |
3028 | 485 raise ValueError(_("hash_algo must be set if file_hash is set")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
486 extra["file_hash"] = file_hash |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
487 extra["hash_algo"] = hash_algo |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
488 else: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
489 if hash_algo is not None: |
3028 | 490 raise ValueError(_("file_hash must be set if hash_algo is set")) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
491 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
492 content = { |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
493 "app_ns": NS_JINGLE_FT, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
494 "senders": self._j.ROLE_RESPONDER, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
495 "app_kwargs": { |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
496 "filepath": filepath, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
497 "name": name, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
498 "extra": extra, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
499 "progress_id_d": progress_id_d, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
500 }, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
501 } |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
502 |
3434
c84c54c6b046
plugin XEP-0234: make `fileJingleRequest` async to fix call of `initiate`
Goffi <goffi@goffi.org>
parents:
3404
diff
changeset
|
503 await self._j.initiate( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
504 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
505 peer_jid, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
506 [content], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
507 ) |
3434
c84c54c6b046
plugin XEP-0234: make `fileJingleRequest` async to fix call of `initiate`
Goffi <goffi@goffi.org>
parents:
3404
diff
changeset
|
508 return await progress_id_d |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 # jingle callbacks |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
512 def _get_confirm_msg( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
513 self, client: SatXMPPEntity, peer_jid: jid.JID, file_data: dict |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
514 ) -> tuple[bool, str, str]: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
515 """Get confirmation message to display to user. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
516 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
517 This is the message to show when a file sending request is received.""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
518 file_name = file_data.get("name") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
519 file_size = file_data.get("size") |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
520 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
521 if file_name: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
522 file_name_msg = D_('wants to send you the file "{file_name}"').format( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
523 file_name=file_name |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
524 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
525 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
526 file_name_msg = D_("wants to send you an unnamed file") |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
527 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
528 if file_size is not None: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
529 file_size_msg = D_("which has a size of {file_size_human}").format( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
530 file_size_human=get_human_size(file_size) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
531 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
532 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
533 file_size_msg = D_("which has an unknown size") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
534 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
535 file_description = file_data.get("desc") |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
536 if file_description: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
537 description_msg = " Description: {}.".format(file_description) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
538 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
539 description_msg = "" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
540 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
541 if client.roster and peer_jid.userhostJID() not in client.roster: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
542 is_in_roster = False |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
543 confirm_msg = D_( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
544 "Somebody not in your contact list ({peer_jid}) {file_name_msg} {file_size_msg}.{description_msg} " |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
545 "Accepting this could leak your presence and possibly your IP address. Do you accept?" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
546 ).format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
547 peer_jid=peer_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
548 file_name_msg=file_name_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
549 file_size_msg=file_size_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
550 description_msg=description_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
551 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
552 confirm_title = D_("File sent from an unknown contact") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
553 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
554 is_in_roster = True |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
555 confirm_msg = D_( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
556 "{peer_jid} {file_name_msg} {file_size_msg}.{description_msg} Do you " |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
557 "accept?" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
558 ).format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
559 peer_jid=peer_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
560 file_name_msg=file_name_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
561 file_size_msg=file_size_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
562 description_msg=description_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
563 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
564 confirm_title = D_("File Proposed") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
565 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
566 return (is_in_roster, confirm_msg, confirm_title) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
567 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
568 async def jingle_preflight( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
569 self, client: SatXMPPEntity, session: dict, description_elt: domish.Element |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
570 ) -> None: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
571 """Perform preflight checks for an incoming call session. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
572 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
573 Check if the calls is audio only or audio/video, then, prompts the user for |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
574 confirmation. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
575 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
576 @param client: The client instance. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
577 @param session: Jingle session. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
578 @param description_elt: The description element. It's parent attribute is used to |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
579 determine check siblings to see if it's an audio only or audio/video call. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
580 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
581 @raises exceptions.CancelError: If the user doesn't accept the incoming call. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
582 """ |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
583 session_id = session["id"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
584 peer_jid = session["peer_jid"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
585 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
586 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
587 file_elt = next(description_elt.elements(NS_JINGLE_FT, "file")) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
588 except StopIteration: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
589 file_data = {} |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
590 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
591 file_data = await self.parse_file_element(client, file_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
592 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
593 is_in_roster, confirm_msg, confirm_title = self._get_confirm_msg( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
594 client, peer_jid, file_data |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
595 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
596 if is_in_roster: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
597 action_type = C.META_TYPE_CONFIRM |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
598 else: |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
599 action_type = C.META_TYPE_NOT_IN_ROSTER_LEAK |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
600 |
4220
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
601 action_extra = { |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
602 "type": action_type, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
603 "session_id": session_id, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
604 "from_jid": peer_jid.full(), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
605 "file_data": file_data, |
4220
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
606 } |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
607 action_extra["subtype"] = C.META_TYPE_FILE |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
608 accepted = await xml_tools.defer_confirm( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
609 self.host, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
610 confirm_msg, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
611 confirm_title, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
612 profile=client.profile, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
613 action_extra=action_extra, |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
614 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
615 if accepted: |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
616 session["pre_accepted"] = True |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
617 return accepted |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
618 |
4115
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
619 async def jingle_preflight_info( |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
620 self, |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
621 client: SatXMPPEntity, |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
622 session: dict, |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
623 info_type: str, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
624 info_data: dict | None = None, |
4115
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
625 ) -> None: |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
626 pass |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
627 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
628 async def jingle_preflight_cancel( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
629 self, client: SatXMPPEntity, session: dict, cancel_error: exceptions.CancelError |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
630 ) -> None: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
631 pass |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
632 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
633 def jingle_description_elt( |
3404
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3403
diff
changeset
|
634 self, client, session, content_name, filepath, name, extra, progress_id_d |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3403
diff
changeset
|
635 ): |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3403
diff
changeset
|
636 return domish.Element((NS_JINGLE_FT, "description")) |
26a0af6e32c1
plugin XEP-0166: new trigger point + coroutines + helper methods:
Goffi <goffi@goffi.org>
parents:
3403
diff
changeset
|
637 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
638 def jingle_session_init( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
639 self, client, session, content_name, filepath, name, extra, progress_id_d |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
640 ): |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
641 if extra is None: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
642 extra = {} |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
643 else: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
644 if not EXTRA_ALLOWED.issuperset(extra): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
645 raise ValueError( |
3028 | 646 _("only the following keys are allowed in extra: {keys}").format( |
647 keys=", ".join(EXTRA_ALLOWED) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
648 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
649 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
650 progress_id_d.callback(self.get_progress_id(session, content_name)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
651 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
652 application_data = content_data["application_data"] |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
653 if extra.get("webrtc"): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
654 transport_data = content_data["transport_data"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
655 transport_data["webrtc"] = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
656 assert "file_path" not in application_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
657 application_data["file_path"] = filepath |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
658 file_data = application_data["file_data"] = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
659 desc_elt = self.jingle_description_elt( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
660 client, session, content_name, filepath, name, extra, progress_id_d |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
661 ) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 file_elt = desc_elt.addElement("file") |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
663 |
3028 | 664 if content_data["senders"] == self._j.ROLE_INITIATOR: |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
665 # we send a file |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
666 if name is None: |
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
667 name = os.path.basename(filepath) |
3028 | 668 file_data["date"] = utils.xmpp_date() |
669 file_data["desc"] = extra.pop("file_desc", "") | |
670 file_data["name"] = name | |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
671 mime_type = ( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
672 file_data.get("media_type") or mimetypes.guess_type(name, strict=False)[0] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
673 ) |
2512
025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents:
2502
diff
changeset
|
674 if mime_type is not None: |
3028 | 675 file_data["mime_type"] = mime_type |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
676 size = extra.pop("size", None) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
677 if size is None: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
678 size = os.path.getsize(filepath) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
679 file_data["size"] = size |
3028 | 680 if "namespace" in extra: |
681 file_data["namespace"] = extra["namespace"] | |
682 if "path" in extra: | |
683 file_data["path"] = extra["path"] | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
684 self.build_file_element_from_dict( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
685 client, file_data, file_elt=file_elt, file_hash="" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
686 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
687 else: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
688 # we request a file |
3028 | 689 file_hash = extra.pop("file_hash", "") |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
690 if not name and not file_hash: |
3028 | 691 raise ValueError(_("you need to provide at least name or file hash")) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
692 if name: |
3028 | 693 file_data["name"] = name |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
694 if file_hash: |
3028 | 695 file_data["file_hash"] = file_hash |
696 file_data["hash_algo"] = extra["hash_algo"] | |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
697 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
698 file_data["hash_algo"] = self._hash.get_default_algo() |
3028 | 699 if "namespace" in extra: |
700 file_data["namespace"] = extra["namespace"] | |
701 if "path" in extra: | |
702 file_data["path"] = extra["path"] | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
703 self.build_file_element_from_dict(client, file_data, file_elt=file_elt) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
704 |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 return desc_elt |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
706 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
707 async def jingle_request_confirmation( |
4220
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
708 self, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
709 client: SatXMPPEntity, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
710 action: str, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
711 session: dict, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
712 content_name: str, |
5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
713 desc_elt: domish.Element, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
714 ) -> bool: |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
715 """This method request confirmation for a jingle session""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
716 content_data = session["contents"][content_name] |
3028 | 717 senders = content_data["senders"] |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
718 if senders not in (self._j.ROLE_INITIATOR, self._j.ROLE_RESPONDER): |
3028 | 719 log.warning("Bad sender, assuming initiator") |
720 senders = content_data["senders"] = self._j.ROLE_INITIATOR | |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
721 # first we grab file informations |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
722 try: |
3028 | 723 file_elt = next(desc_elt.elements(NS_JINGLE_FT, "file")) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
724 except StopIteration: |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
725 raise failure.Failure(exceptions.DataError) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
726 file_data = {"progress_id": self.get_progress_id(session, content_name)} |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
727 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
728 if senders == self._j.ROLE_RESPONDER: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
729 # we send the file |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
730 return await self._file_sending_request_conf( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
731 client, session, content_data, content_name, file_data, file_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
732 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
733 else: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
734 # we receive the file |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
735 return await self._file_receiving_request_conf( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
736 client, session, content_data, content_name, file_data, file_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
737 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
738 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
739 async def _file_sending_request_conf( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
740 self, client, session, content_data, content_name, file_data, file_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
741 ): |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
742 """parse file_elt, and handle file retrieving/permission checking""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
743 await self.parse_file_element(client, file_elt, file_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
744 content_data["application_data"]["file_data"] = file_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
745 finished_d = content_data["finished_d"] = defer.Deferred() |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
746 |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
747 # confirmed_d is a deferred returning confimed value (only used if cont is False) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
748 cont, confirmed_d = self.host.trigger.return_point( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
749 "XEP-0234_fileSendingRequest", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
750 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
751 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
752 content_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
753 content_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
754 file_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
755 file_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
756 ) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
757 if not cont: |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
758 confirmed = await confirmed_d |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
759 if confirmed: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
760 args = [client, session, content_name, content_data] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
761 finished_d.addCallbacks( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
762 self._finished_cb, self._finished_eb, args, None, args |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
763 ) |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
764 return confirmed |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
765 |
3028 | 766 log.warning(_("File continue is not implemented yet")) |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
767 return False |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
768 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
769 async def _file_receiving_request_conf( |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
770 self, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
771 client: SatXMPPEntity, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
772 session: dict, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
773 content_data: dict, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
774 content_name: str, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
775 file_data: dict, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
776 file_elt: domish.Element, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
777 ) -> bool: |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
778 """parse file_elt, and handle user permission/file opening""" |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
779 transport_data = content_data["transport_data"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
780 webrtc = transport_data.get("webrtc", False) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
781 # file may have been already accepted in preflight |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
782 pre_accepted = session.get("pre_accepted", False) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
783 file_data = await self.parse_file_element(client, file_elt, file_data, given=True) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
784 # FIXME: looks redundant with code done in self.parse_file_element |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
785 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
786 hash_algo, file_data["given_file_hash"] = self._hash.parse_hash_elt(file_elt) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
787 except exceptions.NotFound: |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
788 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
789 hash_algo = self._hash.parse_hash_used_elt(file_elt) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
790 except exceptions.NotFound: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
791 raise failure.Failure(exceptions.DataError) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
792 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
793 # deferred to track end of transfer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
794 finished_d = content_data["finished_d"] = defer.Deferred() |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
795 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
796 if webrtc: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
797 peer_jid = session["peer_jid"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
798 __, confirm_msg, confirm_title = self._get_confirm_msg( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
799 client, peer_jid, file_data |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
800 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
801 action_extra = { |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
802 "webrtc": webrtc, |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
803 "pre_accepted": pre_accepted, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
804 "type": C.META_TYPE_FILE, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
805 "session_id": session["id"], |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
806 "from_jid": peer_jid.full(), |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
807 "file_data": file_data, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
808 "progress_id": file_data["progress_id"], |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
809 } |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
810 # we need a confirm dialog here and not a file dialog, as the file handling is |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
811 # managed by the frontends with webRTC. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
812 confirmed = await xml_tools.defer_confirm( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
813 self.host, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
814 confirm_msg, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
815 confirm_title, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
816 profile=client.profile, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
817 action_extra=action_extra, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
818 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
819 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
820 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
821 if hash_algo is not None: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
822 file_data["hash_algo"] = hash_algo |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
823 file_data["hash_hasher"] = hasher = self._hash.get_hasher(hash_algo) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
824 file_data["data_cb"] = lambda data: hasher.update(data) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
825 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
826 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
827 file_data["size"] = int(file_data["size"]) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
828 except ValueError: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
829 raise failure.Failure(exceptions.DataError) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
830 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
831 content_data["application_data"]["file_data"] = file_data |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
832 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
833 # now we actualy request permission to user |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
834 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
835 confirmed = await self._f.get_dest_dir( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
836 client, session["peer_jid"], content_data, file_data, stream_object=True |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
837 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
838 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
839 if confirmed: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
840 await self.host.trigger.async_point( |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
841 "XEP-0234_file_receiving_request_conf", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
842 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
843 session, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
844 content_data, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
845 file_elt, |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
846 ) |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
847 args = [client, session, content_name, content_data] |
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
848 finished_d.addCallbacks( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
849 self._finished_cb, self._finished_eb, args, None, args |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
850 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
851 |
3333
ac9342f359e9
plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
852 return confirmed |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
853 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
854 async def jingle_handler(self, client, action, session, content_name, desc_elt): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
855 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
856 application_data = content_data["application_data"] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1529
diff
changeset
|
857 if action in (self._j.A_ACCEPTED_ACK,): |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
858 pass |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1529
diff
changeset
|
859 elif action == self._j.A_SESSION_INITIATE: |
3028 | 860 file_elt = next(desc_elt.elements(NS_JINGLE_FT, "file")) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1529
diff
changeset
|
861 try: |
3028 | 862 next(file_elt.elements(NS_JINGLE_FT, "range")) |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1529
diff
changeset
|
863 except StopIteration: |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1529
diff
changeset
|
864 # initiator doesn't manage <range>, but we do so we advertise it |
3040 | 865 # FIXME: to be checked |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1529
diff
changeset
|
866 log.debug("adding <range> element") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
867 file_elt.addElement("range") |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
868 elif action == self._j.A_SESSION_ACCEPT: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
869 assert not "stream_object" in content_data |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
870 transport_data = content_data["transport_data"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
871 if transport_data.get("webrtc"): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
872 # WebRTC case is special, the file is transfered by the frontend |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
873 # implementation directly, there is nothing done in backend. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
874 log.debug( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
875 "We're using WebRTC datachannel, the frontend handles it from now on." |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
876 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
877 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
878 file_data = application_data["file_data"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
879 file_path = application_data["file_path"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
880 senders = content_data["senders"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
881 if senders != session["role"]: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
882 # we are receiving the file |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
883 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
884 # did the responder specified the size of the file? |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
885 file_elt = next(desc_elt.elements(NS_JINGLE_FT, "file")) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
886 size_elt = next(file_elt.elements(NS_JINGLE_FT, "size")) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
887 size = int(str(size_elt)) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
888 except (StopIteration, ValueError): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
889 size = None |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
890 # XXX: hash security is not critical here, so we just take the higher |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
891 # mandatory one |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
892 hasher = file_data["hash_hasher"] = self._hash.get_hasher() |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
893 progress_id = self.get_progress_id(session, content_name) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
894 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
895 content_data["stream_object"] = stream.FileStreamObject( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
896 self.host, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
897 client, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
898 file_path, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
899 mode="wb", |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
900 uid=progress_id, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
901 size=size, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
902 data_cb=lambda data: hasher.update(data), |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
903 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
904 except Exception as e: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
905 self.host.bridge.progress_error( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
906 progress_id, C.PROGRESS_ERROR_FAILED, client.profile |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
907 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
908 await self._j.terminate( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
909 client, self._j.REASON_FAILED_APPLICATION, session |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
910 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
911 raise e |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
912 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
913 # we are sending the file |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
914 size = file_data["size"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
915 # XXX: hash security is not critical here, so we just take the higher |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
916 # mandatory one |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
917 hasher = file_data["hash_hasher"] = self._hash.get_hasher() |
3040 | 918 content_data["stream_object"] = stream.FileStreamObject( |
919 self.host, | |
920 client, | |
921 file_path, | |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
922 uid=self.get_progress_id(session, content_name), |
3040 | 923 size=size, |
924 data_cb=lambda data: hasher.update(data), | |
925 ) | |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4220
diff
changeset
|
926 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
927 finished_d = content_data["finished_d"] = defer.Deferred() |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
928 args = [client, session, content_name, content_data] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
929 finished_d.addCallbacks( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
930 self._finished_cb, self._finished_eb, args, None, args |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
931 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
932 await self.host.trigger.async_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
933 "XEP-0234_jingle_handler", client, session, content_data, desc_elt |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
934 ) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
935 else: |
3028 | 936 log.warning("FIXME: unmanaged action {}".format(action)) |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
937 return desc_elt |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
938 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
939 def jingle_session_info(self, client, action, session, content_name, jingle_elt): |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
940 """Called on session-info action |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
941 |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
942 manage checksum, and ignore <received/> element |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
943 """ |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
944 # TODO: manage <received/> element |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
945 content_data = session["contents"][content_name] |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
946 elts = [elt for elt in jingle_elt.elements() if elt.uri == NS_JINGLE_FT] |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
947 if not elts: |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
948 return |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
949 for elt in elts: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
950 if elt.name == "received": |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
951 pass |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
952 elif elt.name == "checksum": |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
953 # we have received the file hash, we need to parse it |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
954 if content_data["senders"] == session["role"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
955 log.warning( |
3028 | 956 "unexpected checksum received while we are the file sender" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
957 ) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
958 raise exceptions.DataError |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
959 info_content_name = elt["name"] |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
960 if info_content_name != content_name: |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
961 # it was for an other content... |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
962 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
963 file_data = content_data["application_data"]["file_data"] |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
964 try: |
3859
3ef988734869
core: fix calls to `domish.Element.elements`:
Goffi <goffi@goffi.org>
parents:
3527
diff
changeset
|
965 file_elt = next(elt.elements(NS_JINGLE_FT, "file")) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
966 except StopIteration: |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
967 raise exceptions.DataError |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
968 algo, file_data["given_file_hash"] = self._hash.parse_hash_elt(file_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
969 if algo != file_data.get("hash_algo"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
970 log.warning( |
3028 | 971 "Hash algorithm used in given hash ({peer_algo}) doesn't correspond to the one we have used ({our_algo}) [{profile}]".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
972 peer_algo=algo, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
973 our_algo=file_data.get("hash_algo"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
974 profile=client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
975 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
976 ) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
977 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
978 self._receiver_try_terminate( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
979 client, session, content_name, content_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
980 ) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
981 else: |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
982 raise NotImplementedError |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
983 |
4052
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
984 def jingle_terminate(self, client, action, session, content_name, reason_elt): |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
985 if reason_elt.decline: |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
986 # progress is the only way to tell to frontends that session has been declined |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
987 progress_id = self.get_progress_id(session, content_name) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
988 self.host.bridge.progress_error( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
989 progress_id, C.PROGRESS_ERROR_DECLINED, client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
990 ) |
4052
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
991 elif not reason_elt.success: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
992 progress_id = self.get_progress_id(session, content_name) |
4052
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
993 first_child = reason_elt.firstChildElement() |
3040 | 994 if first_child is not None: |
995 reason = first_child.name | |
4052
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
996 if reason_elt.text is not None: |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
997 reason = f"{reason} - {reason_elt.text}" |
3040 | 998 else: |
999 reason = C.PROGRESS_ERROR_FAILED | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
1000 self.host.bridge.progress_error(progress_id, reason, client.profile) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1001 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1002 def _send_check_sum(self, client, session, content_name, content_data): |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1003 """Send the session-info with the hash checksum""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1004 file_data = content_data["application_data"]["file_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1005 hasher = file_data["hash_hasher"] |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1006 hash_ = hasher.hexdigest() |
3028 | 1007 log.debug("Calculated hash: {}".format(hash_)) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1008 iq_elt, jingle_elt = self._j.build_session_info(client, session) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1009 checksum_elt = jingle_elt.addElement((NS_JINGLE_FT, "checksum")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1010 checksum_elt["creator"] = content_data["creator"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1011 checksum_elt["name"] = content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1012 file_elt = checksum_elt.addElement("file") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1013 file_elt.addChild(self._hash.build_hash_elt(hash_)) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1014 iq_elt.send() |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1015 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1016 def _receiver_try_terminate( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1017 self, client, session, content_name, content_data, last_try=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1018 ): |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1019 """Try to terminate the session |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1020 |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1021 This method must only be used by the receiver. |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1022 It check if transfer is finished, and hash available, |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1023 if everything is OK, it check hash and terminate the session |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1024 @param last_try(bool): if True this mean than session must be terminated even given hash is not available |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1025 @return (bool): True if session was terminated |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1026 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1027 if not content_data.get("transfer_finished", False): |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1028 return False |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1029 file_data = content_data["application_data"]["file_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1030 given_hash = file_data.get("given_file_hash") |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1031 if given_hash is None: |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1032 if last_try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1033 log.warning( |
3028 | 1034 "sender didn't sent hash checksum, we can't check the file [{profile}]".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1035 profile=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1036 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1037 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1038 self._j.delayed_content_terminate(client, session, content_name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1039 content_data["stream_object"].close() |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1040 return True |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1041 return False |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1042 hasher = file_data["hash_hasher"] |
3040 | 1043 hash_ = hasher.hexdigest() |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1044 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1045 if hash_ == given_hash: |
3040 | 1046 log.info(f"Hash checked, file was successfully transfered: {hash_}") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1047 progress_metadata = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1048 "hash": hash_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1049 "hash_algo": file_data["hash_algo"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1050 "hash_verified": C.BOOL_TRUE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1051 } |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
1052 error = None |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1053 else: |
3028 | 1054 log.warning("Hash mismatch, the file was not transfered correctly") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1055 progress_metadata = None |
3028 | 1056 error = "Hash mismatch: given={algo}:{given}, calculated={algo}:{our}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1057 algo=file_data["hash_algo"], given=given_hash, our=hash_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1058 ) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1059 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1060 self._j.delayed_content_terminate(client, session, content_name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1061 content_data["stream_object"].close(progress_metadata, error) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1062 # we may have the last_try timer still active, so we try to cancel it |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1063 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1064 content_data["last_try_timer"].cancel() |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1065 except (KeyError, internet_error.AlreadyCalled): |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1066 pass |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1067 return True |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1068 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1069 def _finished_cb(self, __, client, session, content_name, content_data): |
3028 | 1070 log.info("File transfer terminated") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1071 if content_data["senders"] != session["role"]: |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1072 # we terminate the session only if we are the receiver, |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
1073 # as recommanded in XEP-0234 §2 (after example 6) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1074 content_data["transfer_finished"] = True |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1075 if not self._receiver_try_terminate( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1076 client, session, content_name, content_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1077 ): |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1078 # we have not received the hash yet, we wait 5 more seconds |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1079 content_data["last_try_timer"] = reactor.callLater( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1080 5, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1081 self._receiver_try_terminate, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1082 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1083 session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1084 content_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1085 content_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1086 last_try=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1087 ) |
1620
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1088 else: |
4dd07d026214
plugin XEP-0234: hash checksum proper handling
Goffi <goffi@goffi.org>
parents:
1618
diff
changeset
|
1089 # we are the sender, we send the checksum |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1090 self._send_check_sum(client, session, content_name, content_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1091 content_data["stream_object"].close() |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
1092 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1093 def _finished_eb(self, failure, client, session, content_name, content_data): |
3028 | 1094 log.warning("Error while streaming file: {}".format(failure)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1095 content_data["stream_object"].close() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
1096 self._j.content_terminate( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1097 client, session, content_name, reason=self._j.REASON_FAILED_TRANSPORT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1098 ) |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
1099 |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1100 |
3028 | 1101 @implementer(iwokkel.IDisco) |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1102 class XEP_0234_handler(XMPPHandler): |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1103 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1104 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1105 return [disco.DiscoFeature(NS_JINGLE_FT)] |
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1106 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1107 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
1528
1c71d7335d02
plugin XEP-0234: jingle file transfer first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1108 return [] |