annotate src/plugins/plugin_xep_0096.py @ 1577:d04d7402b8e9

plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation: /!\ range is not working yet /!\ pipe plugin is broken for now
author Goffi <goffi@goffi.org>
date Wed, 11 Nov 2015 18:19:49 +0100
parents 7cc29634b6ef
children d46aae87c03a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing xep-0096
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 721
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 "dependencies": ["XEP-0020", "XEP-0095", "XEP-0065", "XEP-0047"],
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
goffi@necton2
parents:
diff changeset
45 }
goffi@necton2
parents:
diff changeset
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):
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
49
0
goffi@necton2
parents:
diff changeset
50 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
51 log.info(_("Plugin XEP_0096 initialization"))
0
goffi@necton2
parents:
diff changeset
52 self.host = host
540
47e45a577ab7 plugin XEP-0096: restored XEP-0065 usage
Goffi <goffi@goffi.org>
parents: 538
diff changeset
53 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
54 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
55 self._f = self.host.plugins["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
56 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
57 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
58 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
59
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 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
61 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
62
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 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
64 """Send a bad-request error
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 8
diff changeset
65
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
66 @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
67 @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
68 @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
69 """
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 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
71 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
72 self._si.sendError(iq_elt, 'bad-request', profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
73
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
74 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
75 """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
76
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 @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
78 @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
79 - 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
80 - 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
81 - 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
82 """
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 range_ = True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
91
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
92 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
93 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
94 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
95 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
96
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 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
98 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
99 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
100 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
101
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 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
103 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
104
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 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
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 def _transferRequest(self, iq_elt, si_id, si_mime_type, si_elt, profile):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
108 """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
109
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
110 @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
111 @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
112 @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
113 @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
114 @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
115 """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
116 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
117 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
118
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
119 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
120 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
121 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
122 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
123
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
124 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
125 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
126 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
127 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
128
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
129 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
130 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
131 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
132 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
133 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
134
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 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
136 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
137
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 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
139
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
140 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
141 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
142 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
143 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
144
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 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
146 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
147 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
148 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
149
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
150 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
151 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
152 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
153 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
154
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 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
156 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
157 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
158 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
159 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
160 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
161 log.error(_("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
162 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
163 log.warning(_("Can't find a valid 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
164 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
165 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
166
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
167 #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
168 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
169 "range": range_, "range_offset": range_offset, "range_length": 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
170 "si_id": si_id, "stream_method": stream_method, "stream_plugin": plugin}
0
goffi@necton2
parents:
diff changeset
171
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
172 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
173 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
174
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
175 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
176 """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
177 @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
178 @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
179 @return: File Object"""
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
180 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
181
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
182 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
183 """Called on confirmation answer
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
184
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
185 @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
186 @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
187 @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
188 @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
189 """
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 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
191 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
192 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
193 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
194 # 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
195 # 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
196 # 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
197 # 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
198 # 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
199 # 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
200 # 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
201 # 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
202 # 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
203 # 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
204 # 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
205 # 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
206 # 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
207 # 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
208 # 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
209 # 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
210 # 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
211 # 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
212 # return
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
213
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
214 # 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
215 # 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
216 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
217 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
218 d.addErrback(self._transferEb, data, profile)
0
goffi@necton2
parents:
diff changeset
219
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
220 #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
221 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
222 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
223 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
224 # 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
225 # 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
226 # 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
227 # #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
228 # 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
229 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
230
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
231 def _transferCb(self, dummy, data, profile):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
232 """Called by the stream method when transfer successfuly finished
0
goffi@necton2
parents:
diff changeset
233
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
234 @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
235 @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
236 """
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 #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
238 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
239 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
240
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
241 def _transferEb(self, failure, data, profile):
391
c34fd9d6242e spelling
Goffi <goffi@goffi.org>
parents: 386
diff changeset
242 """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
243
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
244 @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
245 @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
246 @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
247 """
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 log.warning(u'Transfer {si_id} failed: {reason}'.format(reason=unicode(failure.condition), **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
249 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
250
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 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
252 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
253
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 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
255 """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
256
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 @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
258 @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
259 @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
260 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
261 @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
262 @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
263 @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
264 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
265 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
266 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
267
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 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
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 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 file_transfer_elts.append(file_elt)
0
goffi@necton2
parents:
diff changeset
279
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
280 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
281
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 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
283 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
284 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
285 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
286
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 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
288 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
289
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 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
291 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
292 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
293 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
294 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
295
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
296 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
297 try:
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
298 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
299 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
300 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
301 return
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
302
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
303 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
304 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
305 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
306 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
307 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
308 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
309
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
310 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
311 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
312 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
313 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
314 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
315 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
316 return
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
317
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
318 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
319 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
320 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
321 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
322 )
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
323 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
324 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
325 d.addErrback(self._sendEb, sid, file_obj, client.profile)
0
goffi@necton2
parents:
diff changeset
326
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
327 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
328 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
329 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
330 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
331 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
332 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
333 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
334 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
335 log.warning(_(u"Error during 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
336 self.host.bridge.newAlert(_(u"Something went wrong during the file transfer session intialisation: {reason}").format(reason=unicode(stanza_err.condition)), _("File transfer error"), "ERROR", 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 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
338 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
339 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
340 log.error(u'Error while proposing stream: {}'.format(failure))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
341
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
342 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
343 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
344 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
345 profile=profile))
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
346 file_obj.close()
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 57
diff changeset
347
1577
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1559
diff changeset
348 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
349 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
350 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
351 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
352 reason=unicode(failure.condition),
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 ))
386
deeebf697d9a plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents: 372
diff changeset
354 file_obj.close()