diff src/plugins/plugin_xep_0096.py @ 394:8f3551ceee17

plugin XEP-0065: refactored and misc stuff fixed. Still not finished plugins XEP-0096: XEP-0065 (Socks5 stream method) managed
author Goffi <goffi@goffi.org>
date Mon, 03 Oct 2011 18:05:15 +0200
parents c34fd9d6242e
children cb0285372818
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0096.py	Sun Oct 02 00:29:04 2011 +0200
+++ b/src/plugins/plugin_xep_0096.py	Mon Oct 03 18:05:15 2011 +0200
@@ -56,7 +56,7 @@
         self.host = host
         self._waiting_for_approval = {} #key = id, value = [transfer data, IdelayedCall Reactor timeout, 
                                         # current stream method, [failed stream methods], profile]
-        self.managed_stream_m = [#self.host.plugins["XEP-0065"].NS_BS,
+        self.managed_stream_m = [self.host.plugins["XEP-0065"].NAMESPACE,
                                  self.host.plugins["XEP-0047"].NAMESPACE] #Stream methods managed
         self.host.plugins["XEP-0095"].registerSIProfile(PROFILE_NAME, self.transferRequest)
         host.bridge.addMethod("sendFile", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self.sendFile)
@@ -155,7 +155,10 @@
                 del(self._waiting_for_approval[id])
                 return
             if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
-                self.host.plugins["XEP-0065"].setData(data, id)
+                file_obj = self._getFileObject(dest_path, can_range)
+                range_offset = file_obj.tell()
+                self.host.plugins["XEP-0065"].prepareToReceive(jid.JID(data['from']), id, file_obj, int(data["size"]), self._transferSucceeded, self._transferFailed)
+                #self.host.plugins["XEP-0065"].setData(data, id)
             elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
                 file_obj = self._getFileObject(dest_path, can_range)
                 range_offset = file_obj.tell()
@@ -199,8 +202,7 @@
         os.remove(filepath)
         #TODO: session remenber (within a time limit) when a stream method fail, and avoid that stream method with full jid for the rest of the session
         warning(_("All stream methods failed, can't transfer the file"))
-        self.host.plugins["XEP-0095"].sendFailedError(id, data['from'], profile)
-        del(self._waiting_for_approval[id])
+        del(self._waiting_for_approval[sid])
 
     def fileCb(self, profile, filepath, sid, size, IQ):
         if IQ['type'] == "error":
@@ -240,18 +242,10 @@
             range_length = range_elt.getAttribute("length")
 
         if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
-            info("SENDING UGLY ANSWER")
-            """offer=client.IQ(xmlstream,'set')
-            offer["from"]=current_jid.full()
-            offer["to"]=answer['from']
-            query=offer.addElement('query', 'http://jabber.org/protocol/ibb')
-            #query=offer.addElement('query', 'http://jabber.org/protocol/bytestreams')
-            query['mode']='tcp'
-            streamhost=query.addElement('streamhost')
-            streamhost['host']=self.host.memory.getParamA("IP", "File Transfer")
-            streamhost['port']=self.host.memory.getParamA("Port", "File Transfer")
-            streamhost['jid']=current_jid.full()
-            offer.send()"""
+           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)
         elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
            file_obj = open(filepath, 'r')
            if range_offset:
@@ -275,8 +269,6 @@
             return ""
         feature_elt = self.host.plugins["XEP-0020"].proposeFeatures({'stream-method': self.managed_stream_m})
        
-        #self.host.plugins["XEP-0065"].sendFile(offer["id"], filepath, str(statinfo.st_size))
-
         file_transfer_elts = []
         
         statinfo = os.stat(filepath)
@@ -291,7 +283,6 @@
         offer.addCallback(self.fileCb, profile, filepath, sid, size)
         return sid
 
-
     def sendSuccessCb(self, sid, file_obj, stream_method):
         info(_('Transfer %s successfuly finished') % sid)
         file_obj.close()