changeset 0b88edc63455 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=0b88edc63455
description: Cancel an IBB transfer

diffstat:

 src/common/protocol/bytestream.py |  19 ++++++++++++++++++-
 src/filetransfers_window.py       |   6 +++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diffs (67 lines):

diff -r 57e066cee4a2 -r 0b88edc63455 src/common/protocol/bytestream.py
--- a/src/common/protocol/bytestream.py Wed Feb 13 10:16:52 2013 +0400
+++ b/src/common/protocol/bytestream.py Wed Dec 26 18:41:31 2012 -0400
@@ -803,6 +803,16 @@
             file_props.fp = open(file_props.file_name, 'w')
         conn.send(rep)
 
+    def CloseIBBStream(self, file_props):
+        file_props.connected = False
+        file_props.fp.close()
+        file_props.stopped = True
+        self.connection.send(nbxmpp.Protocol('iq',
+            file_props.direction[1:], 'set',
+            payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close',
+            {'sid':file_props.sid})]))
+
+
     def OpenStream(self, sid, to, fp, blocksize=4096):
         """
         Start new stream. You should provide stream id 'sid', the endpoind jid
@@ -849,6 +859,9 @@
             if file_props.direction[0] == '>':
                 if file_props.paused:
                     continue
+                if not file_props.connected:
+                    #TODO: Reply with out of order error
+                    continue
                 chunk = file_props.fp.read(file_props.block_size)
                 if chunk:
                     datanode = nbxmpp.Node(nbxmpp.NS_IBB + ' data', {'sid': 
sid,
@@ -940,6 +953,9 @@
             reply.delChild('close')
             conn.send(reply)
             file_props.fp.close()
+            file_props.completed = file_props.received_len >= file_props.size
+            if not file_props.completed:
+                file_props.error = -1
             gajim.socks5queue.complete_transfer_cb(self.name, file_props)
         else:
             conn.send(nbxmpp.Error(stanza, nbxmpp.ERR_ITEM_NOT_FOUND))
@@ -954,8 +970,9 @@
         syn_id = stanza.getID()
         log.debug('IBBAllIqHandler called syn_id->%s' % syn_id)
         for file_props in FilesProp.getAllFileProp():
-            if not file_props.direction:
+            if not file_props.direction or not file_props.connected:
                 # It's socks5 bytestream
+                # Or we closed the IBB stream
                 continue
             if file_props.syn_id == syn_id:
                 if stanza.getType() == 'error':
diff -r 57e066cee4a2 -r 0b88edc63455 src/filetransfers_window.py
--- a/src/filetransfers_window.py       Wed Feb 13 10:16:52 2013 +0400
+++ b/src/filetransfers_window.py       Wed Dec 26 18:41:31 2012 -0400
@@ -944,7 +944,11 @@
         account = file_props.tt_account
         if account not in gajim.connections:
             return
-        gajim.connections[account].disconnect_transfer(file_props)
+        con = gajim.connections[account]
+        # Check if we are in a IBB transfer
+        if file_props.direction:
+            con.CloseIBBStream(file_props)
+        con.disconnect_transfer(file_props)
         self.set_status(file_props, 'stop')
 
     def show_tooltip(self, widget):
_______________________________________________
Commits mailing list
Commits@gajim.org
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to