diff src/plugins/plugin_xep_0234.py @ 1556:cbfbe028d099

plugin XEP-0166, XEP-0234, XEP-0261: - transport and application data are now managed in separate dictionaries - new client.IQ method is used - new buildAction helper method for applications and transports - "role" is now stored in session_data - "senders" is now stored in content_data - plugin XEP-0166: "transport-info" action is now managed - plugin XEP-0166: application namespace and handler are now managed in a namedtuple - plugin XEP-0234: <range/> element is added by responder if not already present
author Goffi <goffi@goffi.org>
date Mon, 02 Nov 2015 22:02:41 +0100
parents a151f3a5a2d0
children 22f0307864b4
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0234.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_xep_0234.py	Mon Nov 02 22:02:41 2015 +0100
@@ -93,17 +93,18 @@
         @param profile: %(doc_profile)s
         return (defer.Deferred): True if transfer is accepted
         """
-        file_data = content_data['file_data']
+        application_data = content_data['application_data']
+        file_data = application_data['file_data']
         d = xml_tools.deferDialog(self.host,
             _(CONFIRM).format(entity=session['to_jid'].full(), **file_data),
             _(CONFIRM_TITLE),
             type_=C.XMLUI_DIALOG_FILE,
             options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR},
             profile=profile)
-        d.addCallback(self._gotConfirmation, session, content_data, profile)
+        d.addCallback(self._gotConfirmation, session, content_data, application_data, profile)
         return d
 
-    def _gotConfirmation(self, data, session, content_data, profile):
+    def _gotConfirmation(self, data, session, content_data, application_data, profile):
         """Called when the permission and dest path have been received
 
         @param data(dict): xmlui data received from file dialog
@@ -113,7 +114,7 @@
         """
         if data.get('cancelled', False):
             return False
-        file_data = content_data['file_data']
+        file_data = application_data['file_data']
         path = data['path']
         file_data['file_path'] = file_path = os.path.join(path, file_data['name'])
         log.debug(u'destination file path set to {}'.format(file_path))
@@ -144,9 +145,10 @@
 
     def jingleSessionInit(self, session, content_name, filepath, name=None, file_desc=None, profile=C.PROF_KEY_NONE):
         content_data = session['contents'][content_name]
-        assert 'file_path' not in content_data
-        content_data['file_path'] = filepath
-        file_data = content_data['file_data'] = {}
+        application_data = content_data['application_data']
+        assert 'file_path' not in application_data
+        application_data['file_path'] = filepath
+        file_data = application_data['file_data'] = {}
         file_data['date'] = utils.xmpp_date()
         file_data['desc'] = file_desc or ''
         file_data['media-type'] = "application/octet-stream" # TODO
@@ -190,7 +192,7 @@
 
         # TODO: parse hash using plugin XEP-0300
 
-        content_data['file_data'] = file_data
+        content_data['application_data']['file_data'] = file_data
 
         # now we actualy request permission to user
         return self._getDestDir(session, content_data, profile)
@@ -198,12 +200,21 @@
 
     def jingleHandler(self, action, session, content_name, desc_elt, profile):
         content_data = session['contents'][content_name]
-        if action in (self._j.A_SESSION_INITIATE, self._j.A_ACCEPTED_ACK):
+        application_data = content_data['application_data']
+        if action in (self._j.A_ACCEPTED_ACK,):
             pass
+        elif action == self._j.A_SESSION_INITIATE:
+            file_elt = desc_elt.elements(NS_JINGLE_FT, 'file').next()
+            try:
+                file_elt.elements(NS_JINGLE_FT, 'range').next()
+            except StopIteration:
+                # initiator doesn't manage <range>, but we do so we advertise it
+                log.debug("adding <range> element")
+                file_elt.addElement('range')
         elif action == self._j.A_SESSION_ACCEPT:
             assert not 'file_obj' in content_data
-            file_path = content_data['file_path']
-            size = content_data['file_data']['size']
+            file_path = application_data['file_path']
+            size = application_data['file_data']['size']
             file_obj = content_data['file_obj'] = self._f.File(self.host,
                                                   file_path,
                                                   size=size,