Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0096.py @ 386:deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Sep 2011 12:09:31 +0200 |
parents | f964dcec1611 |
children | c34fd9d6242e |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT plugin for managing xep-0096 | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
22 from logging import debug, info, warning, error |
0 | 23 from twisted.words.xish import domish |
24 from twisted.internet import protocol | |
64 | 25 from twisted.words.protocols.jabber import client, jid |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
26 from twisted.words.protocols.jabber import error as jab_error |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
27 import os, os.path |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
28 from twisted.internet import reactor |
1 | 29 import pdb |
0 | 30 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
31 from zope.interface import implements |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
32 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
33 from wokkel import disco, iwokkel, data_form |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
34 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
35 IQ_SET = '/iq[@type="set"]' |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
36 NS_SI = 'http://jabber.org/protocol/si' |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
37 SI_REQUEST = IQ_SET + '/si[@xmlns="' + NS_SI + '"]' |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
38 PROFILE_NAME = "file-transfer" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
39 PROFILE = "http://jabber.org/protocol/si/profile/" + PROFILE_NAME |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
40 |
0 | 41 PLUGIN_INFO = { |
42 "name": "XEP 0096 Plugin", | |
291 | 43 "import_name": "XEP-0096", |
0 | 44 "type": "XEP", |
48 | 45 "protocols": ["XEP-0096"], |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
46 "dependencies": ["XEP-0020", "XEP-0095", "XEP-0065", "XEP-0047"], |
0 | 47 "main": "XEP_0096", |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
48 "handler": "no", |
69 | 49 "description": _("""Implementation of SI File Transfert""") |
0 | 50 } |
51 | |
64 | 52 class XEP_0096(): |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
53 |
0 | 54 def __init__(self, host): |
69 | 55 info(_("Plugin XEP_0096 initialization")) |
0 | 56 self.host = host |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
57 self._waiting_for_approval = {} #key = id, value = [transfert data, IdelayedCall Reactor timeout, |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
58 # current stream method, [failed stream methods], profile] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
59 self.managed_stream_m = [#self.host.plugins["XEP-0065"].NS_BS, |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
60 self.host.plugins["XEP-0047"].NAMESPACE] #Stream methods managed |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
61 self.host.plugins["XEP-0095"].registerSIProfile(PROFILE_NAME, self.transfertRequest) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
62 host.bridge.addMethod("sendFile", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self.sendFile) |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
63 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
64 def _kill_id(self, approval_id): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
65 """Delete a waiting_for_approval id, called after timeout |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
66 @param approval_id: id of _waiting_for_approval""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
67 info(_("SI File Transfert: TimeOut reached for id %s") % approval_id); |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
68 try: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
69 del self._waiting_for_approval[approval_id] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
70 except KeyError: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
71 warning(_("kill id called on a non existant approval id")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
72 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
73 def transfertRequest(self, from_jid, si_id, si_mime_type, si_el, profile): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
74 """Called when a file transfert is requested |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
75 @param from_jid: jid of the sender |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
76 @param si_id: Stream Initiation session id |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
77 @param si_mime_type: Mime type of the file (or default "application/octet-stream" if unknown) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
78 @param si_el: domish.Element of the request |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
79 @param profile: %(doc_profile)s""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
80 info (_("XEP-0096 file transfert requested")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
81 debug(si_el.toXml()) |
0 | 82 filename = "" |
83 file_size = "" | |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
84 file_date = None |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
85 file_hash = None |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
86 file_desc = "" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
87 can_range = False |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
88 file_elts = filter(lambda elt: elt.name == 'file', si_el.elements()) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
89 feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_el) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
90 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
91 if file_elts: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
92 file_el = file_elts[0] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
93 filename = file_el["name"] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
94 file_size = file_el["size"] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
95 file_date = file_el.getAttribute("date", "") |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
96 file_hash = file_el.getAttribute("hash", "") |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
97 info (_("File proposed: name=[%(name)s] size=%(size)s") % {'name':filename, 'size':file_size}) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
98 for file_child_el in file_el.elements(): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
99 if file_child_el.name == "desc": |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
100 file_desc = unicode(file_child_el) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
101 elif file_child_el.name == "range": |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
102 can_range = True |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
103 else: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
104 warning(_("No file element found")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
105 self.host.plugins["XEP-0095"].sendBadRequestError(si_id, from_jid, profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
106 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
107 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
108 if feature_elts: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
109 feature_el = feature_elts[0] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
110 form = data_form.Form.fromElement(feature_el.firstChildElement()) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
111 try: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
112 stream_method = self.host.plugins["XEP-0020"].negociate(feature_el, 'stream-method',self.managed_stream_m) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
113 except KeyError: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
114 warning(_("No stream method found")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
115 self.host.plugins["XEP-0095"].sendBadRequestError(si_id, from_jid, profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
116 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
117 if not stream_method: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
118 warning(_("Can't find a valid stream method")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
119 self.host.plugins["XEP-0095"].sendFailedError(si_id, from_jid, profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
120 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
121 else: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
122 warning(_("No feature element found")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
123 self.host.plugins["XEP-0095"].sendBadRequestError(si_id, from_jid, profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
124 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
125 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
126 #if we are here, the transfert can start, we just need user's agreement |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
127 data={ "filename":filename, "from":from_jid, "size":file_size, "date":file_date, "hash":file_hash, "desc":file_desc, "can_range": str(can_range) } |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
128 self._waiting_for_approval[si_id] = [data, reactor.callLater(300, self._kill_id, si_id), stream_method, [], profile] |
0 | 129 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
130 self.host.askConfirmation(si_id, "FILE_TRANSFERT", data, self.confirmationCB) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
131 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
132 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
133 def _getFileObject(self, dest_path, can_range = False): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
134 """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
|
135 @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
|
136 @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
|
137 @return: File Object""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
138 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
|
139 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
140 def confirmationCB(self, id, accepted, frontend_data): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
141 """Called on confirmation answer |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
142 @param id: file transfert session id |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
143 @param accepted: True if file transfert is accepted |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
144 @param frontend_data: data sent by frontend""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
145 data, timeout, stream_method, failed_methods, profile = self._waiting_for_approval[id] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
146 can_range = data['can_range'] == "True" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
147 range_offset = 0 |
0 | 148 if accepted: |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
149 if timeout.active(): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
150 timeout.cancel() |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
151 try: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
152 dest_path = frontend_data['dest_path'] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
153 except KeyError: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
154 error(_('dest path not found in frontend_data')) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
155 del(self._waiting_for_approval[id]) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
156 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
157 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
158 self.host.plugins["XEP-0065"].setData(data, id) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
159 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
160 file_obj = self._getFileObject(dest_path, can_range) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
161 range_offset = file_obj.tell() |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
162 self.host.plugins["XEP-0047"].prepareToReceive(jid.JID(data['from']), id, file_obj, int(data["size"]), self._transferSucceeded, self._transferFailed) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
163 else: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
164 error(_("Unknown stream method, this should not happen at this stage, cancelling transfert")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
165 del(self._waiting_for_approval[id]) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
166 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
167 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
168 #we can send the iq result |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
169 feature_elt = self.host.plugins["XEP-0020"].chooseOption({'stream-method':stream_method}) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
170 misc_elts = [] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
171 misc_elts.append(domish.Element((PROFILE, "file"))) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
172 if can_range: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
173 range_elt = domish.Element(('', "range")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
174 range_elt['offset'] = str(range_offset) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
175 #TODO: manage range length |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
176 misc_elts.append(range_elt) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
177 self.host.plugins["XEP-0095"].acceptStream(id, data['from'], feature_elt, misc_elts, profile) |
0 | 178 else: |
69 | 179 debug (_("Transfert [%s] refused"), id) |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
180 self.host.plugins["XEP-0095"].sendRejectedError (id, data['from'], profile=profile) |
0 | 181 del(self._waiting_for_approval[id]) |
182 | |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
183 def _transferSucceeded(self, sid, file_obj, stream_method): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
184 """Called by the stream method when transfert successfuly finished |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
185 @param id: stream id""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
186 file_obj.close() |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
187 info(_('Transfert %s successfuly finished') % sid) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
188 del(self._waiting_for_approval[sid]) |
0 | 189 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
190 def _transferFailed(self, sid, file_obj, stream_method, reason): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
191 """Called when something went wrong with the transfert |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
192 @param id: stream id |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
193 @param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
194 data, timeout, stream_method, failed_methods, profile = self._waiting_for_approval[sid] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
195 warning(_('Transfert %(id)s failed with stream method %(s_method)s') % { 'id': sid, |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
196 's_method': stream_method }) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
197 filepath = file_obj.name |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
198 file_obj.close() |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
199 os.remove(filepath) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
200 #TODO: session remenber (within a time limit) when a stream method fail, and avoid that stream method with full jid for the rest of the session |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
201 warning(_("All stream methods failed, can't transfert the file")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
202 self.host.plugins["XEP-0095"].sendFailedError(id, data['from'], profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
203 del(self._waiting_for_approval[id]) |
0 | 204 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
205 def fileCb(self, profile, filepath, sid, size, IQ): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
206 if IQ['type'] == "error": |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
207 stanza_err = jab_error.exceptionFromStanza(IQ) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
208 if stanza_err.code == '403' and stanza_err.condition == 'forbidden': |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
209 debug(_("File transfert refused by %s") % IQ['from']) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
210 self.host.bridge.newAlert(_("The contact %s refused your file") % IQ['from'], _("File refused"), "INFO", profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
211 else: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
212 warning(_("Error during file transfert with %s") % IQ['from']) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
213 self.host.bridge.newAlert(_("Something went wrong during the file transfer session intialisation with %s") % IQ['from'], _("File transfer error"), "ERROR", profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
214 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
215 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
216 si_elt = IQ.firstChildElement() |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
217 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
218 if IQ['type'] != "result" or not si_elt or si_elt.name != "si": |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
219 error(_("Protocol error during file transfer")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
220 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
221 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
222 feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_elt) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
223 if not feature_elts: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
224 warning(_("No feature element")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
225 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
226 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
227 choosed_options = self.host.plugins["XEP-0020"].getChoosedOptions(feature_elts[0]) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
228 try: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
229 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
|
230 except KeyError: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
231 warning(_("No stream method choosed")) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
232 return |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
233 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
234 range_offset = 0 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
235 range_length = None |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
236 range_elts = filter(lambda elt: elt.name == 'range', si_elt.elements()) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
237 if range_elts: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
238 range_elt = range_elts[0] |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
239 range_offset = range_elt.getAttribute("offset", 0) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
240 range_length = range_elt.getAttribute("length") |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
241 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
242 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
0 | 243 info("SENDING UGLY ANSWER") |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
244 """offer=client.IQ(xmlstream,'set') |
64 | 245 offer["from"]=current_jid.full() |
0 | 246 offer["to"]=answer['from'] |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
247 query=offer.addElement('query', 'http://jabber.org/protocol/ibb') |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
248 #query=offer.addElement('query', 'http://jabber.org/protocol/bytestreams') |
0 | 249 query['mode']='tcp' |
250 streamhost=query.addElement('streamhost') | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
251 streamhost['host']=self.host.memory.getParamA("IP", "File Transfert") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
252 streamhost['port']=self.host.memory.getParamA("Port", "File Transfert") |
64 | 253 streamhost['jid']=current_jid.full() |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
254 offer.send()""" |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
255 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
256 file_obj = open(filepath, 'r') |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
257 if range_offset: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
258 file_obj.seek(range_offset) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
259 self.host.plugins["XEP-0047"].startStream(file_obj, jid.JID(IQ['from']), sid, range_length, self.sendSuccessCb, self.sendFailureCb, size, profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
260 else: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
261 warning(_("Invalid stream method received")) |
0 | 262 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
263 def sendFile(self, to_jid, filepath, data={}, profile_key='@DEFAULT@'): |
0 | 264 """send a file using XEP-0096 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
265 @to_jid: recipient |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
266 @filepath: absolute path to the file to send |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
267 @data: dictionnary with the optional following keys: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
268 - "description": description of the file |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
269 @param profile_key: %(doc_profile_key)s |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
270 @return: an unique id to identify the transfert |
0 | 271 """ |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
272 profile = self.host.memory.getProfileName(profile_key) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
273 if not profile: |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
274 warning(_("Trying to send a file from an unknown profile")) |
64 | 275 return "" |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
276 feature_elt = self.host.plugins["XEP-0020"].proposeFeatures({'stream-method': self.managed_stream_m}) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
277 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
278 #self.host.plugins["XEP-0065"].sendFile(offer["id"], filepath, str(statinfo.st_size)) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
279 |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
280 file_transfer_elts = [] |
0 | 281 |
282 statinfo = os.stat(filepath) | |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
283 file_elt = domish.Element((PROFILE, 'file')) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
284 file_elt['name']=os.path.basename(filepath) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
285 size = file_elt['size']=str(statinfo.st_size) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
286 file_transfer_elts.append(file_elt) |
0 | 287 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
288 file_transfer_elts.append(domish.Element((None,'range'))) |
0 | 289 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
290 sid, offer = self.host.plugins["XEP-0095"].proposeStream(jid.JID(to_jid), PROFILE, feature_elt, file_transfer_elts, profile_key = profile) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
291 offer.addCallback(self.fileCb, profile, filepath, sid, size) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
292 return sid |
0 | 293 |
294 | |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
295 def sendSuccessCb(self, sid, file_obj, stream_method): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
296 info(_('Transfer %s successfuly finished') % sid) |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
297 file_obj.close() |
64 | 298 |
386
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
299 def sendFailureCb(self, sid, file_obj, stream_method, reason): |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
300 file_obj.close() |
deeebf697d9a
plugins: plugin XEP-0096 update, use of XEP-0047 (IBB)
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
301 warning(_('Transfert %(id)s failed with stream method %(s_method)s') % { 'id': sid, s_method: stream_method }) |