comparison src/plugins/plugin_xep_0096.py @ 1585:846a39900fa6

plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2015 19:18:05 +0100
parents d46aae87c03a
children d470affbe65c
comparison
equal deleted inserted replaced
1584:b57b4683dc33 1585:846a39900fa6
44 "description": _("""Implementation of SI File Transfer""") 44 "description": _("""Implementation of SI File Transfer""")
45 } 45 }
46 46
47 47
48 class XEP_0096(object): 48 class XEP_0096(object):
49 # TODO: call self._f.unregister when unloading order will be managing (i.e. when depenencies will be unloaded at the end)
49 50
50 def __init__(self, host): 51 def __init__(self, host):
51 log.info(_("Plugin XEP_0096 initialization")) 52 log.info(_("Plugin XEP_0096 initialization"))
52 self.host = host 53 self.host = host
53 self.managed_stream_m = [self.host.plugins["XEP-0065"].NAMESPACE, 54 self.managed_stream_m = [self.host.plugins["XEP-0065"].NAMESPACE,
54 self.host.plugins["XEP-0047"].NAMESPACE] # Stream methods managed 55 self.host.plugins["XEP-0047"].NAMESPACE] # Stream methods managed
55 self._f = self.host.plugins["FILE"] 56 self._f = self.host.plugins["FILE"]
57 self._f.register(NS_SI_FT, self.sendFile, priority=0, method_name=u"Stream Initiation")
56 self._si = self.host.plugins["XEP-0095"] 58 self._si = self.host.plugins["XEP-0095"]
57 self._si.registerSIProfile(SI_PROFILE_NAME, self._transferRequest) 59 self._si.registerSIProfile(SI_PROFILE_NAME, self._transferRequest)
58 host.bridge.addMethod("siSendFile", ".plugin", in_sign='sssss', out_sign='s', method=self._sendFile) 60 host.bridge.addMethod("siSendFile", ".plugin", in_sign='sssss', out_sign='s', method=self._sendFile)
59 61
60 def unload(self): 62 def unload(self):
165 return 167 return
166 168
167 #if we are here, the transfer can start, we just need user's agreement 169 #if we are here, the transfer can start, we just need user's agreement
168 data = {"name": filename, "peer_jid": peer_jid, "size": file_size, "date": file_date, "hash": file_hash, "desc": file_desc, 170 data = {"name": filename, "peer_jid": peer_jid, "size": file_size, "date": file_date, "hash": file_hash, "desc": file_desc,
169 "range": range_, "range_offset": range_offset, "range_length": range_length, 171 "range": range_, "range_offset": range_offset, "range_length": range_length,
170 "si_id": si_id, "stream_method": stream_method, "stream_plugin": plugin} 172 "si_id": si_id, "progress_id": si_id, "stream_method": stream_method, "stream_plugin": plugin}
171 173
172 d = self._f.getDestDir(peer_jid, data, data, profile) 174 d = self._f.getDestDir(peer_jid, data, data, profile)
173 d.addCallback(self.confirmationCb, iq_elt, data, profile) 175 d.addCallback(self.confirmationCb, iq_elt, data, profile)
174 176
175 def _getFileObject(self, dest_path, can_range=False): 177 def _getFileObject(self, dest_path, can_range=False):
315 log.warning(u"Invalid stream method received") 317 log.warning(u"Invalid stream method received")
316 return 318 return
317 319
318 file_obj = self._f.File(self.host, 320 file_obj = self._f.File(self.host,
319 filepath, 321 filepath,
322 uid=sid,
320 size=size, 323 size=size,
321 profile=client.profile 324 profile=client.profile
322 ) 325 )
323 d = plugin.startStream(file_obj, jid.JID(iq_elt['from']), sid, profile=client.profile) 326 d = plugin.startStream(file_obj, jid.JID(iq_elt['from']), sid, profile=client.profile)
324 d.addCallback(self._sendCb, sid, file_obj, client.profile) 327 d.addCallback(self._sendCb, sid, file_obj, client.profile)
331 from_s = stanza_err.stanza['from'] 334 from_s = stanza_err.stanza['from']
332 log.info(u"File transfer refused by {}".format(from_s)) 335 log.info(u"File transfer refused by {}".format(from_s))
333 self.host.bridge.newAlert(_("The contact {} has refused your file").format(from_s), _("File refused"), "INFO", client.profile) 336 self.host.bridge.newAlert(_("The contact {} has refused your file").format(from_s), _("File refused"), "INFO", client.profile)
334 else: 337 else:
335 log.warning(_(u"Error during file transfer")) 338 log.warning(_(u"Error during file transfer"))
336 self.host.bridge.newAlert(_(u"Something went wrong during the file transfer session intialisation: {reason}").format(reason=unicode(stanza_err.value)), _("File transfer error"), "ERROR", client.profile) 339 self.host.bridge.newAlert(_(u"Something went wrong during the file transfer session initialisation: {reason}").format(reason=unicode(stanza_err.value)), _("File transfer error"), "ERROR", client.profile)
337 elif failure.check(exceptions.DataError): 340 elif failure.check(exceptions.DataError):
338 log.warning(u'Invalid stanza received') 341 log.warning(u'Invalid stanza received')
339 else: 342 else:
340 log.error(u'Error while proposing stream: {}'.format(failure)) 343 log.error(u'Error while proposing stream: {}'.format(failure))
341 344