Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0096.py @ 2000:d64e9c3dc6e3
Added tag 0.6.1 for changeset 30e83614af48
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 12 Jul 2016 23:43:37 +0200 |
parents | 2daf7b4c6756 |
children | b99bd02ea643 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1899
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 2 # -*- coding: utf-8 -*- |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing xep-0096 |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
771 | 20 from sat.core.i18n import _ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
22 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
23 log = getLogger(__name__) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
24 from sat.core import exceptions |
0 | 25 from twisted.words.xish import domish |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
26 from twisted.words.protocols.jabber import jid |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
27 from twisted.words.protocols.jabber import error |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
28 import os |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
29 |
0 | 30 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
31 NS_SI_FT = "http://jabber.org/protocol/si/profile/file-transfer" |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
32 IQ_SET = '/iq[@type="set"]' |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
33 SI_PROFILE_NAME = "file-transfer" |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
34 SI_PROFILE = "http://jabber.org/protocol/si/profile/" + SI_PROFILE_NAME |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
35 |
0 | 36 PLUGIN_INFO = { |
721
0077912bc9ba
jp: removed named argument for pipeOut, as it's not managed with dynamicaly added methods
Goffi <goffi@goffi.org>
parents:
638
diff
changeset
|
37 "name": "XEP-0096 Plugin", |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
38 "import_name": "XEP-0096", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
39 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 "protocols": ["XEP-0096"], |
1899
7c97554a84d5
plugin XEP-0096: add missing dependency to FILE plugin
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
41 "dependencies": ["XEP-0020", "XEP-0095", "XEP-0065", "XEP-0047", "FILE"], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
42 "main": "XEP_0096", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
43 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
44 "description": _("""Implementation of SI File Transfer""") |
0 | 45 } |
46 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
48 class XEP_0096(object): |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
49 # TODO: call self._f.unregister when unloading order will be managing (i.e. when depenencies will be unloaded at the end) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
50 |
0 | 51 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
52 log.info(_("Plugin XEP_0096 initialization")) |
0 | 53 self.host = host |
540
47e45a577ab7
plugin XEP-0096: restored XEP-0065 usage
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
54 self.managed_stream_m = [self.host.plugins["XEP-0065"].NAMESPACE, |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
55 self.host.plugins["XEP-0047"].NAMESPACE] # Stream methods managed |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
56 self._f = self.host.plugins["FILE"] |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
57 self._f.register(NS_SI_FT, self.sendFile, priority=0, method_name=u"Stream Initiation") |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
58 self._si = self.host.plugins["XEP-0095"] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
59 self._si.registerSIProfile(SI_PROFILE_NAME, self._transferRequest) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
60 host.bridge.addMethod("siSendFile", ".plugin", in_sign='sssss', out_sign='s', method=self._sendFile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
61 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
62 def unload(self): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
63 self._si.unregisterSIProfile(SI_PROFILE_NAME) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
64 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
65 def _badRequest(self, iq_elt, message=None, profile=C.PROF_KEY_NONE): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
66 """Send a bad-request error |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
67 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
68 @param iq_elt(domish.Element): initial <IQ> element of the SI request |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
69 @param message(None, unicode): informational message to display in the logs |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
70 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
71 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
72 if message is not None: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
73 log.warning(message) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
74 self._si.sendError(iq_elt, 'bad-request', profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
75 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
76 def _parseRange(self, parent_elt, file_size): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
77 """find and parse <range/> element |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
78 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
79 @param parent_elt(domish.Element): direct parent of the <range/> element |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
80 @return (tuple[bool, int, int]): a tuple with |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
81 - True if range is required |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
82 - range_offset |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
83 - range_length |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
84 """ |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
85 try: |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
86 range_elt = parent_elt.elements(NS_SI_FT, 'range').next() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
87 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
88 range_ = False |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
89 range_offset = None |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
90 range_length = None |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
91 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
92 range_ = True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
93 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
94 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
95 range_offset = int(range_elt['offset']) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
96 except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
97 range_offset = 0 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
98 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
99 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
100 range_length = int(range_elt['length']) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
101 except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
102 range_length = file_size |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
103 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
104 if range_offset != 0 or range_length != file_size: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
105 raise NotImplementedError # FIXME |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
106 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
107 return range_, range_offset, range_length |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
108 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
109 def _transferRequest(self, iq_elt, si_id, si_mime_type, si_elt, profile): |
391 | 110 """Called when a file transfer is requested |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
111 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
112 @param iq_elt(domish.Element): initial <IQ> element of the SI request |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
113 @param si_id(unicode): Stream Initiation session id |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
114 @param si_mime_type("unicode"): Mime type of the file (or default "application/octet-stream" if unknown) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
115 @param si_elt(domish.Element): request |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
116 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
117 """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
118 log.info(_("XEP-0096 file transfer requested")) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
119 peer_jid = jid.JID(iq_elt['from']) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
120 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
121 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
122 file_elt = si_elt.elements(NS_SI_FT, "file").next() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
123 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
124 return self._badRequest(iq_elt, "No <file/> element found in SI File Transfer request", profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
125 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
126 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
127 feature_elt = self.host.plugins["XEP-0020"].getFeatureElt(si_elt) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
128 except exceptions.NotFound: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
129 return self._badRequest(iq_elt, "No <feature/> element found in SI File Transfer request", profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
130 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
131 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
132 filename = file_elt["name"] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
133 file_size = int(file_elt["size"]) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
134 except (KeyError, ValueError): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
135 return self._badRequest(iq_elt, "Malformed SI File Transfer request", profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
136 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
137 file_date = file_elt.getAttribute("date") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
138 file_hash = file_elt.getAttribute("hash") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
139 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
140 log.info(u"File proposed: name=[{name}] size={size}".format(name=filename, size=file_size)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
141 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
142 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
143 file_desc = unicode(file_elt.elements(NS_SI_FT, 'desc').next()) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
144 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
145 file_desc = '' |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
146 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
147 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
148 range_, range_offset, range_length = self._parseRange(file_elt, file_size) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
149 except ValueError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
150 return self._badRequest(iq_elt, "Malformed SI File Transfer request", profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
151 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
152 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
153 stream_method = self.host.plugins["XEP-0020"].negotiate(feature_elt, 'stream-method', self.managed_stream_m, namespace=None) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
154 except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
155 return self._badRequest(iq_elt, "No stream method found", profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
156 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
157 if stream_method: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
158 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
159 plugin = self.host.plugins["XEP-0065"] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
160 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
161 plugin = self.host.plugins["XEP-0047"] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
162 else: |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
163 log.error(u"Unknown stream method, this should not happen at this stage, cancelling transfer") |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
164 else: |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
165 log.warning(u"Can't find a valid stream method") |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
166 self._si.sendError(iq_elt, 'not-acceptable', profile) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
167 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
168 |
391 | 169 #if we are here, the transfer can start, we just need user's agreement |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
170 data = {"name": filename, "peer_jid": peer_jid, "size": file_size, "date": file_date, "hash": file_hash, "desc": file_desc, |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
171 "range": range_, "range_offset": range_offset, "range_length": range_length, |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
172 "si_id": si_id, "progress_id": si_id, "stream_method": stream_method, "stream_plugin": plugin} |
0 | 173 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
174 d = self._f.getDestDir(peer_jid, data, data, profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
175 d.addCallback(self.confirmationCb, iq_elt, data, profile) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
176 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
177 def _getFileObject(self, dest_path, can_range=False): |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
178 """Open file, put file pointer to the end if the file if needed |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
179 @param dest_path: path of the destination file |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
180 @param can_range: True if the file pointer can be moved |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
181 @return: File Object""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
182 return open(dest_path, "ab" if can_range else "wb") |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
183 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
184 def confirmationCb(self, accepted, iq_elt, data, profile): |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
185 """Called on confirmation answer |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
186 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
187 @param accepted(bool): True if file transfer is accepted |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
188 @param iq_elt(domish.Element): initial SI request |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
189 @param data(dict): session data |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
190 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
191 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
192 if not accepted: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
193 log.info(u"File transfer declined") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
194 self._si.sendError(iq_elt, 'forbidden', profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
195 return |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
196 # data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
197 # can_range = data['can_range'] == "True" |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
198 # range_offset = 0 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
199 # if timeout.active(): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
200 # timeout.cancel() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
201 # try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
202 # dest_path = frontend_data['dest_path'] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
203 # except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
204 # log.error(_('dest path not found in frontend_data')) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
205 # del client._xep_0096_waiting_for_approval[sid] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
206 # return |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
207 # if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
208 # plugin = self.host.plugins["XEP-0065"] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
209 # elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
210 # plugin = self.host.plugins["XEP-0047"] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
211 # else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
212 # log.error(_("Unknown stream method, this should not happen at this stage, cancelling transfer")) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
213 # del client._xep_0096_waiting_for_approval[sid] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
214 # return |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
215 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
216 # file_obj = self._getFileObject(dest_path, can_range) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
217 # range_offset = file_obj.tell() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
218 d = data['stream_plugin'].createSession(data['file_obj'], data['peer_jid'], data['si_id'], profile=profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
219 d.addCallback(self._transferCb, data, profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
220 d.addErrback(self._transferEb, data, profile) |
0 | 221 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
222 #we can send the iq result |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
223 feature_elt = self.host.plugins["XEP-0020"].chooseOption({'stream-method': data['stream_method']}, namespace=None) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
224 misc_elts = [] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
225 misc_elts.append(domish.Element((SI_PROFILE, "file"))) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
226 # if can_range: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
227 # range_elt = domish.Element((None, "range")) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
228 # range_elt['offset'] = str(range_offset) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
229 # #TODO: manage range length |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
230 # misc_elts.append(range_elt) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
231 self._si.acceptStream(iq_elt, feature_elt, misc_elts, profile) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
232 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
233 def _transferCb(self, dummy, data, profile): |
391 | 234 """Called by the stream method when transfer successfuly finished |
0 | 235 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
236 @param data: session data |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
237 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
238 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
239 #TODO: check hash |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
240 data['file_obj'].close() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
241 log.info(u'Transfer {si_id} successfuly finished'.format(**data)) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
242 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
243 def _transferEb(self, failure, data, profile): |
391 | 244 """Called when something went wrong with the transfer |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
245 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
246 @param id: stream id |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
247 @param data: session data |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
248 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
249 """ |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
250 log.warning(u'Transfer {si_id} failed: {reason}'.format(reason=unicode(failure.value), **data)) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
251 data['file_obj'].close() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
252 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
253 def _sendFile(self, peer_jid_s, filepath, name, desc, profile=C.PROF_KEY_NONE): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
254 return self.sendFile(jid.JID(peer_jid_s), filepath, name or None, desc or None, profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
255 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
256 def sendFile(self, peer_jid, filepath, name=None, desc=None, profile=C.PROF_KEY_NONE): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
257 """Send a file using XEP-0096 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
258 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
259 @param peer_jid(jid.JID): recipient |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
260 @param filepath(str): absolute path to the file to send |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
261 @param name(unicode): name of the file to send |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
262 name must not contain "/" characters |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
263 @param desc: description of the file |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
264 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
265 @return: an unique id to identify the transfer |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
266 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
267 client = self.host.getClient(profile) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
268 feature_elt = self.host.plugins["XEP-0020"].proposeFeatures({'stream-method': self.managed_stream_m}, namespace=None) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
269 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
270 file_transfer_elts = [] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
271 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
272 statinfo = os.stat(filepath) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
273 file_elt = domish.Element((SI_PROFILE, 'file')) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
274 file_elt['name'] = name or os.path.basename(filepath) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
275 assert '/' not in file_elt['name'] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
276 size = statinfo.st_size |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
277 file_elt['size'] = str(size) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
278 if desc: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
279 file_elt.addElement('desc', content=desc) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
280 file_transfer_elts.append(file_elt) |
0 | 281 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
282 file_transfer_elts.append(domish.Element((None, 'range'))) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
283 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
284 sid, offer_d = self._si.proposeStream(peer_jid, SI_PROFILE, feature_elt, file_transfer_elts, profile=client.profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
285 args = [filepath, sid, size, client] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
286 offer_d.addCallbacks(self._fileCb, self._fileEb, args, None, args) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
287 return sid |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
288 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
289 def _fileCb(self, result_tuple, filepath, sid, size, client): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
290 iq_elt, si_elt = result_tuple |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
291 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
292 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
293 feature_elt = self.host.plugins["XEP-0020"].getFeatureElt(si_elt) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
294 except exceptions.NotFound: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
295 log.warning(u"No <feature/> element found in result while expected") |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
296 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
297 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
298 choosed_options = self.host.plugins["XEP-0020"].getChoosedOptions(feature_elt, namespace=None) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
299 try: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
300 stream_method = choosed_options["stream-method"] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
301 except KeyError: |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
302 log.warning(u"No stream method choosed") |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
303 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
304 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
305 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
306 file_elt = si_elt.elements(NS_SI_FT, "file").next() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
307 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
308 pass |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
309 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
310 range_, range_offset, range_length = self._parseRange(file_elt, size) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
311 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
312 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
313 plugin = self.host.plugins["XEP-0065"] |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
314 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
315 plugin = self.host.plugins["XEP-0047"] |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
316 else: |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
317 log.warning(u"Invalid stream method received") |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
318 return |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
319 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
320 file_obj = self._f.File(self.host, |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
321 filepath, |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
322 uid=sid, |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
323 size=size, |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
324 profile=client.profile |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
325 ) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
326 d = plugin.startStream(file_obj, jid.JID(iq_elt['from']), sid, profile=client.profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
327 d.addCallback(self._sendCb, sid, file_obj, client.profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
328 d.addErrback(self._sendEb, sid, file_obj, client.profile) |
0 | 329 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
330 def _fileEb(self, failure, filepath, sid, size, client): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
331 if failure.check(error.StanzaError): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
332 stanza_err = failure.value |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
333 if stanza_err.code == '403' and stanza_err.condition == 'forbidden': |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
334 from_s = stanza_err.stanza['from'] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
335 log.info(u"File transfer refused by {}".format(from_s)) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
336 self.host.bridge.newAlert(_("The contact {} has refused your file").format(from_s), _("File refused"), "INFO", client.profile) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
337 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
338 log.warning(_(u"Error during file transfer")) |
1640
d470affbe65c
plugin XEP-0363, upload: File upload (through HTTP upload only for now):
Goffi <goffi@goffi.org>
parents:
1585
diff
changeset
|
339 self.host.bridge.newAlert(_(u"Something went wrong during the file transfer session initialisation: {reason}").format(reason=unicode(stanza_err)), _("File transfer error"), "ERROR", client.profile) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
340 elif failure.check(exceptions.DataError): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
341 log.warning(u'Invalid stanza received') |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
342 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
343 log.error(u'Error while proposing stream: {}'.format(failure)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
344 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
345 def _sendCb(self, dummy, sid, file_obj, profile): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
346 log.info(_(u'transfer {sid} successfuly finished [{profile}]').format( |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
347 sid=sid, |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
348 profile=profile)) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
349 file_obj.close() |
64 | 350 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
351 def _sendEb(self, failure, sid, file_obj, profile): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
352 log.warning(_(u'transfer {sid} failed [{profile}]: {reason}').format( |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
353 sid=sid, |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
354 profile=profile, |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
355 reason=unicode(failure.value), |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1559
diff
changeset
|
356 )) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
357 file_obj.close() |