comparison sat/plugins/plugin_xep_0096.py @ 3449:893582c2d983

plugin XEP-0096: fix plugin following changes in `plugin_misc_file`
author Goffi <goffi@goffi.org>
date Fri, 11 Dec 2020 17:48:19 +0100
parents 559a625a236b
children be6d91572633
comparison
equal deleted inserted replaced
3448:987198910e56 3449:893582c2d983
48 } 48 }
49 49
50 50
51 class XEP_0096(object): 51 class XEP_0096(object):
52 # TODO: call self._f.unregister when unloading order will be managing (i.e. when depenencies will be unloaded at the end) 52 # TODO: call self._f.unregister when unloading order will be managing (i.e. when depenencies will be unloaded at the end)
53 name = PLUGIN_INFO[C.PI_NAME]
54 human_name = D_("Stream Initiation")
53 55
54 def __init__(self, host): 56 def __init__(self, host):
55 log.info(_("Plugin XEP_0096 initialization")) 57 log.info(_("Plugin XEP_0096 initialization"))
56 self.host = host 58 self.host = host
57 self.managed_stream_m = [ 59 self.managed_stream_m = [
58 self.host.plugins["XEP-0065"].NAMESPACE, 60 self.host.plugins["XEP-0065"].NAMESPACE,
59 self.host.plugins["XEP-0047"].NAMESPACE, 61 self.host.plugins["XEP-0047"].NAMESPACE,
60 ] # Stream methods managed 62 ] # Stream methods managed
61 self._f = self.host.plugins["FILE"] 63 self._f = self.host.plugins["FILE"]
62 self._f.register( 64 self._f.register(self)
63 NS_SI_FT, self.sendFile, priority=0, method_name="Stream Initiation"
64 )
65 self._si = self.host.plugins["XEP-0095"] 65 self._si = self.host.plugins["XEP-0095"]
66 self._si.registerSIProfile(SI_PROFILE_NAME, self._transferRequest) 66 self._si.registerSIProfile(SI_PROFILE_NAME, self._transferRequest)
67 host.bridge.addMethod( 67 host.bridge.addMethod(
68 "siSendFile", ".plugin", in_sign="sssss", out_sign="s", method=self._sendFile 68 "siSendFile", ".plugin", in_sign="sssss", out_sign="s", method=self._fileSend
69 ) 69 )
70
71 async def canHandleFileSend(self, client, peer_jid, filepath):
72 return await self.host.hasFeature(client, NS_SI_FT, peer_jid)
70 73
71 def unload(self): 74 def unload(self):
72 self._si.unregisterSIProfile(SI_PROFILE_NAME) 75 self._si.unregisterSIProfile(SI_PROFILE_NAME)
73 76
74 def _badRequest(self, client, iq_elt, message=None): 77 def _badRequest(self, client, iq_elt, message=None):
277 reason=str(failure.value), **data 280 reason=str(failure.value), **data
278 ) 281 )
279 ) 282 )
280 data["stream_object"].close() 283 data["stream_object"].close()
281 284
282 def _sendFile(self, peer_jid_s, filepath, name, desc, profile=C.PROF_KEY_NONE): 285 def _fileSend(self, peer_jid_s, filepath, name, desc, profile=C.PROF_KEY_NONE):
283 client = self.host.getClient(profile) 286 client = self.host.getClient(profile)
284 return self.sendFile( 287 return self.fileSend(
285 client, jid.JID(peer_jid_s), filepath, name or None, desc or None 288 client, jid.JID(peer_jid_s), filepath, name or None, desc or None
286 ) 289 )
287 290
288 def sendFile(self, client, peer_jid, filepath, name=None, desc=None, extra=None): 291 def fileSend(self, client, peer_jid, filepath, name=None, desc=None, extra=None):
289 """Send a file using XEP-0096 292 """Send a file using XEP-0096
290 293
291 @param peer_jid(jid.JID): recipient 294 @param peer_jid(jid.JID): recipient
292 @param filepath(str): absolute path to the file to send 295 @param filepath(str): absolute path to the file to send
293 @param name(unicode): name of the file to send 296 @param name(unicode): name of the file to send