Mercurial > libervia-backend
diff src/plugins/plugin_xep_0096.py @ 1559:7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
/!\ SI File Transfert (plugin XEP-0096) is temporarily broken
/!\ proxy handling is temporarily broken
plugin XEP-0096: use of Deferred for plugin XEP-0065 in the same way as for plugin XEP-0047
plugin XEP-0065:
- use of Deferred for sessions
- plugin IP is a dependency
- plugin NAT-PORT is used if available
- everything is now automatic, params are disabled for now (may be re-used in the future to force port or proxy)
- proxy infos are managed with a namedtuple
- connexion candidates are managed with a dedicate class
- priorities can be used for candidates, as needed for XEP-0260
- transfer can now be managed in both direction, with client or server
- socks5 server is launcher on demand, once for all profiles
- helper methods to try and find best candidate
- connection test and file transfer are done in 2 times
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Nov 2015 22:02:41 +0100 |
parents | 7b0fcefd52d4 |
children | d04d7402b8e9 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0096.py Mon Nov 02 22:02:41 2015 +0100 +++ b/src/plugins/plugin_xep_0096.py Mon Nov 02 22:02:41 2015 +0100 @@ -155,23 +155,23 @@ dest_path = frontend_data['dest_path'] except KeyError: log.error(_('dest path not found in frontend_data')) - del(client._xep_0096_waiting_for_approval[sid]) + del client._xep_0096_waiting_for_approval[sid] return if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: - file_obj = self._getFileObject(dest_path, can_range) - range_offset = file_obj.tell() - self.host.plugins["XEP-0065"].prepareToReceive(jid.JID(data['from']), sid, file_obj, int(data["size"]), self._transferSucceeded, self._transferFailed, profile) + plugin = self.host.plugins["XEP-0065"] elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: - file_obj = self._getFileObject(dest_path, can_range) - range_offset = file_obj.tell() - d = self.host.plugins["XEP-0047"].createSession(file_obj, jid.JID(data['from']), sid, int(data["size"]), profile) - d.addCallback(self._transferSucceeded, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) - d.addErrback(self._transferFailed, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) + plugin = self.host.plugins["XEP-0047"] else: log.error(_("Unknown stream method, this should not happen at this stage, cancelling transfer")) - del(client._xep_0096_waiting_for_approval[sid]) + del client._xep_0096_waiting_for_approval[sid] return + file_obj = self._getFileObject(dest_path, can_range) + range_offset = file_obj.tell() + d = plugin.createSession(file_obj, jid.JID(data['from']), sid, int(data["size"]), profile) + d.addCallback(self._transferSucceeded, sid, file_obj, stream_method, profile) + d.addErrback(self._transferFailed, sid, file_obj, stream_method, profile) + #we can send the iq result feature_elt = self.host.plugins["XEP-0020"].chooseOption({'stream-method': stream_method}) misc_elts = [] @@ -249,27 +249,27 @@ return range_offset = 0 - range_length = None + # range_length = None range_elts = filter(lambda elt: elt.name == 'range', si_elt.elements()) if range_elts: range_elt = range_elts[0] range_offset = range_elt.getAttribute("offset", 0) - range_length = range_elt.getAttribute("length") + # range_length = range_elt.getAttribute("length") if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: - file_obj = open(filepath, 'r') - if range_offset: - file_obj.seek(range_offset) - self.host.plugins["XEP-0065"].startStream(file_obj, jid.JID(IQ['from']), sid, range_length, self._sendSuccessCb, self._sendFailureCb, size, profile) + plugin = self.host.plugins["XEP-0065"] elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: - file_obj = open(filepath, 'r') - if range_offset: - file_obj.seek(range_offset) - d = self.host.plugins["XEP-0047"].startStream(file_obj, jid.JID(IQ['from']), sid, profile=profile) - d.addCallback(self.sendSuccessCb, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) - d.addErrback(self.sendFailureCb, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) + plugin = self.host.plugins["XEP-0047"] else: - log.warning(_("Invalid stream method received")) + log.error(u"Invalid stream method received") + return + + file_obj = open(filepath, 'r') + if range_offset: + file_obj.seek(range_offset) + d = plugin.startStream(file_obj, jid.JID(IQ['from']), sid, profile=profile) + d.addCallback(self.sendSuccessCb, sid, file_obj, stream_method, profile) + d.addErrback(self.sendFailureCb, sid, file_obj, stream_method, profile) def sendFile(self, to_jid, filepath, data={}, profile_key=C.PROF_KEY_NONE): """send a file using XEP-0096