Mercurial > libervia-backend
diff src/plugins/plugin_xep_0095.py @ 2489:e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
this is a big patch as things had to be changed at the same time.
- changed methods using profile argument to use client instead
- move SatFile in a new tools.stream module, has it should be part of core, not a plugin
- new IStreamProducer interface, to handler starting a pull producer
- new FileStreamObject which create a stream producer/consumer from a SatFile
- plugin pipe is no more using unix named pipe, as it complicate the thing,
special care need to be taken to not block, and it's generally not necessary.
Instead a socket is now used, so the plugin has been renomed to jingle stream.
- bad connection/error should be better handler in jingle stream plugin, and code should not block anymore
- jp pipe commands have been updated accordingly
fix bug 237
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 08 Feb 2018 00:37:42 +0100 |
parents | 0046283a285d |
children |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0095.py Thu Feb 01 07:24:34 2018 +0100 +++ b/src/plugins/plugin_xep_0095.py Thu Feb 08 00:37:42 2018 +0100 @@ -72,11 +72,11 @@ except KeyError: log.error(u"Trying to unregister SI profile [{}] which was not registered".format(si_profile)) - def streamInit(self, iq_elt, profile): + def streamInit(self, iq_elt, client): """This method is called on stream initiation (XEP-0095 #3.2) @param iq_elt: IQ element - @param profile: %(doc_profile)s""" + """ log.info(_("XEP-0095 Stream initiation")) iq_elt.handled = True si_elt = iq_elt.elements(NS_SI, 'si').next() @@ -86,19 +86,17 @@ si_profile_key = si_profile[len(SI_PROFILE_HEADER):] if si_profile.startswith(SI_PROFILE_HEADER) else si_profile if si_profile_key in self.si_profiles: #We know this SI profile, we call the callback - self.si_profiles[si_profile_key](iq_elt, si_id, si_mime_type, si_elt, profile) + self.si_profiles[si_profile_key](client, iq_elt, si_id, si_mime_type, si_elt) else: #We don't know this profile, we send an error - self.sendError(iq_elt, 'bad-profile', profile) + self.sendError(client, iq_elt, 'bad-profile') - def sendError(self, request, condition, profile): + def sendError(self, client, request, condition): """Send IQ error as a result @param request(domish.Element): original IQ request @param condition(str): error condition - @param profile: %(doc_profile)s """ - client = self.host.getClient(profile) if condition in SI_ERROR_CONDITIONS: si_condition = condition condition = 'bad-request' @@ -111,18 +109,16 @@ client.send(iq_error_elt) - def acceptStream(self, iq_elt, feature_elt, misc_elts=None, profile=C.PROF_KEY_NONE): + def acceptStream(self, client, iq_elt, feature_elt, misc_elts=None): """Send the accept stream initiation answer @param iq_elt(domish.Element): initial SI request @param feature_elt(domish.Element): 'feature' element containing stream method to use @param misc_elts(list[domish.Element]): list of elements to add - @param profile: %(doc_profile)s """ log.info(_("sending stream initiation accept answer")) if misc_elts is None: misc_elts = [] - client = self.host.getClient(profile) result_elt = xmlstream.toResponse(iq_elt, 'result') si_elt = result_elt.addElement((NS_SI, 'si')) si_elt.addChild(feature_elt) @@ -139,7 +135,7 @@ return (iq_elt, si_elt) - def proposeStream(self, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream', profile=C.PROF_KEY_NONE): + def proposeStream(self, client, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream'): """Propose a stream initiation @param to_jid(jid.JID): recipient @@ -147,13 +143,11 @@ @param feature_elt(domish.Element): feature element, according to XEP-0020 @param misc_elts(list[domish.Element]): list of elements to add @param mime_type(unicode): stream mime type - @param profile: %(doc_profile)s @return (tuple): tuple with: - session id (unicode) - (D(domish_elt, domish_elt): offer deferred which returl a tuple with iq_elt and si_elt """ - client = self.host.getClient(profile) offer = client.IQ() sid = str(uuid.uuid4()) log.debug(_(u"Stream Session ID: %s") % offer["id"]) @@ -181,7 +175,7 @@ self.host = plugin_parent.host def connectionInitialized(self): - self.xmlstream.addObserver(SI_REQUEST, self.plugin_parent.streamInit, profile=self.parent.profile) + self.xmlstream.addObserver(SI_REQUEST, self.plugin_parent.streamInit, client=self.parent) def getDiscoInfo(self, requestor, target, nodeIdentifier=''): return [disco.DiscoFeature(NS_SI)] + [disco.DiscoFeature(u"http://jabber.org/protocol/si/profile/{}".format(profile_name)) for profile_name in self.plugin_parent.si_profiles]