Commit ab330975 authored by Yann Leboulanger's avatar Yann Leboulanger

fix using transport sid in jingle IBB instead of jingle sid

fix double iq-result sending
parent 29cc47a6
......@@ -62,6 +62,13 @@ class FilesProp:
if fp.sid == sid:
return fp
@classmethod
def getFilePropByTransportSid(cls, account, sid):
files_prop = cls.getAllFileProp()
for fp in files_prop:
if fp.account == account and fp.transport_sid == sid:
return fp
@classmethod
def getAllFileProp(cls):
return cls._files_props.values()
......
......@@ -199,7 +199,8 @@ class JingleContent(object):
if self.file_props.size < 10000000 and not \
self.file_props.hash_:
h = self._calcHash()
file_tag.addChild(node=h)
if h:
file_tag.addChild(node=h)
pjid = gajim.get_jid_without_resource(self.session.peerjid)
file_info = {'name' : self.file_props.name,
'file-name' : self.file_props.file_name,
......
......@@ -173,10 +173,6 @@ class JingleFileTransfer(JingleContent):
def __on_session_accept(self, stanza, content, error, action):
log.info("__on_session_accept")
con = self.session.connection
# We ack the session accept
response = stanza.buildReply('result')
response.delChild(response.getQuery())
con.connection.send(response)
security = content.getTag('security')
if not security: # responder can not verify our fingerprint
self.use_security = False
......@@ -288,9 +284,6 @@ class JingleFileTransfer(JingleContent):
'sendCand' : False}
if self.state == STATE_CAND_SENT:
self.__state_changed(STATE_CAND_SENT_AND_RECEIVED, args)
response = stanza.buildReply('result')
response.delChild(response.getQuery())
self.session.connection.connection.send(response)
self.__state_changed(STATE_TRANSFERING)
raise nbxmpp.NodeProcessed
else:
......
......@@ -140,6 +140,7 @@ class StateTransfering(JingleFileTransferStates):
'''
def __start_IBB_transfer(self, con):
self.jft.file_props.transport_sid = self.jft.transport.sid
fp = open(self.jft.file_props.file_name, 'r')
con.OpenStream( self.jft.file_props.sid, self.jft.session.peerjid, fp,
blocksize=4096)
......
......@@ -184,6 +184,7 @@ class ConnectionBytestream:
if nbxmpp.NS_BYTESTREAM in file_props.stream_methods:
field.setValue(nbxmpp.NS_BYTESTREAM)
else:
file_props.transport_sid = file_props.sid
field.setValue(nbxmpp.NS_IBB)
self.connection.send(iq)
......@@ -249,6 +250,7 @@ class ConnectionBytestream:
raise nbxmpp.NodeProcessed
if field.getValue() == nbxmpp.NS_IBB:
sid = file_props.sid
file_props.transport_sid = sid
fp = open(file_props.file_name, 'r')
self.OpenStream(sid, file_props.receiver, fp)
raise nbxmpp.NodeProcessed
......@@ -780,7 +782,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
blocksize = stanza.getTagAttr('open', 'block-size')
log.debug('StreamOpenHandler called sid->%s blocksize->%s' % (sid,
blocksize))
file_props = FilesProp.getFileProp(self.name, sid)
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
try:
blocksize = int(blocksize)
except:
......@@ -851,8 +853,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
file_props.disconnect_cb = None
file_props.continue_cb = None
syn = nbxmpp.Protocol('iq', to, 'set', payload=[nbxmpp.Node(
nbxmpp.NS_IBB + ' open', {'sid': sid, 'block-size': blocksize,
'stanza': 'iq'})])
nbxmpp.NS_IBB + ' open', {'sid': file_props.transport_sid,
'block-size': blocksize, 'stanza': 'iq'})])
self.connection.send(syn)
file_props.syn_id = syn.getID()
return file_props
......@@ -878,7 +880,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
continue
chunk = file_props.fp.read(file_props.block_size)
if chunk:
datanode = nbxmpp.Node(nbxmpp.NS_IBB + ' data', {'sid': sid,
datanode = nbxmpp.Node(nbxmpp.NS_IBB + ' data', {
'sid': file_props.transport_sid,
'seq': file_props.seq}, base64.encodestring(chunk))
file_props.seq += 1
file_props.started = True
......@@ -900,7 +903,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
self.connection.send(nbxmpp.Protocol('iq',
file_props.direction[1:], 'set',
payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close',
{'sid':sid})]))
{'sid': file_props.transport_sid})]))
file_props.completed = True
def IBBMessageHandler(self, conn, stanza):
......@@ -919,7 +922,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
seq = ''
data = ''
err = None
file_props = FilesProp.getFileProp(self.name, sid)
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
if file_props is None:
err = nbxmpp.ERR_ITEM_NOT_FOUND
else:
......@@ -956,15 +959,12 @@ class ConnectionIBBytestream(ConnectionBytestream):
sid = stanza.getTagAttr('close', 'sid')
log.debug('StreamCloseHandler called sid->%s' % sid)
# look in sending files
file_props = FilesProp.getFileProp(self.name, sid)
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
if file_props:
reply = stanza.buildReply('result')
reply.delChild('close')
conn.send(reply)
# look in receiving files
reply = stanza.buildReply('result')
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:
......@@ -1004,7 +1004,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
else:
if stanza.getTag('data'):
sid = stanza.getTagAttr('data', 'sid')
file_props = FilesProp.getFileProp(self.name, sid)
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
if file_props.connected and self.IBBMessageHandler(conn,
stanza):
reply = stanza.buildReply('result')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment