Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1558:6a8dd91476f0 | 1559:7cc29634b6ef |
---|---|
153 timeout.cancel() | 153 timeout.cancel() |
154 try: | 154 try: |
155 dest_path = frontend_data['dest_path'] | 155 dest_path = frontend_data['dest_path'] |
156 except KeyError: | 156 except KeyError: |
157 log.error(_('dest path not found in frontend_data')) | 157 log.error(_('dest path not found in frontend_data')) |
158 del(client._xep_0096_waiting_for_approval[sid]) | 158 del client._xep_0096_waiting_for_approval[sid] |
159 return | 159 return |
160 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: | 160 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
161 file_obj = self._getFileObject(dest_path, can_range) | 161 plugin = self.host.plugins["XEP-0065"] |
162 range_offset = file_obj.tell() | |
163 self.host.plugins["XEP-0065"].prepareToReceive(jid.JID(data['from']), sid, file_obj, int(data["size"]), self._transferSucceeded, self._transferFailed, profile) | |
164 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: | 162 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
165 file_obj = self._getFileObject(dest_path, can_range) | 163 plugin = self.host.plugins["XEP-0047"] |
166 range_offset = file_obj.tell() | |
167 d = self.host.plugins["XEP-0047"].createSession(file_obj, jid.JID(data['from']), sid, int(data["size"]), profile) | |
168 d.addCallback(self._transferSucceeded, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) | |
169 d.addErrback(self._transferFailed, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) | |
170 else: | 164 else: |
171 log.error(_("Unknown stream method, this should not happen at this stage, cancelling transfer")) | 165 log.error(_("Unknown stream method, this should not happen at this stage, cancelling transfer")) |
172 del(client._xep_0096_waiting_for_approval[sid]) | 166 del client._xep_0096_waiting_for_approval[sid] |
173 return | 167 return |
168 | |
169 file_obj = self._getFileObject(dest_path, can_range) | |
170 range_offset = file_obj.tell() | |
171 d = plugin.createSession(file_obj, jid.JID(data['from']), sid, int(data["size"]), profile) | |
172 d.addCallback(self._transferSucceeded, sid, file_obj, stream_method, profile) | |
173 d.addErrback(self._transferFailed, sid, file_obj, stream_method, profile) | |
174 | 174 |
175 #we can send the iq result | 175 #we can send the iq result |
176 feature_elt = self.host.plugins["XEP-0020"].chooseOption({'stream-method': stream_method}) | 176 feature_elt = self.host.plugins["XEP-0020"].chooseOption({'stream-method': stream_method}) |
177 misc_elts = [] | 177 misc_elts = [] |
178 misc_elts.append(domish.Element((PROFILE, "file"))) | 178 misc_elts.append(domish.Element((PROFILE, "file"))) |
247 except KeyError: | 247 except KeyError: |
248 log.warning(_("No stream method choosed")) | 248 log.warning(_("No stream method choosed")) |
249 return | 249 return |
250 | 250 |
251 range_offset = 0 | 251 range_offset = 0 |
252 range_length = None | 252 # range_length = None |
253 range_elts = filter(lambda elt: elt.name == 'range', si_elt.elements()) | 253 range_elts = filter(lambda elt: elt.name == 'range', si_elt.elements()) |
254 if range_elts: | 254 if range_elts: |
255 range_elt = range_elts[0] | 255 range_elt = range_elts[0] |
256 range_offset = range_elt.getAttribute("offset", 0) | 256 range_offset = range_elt.getAttribute("offset", 0) |
257 range_length = range_elt.getAttribute("length") | 257 # range_length = range_elt.getAttribute("length") |
258 | 258 |
259 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: | 259 if stream_method == self.host.plugins["XEP-0065"].NAMESPACE: |
260 file_obj = open(filepath, 'r') | 260 plugin = self.host.plugins["XEP-0065"] |
261 if range_offset: | |
262 file_obj.seek(range_offset) | |
263 self.host.plugins["XEP-0065"].startStream(file_obj, jid.JID(IQ['from']), sid, range_length, self._sendSuccessCb, self._sendFailureCb, size, profile) | |
264 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: | 261 elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE: |
265 file_obj = open(filepath, 'r') | 262 plugin = self.host.plugins["XEP-0047"] |
266 if range_offset: | |
267 file_obj.seek(range_offset) | |
268 d = self.host.plugins["XEP-0047"].startStream(file_obj, jid.JID(IQ['from']), sid, profile=profile) | |
269 d.addCallback(self.sendSuccessCb, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) | |
270 d.addErrback(self.sendFailureCb, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile) | |
271 else: | 263 else: |
272 log.warning(_("Invalid stream method received")) | 264 log.error(u"Invalid stream method received") |
265 return | |
266 | |
267 file_obj = open(filepath, 'r') | |
268 if range_offset: | |
269 file_obj.seek(range_offset) | |
270 d = plugin.startStream(file_obj, jid.JID(IQ['from']), sid, profile=profile) | |
271 d.addCallback(self.sendSuccessCb, sid, file_obj, stream_method, profile) | |
272 d.addErrback(self.sendFailureCb, sid, file_obj, stream_method, profile) | |
273 | 273 |
274 def sendFile(self, to_jid, filepath, data={}, profile_key=C.PROF_KEY_NONE): | 274 def sendFile(self, to_jid, filepath, data={}, profile_key=C.PROF_KEY_NONE): |
275 """send a file using XEP-0096 | 275 """send a file using XEP-0096 |
276 @to_jid: recipient | 276 @to_jid: recipient |
277 @filepath: absolute path to the file to send | 277 @filepath: absolute path to the file to send |