fix using transport sid in jingle IBB instead of jingle sid
fix double iq-result sending
This commit is contained in:
parent
a5eb0070e9
commit
845d8a445d
|
@ -62,6 +62,13 @@ class FilesProp:
|
||||||
if fp.sid == sid:
|
if fp.sid == sid:
|
||||||
return fp
|
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
|
@classmethod
|
||||||
def getAllFileProp(cls):
|
def getAllFileProp(cls):
|
||||||
return list(cls._files_props.values())
|
return list(cls._files_props.values())
|
||||||
|
|
|
@ -199,7 +199,8 @@ class JingleContent(object):
|
||||||
if self.file_props.size < 10000000 and not \
|
if self.file_props.size < 10000000 and not \
|
||||||
self.file_props.hash_:
|
self.file_props.hash_:
|
||||||
h = self._calcHash()
|
h = self._calcHash()
|
||||||
file_tag.addChild(node=h)
|
if h:
|
||||||
|
file_tag.addChild(node=h)
|
||||||
pjid = gajim.get_jid_without_resource(self.session.peerjid)
|
pjid = gajim.get_jid_without_resource(self.session.peerjid)
|
||||||
file_info = {'name' : self.file_props.name,
|
file_info = {'name' : self.file_props.name,
|
||||||
'file-name' : self.file_props.file_name,
|
'file-name' : self.file_props.file_name,
|
||||||
|
|
|
@ -174,10 +174,6 @@ class JingleFileTransfer(JingleContent):
|
||||||
def __on_session_accept(self, stanza, content, error, action):
|
def __on_session_accept(self, stanza, content, error, action):
|
||||||
log.info("__on_session_accept")
|
log.info("__on_session_accept")
|
||||||
con = self.session.connection
|
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')
|
security = content.getTag('security')
|
||||||
if not security: # responder can not verify our fingerprint
|
if not security: # responder can not verify our fingerprint
|
||||||
self.use_security = False
|
self.use_security = False
|
||||||
|
@ -289,9 +285,6 @@ class JingleFileTransfer(JingleContent):
|
||||||
'sendCand' : False}
|
'sendCand' : False}
|
||||||
if self.state == STATE_CAND_SENT:
|
if self.state == STATE_CAND_SENT:
|
||||||
self.__state_changed(STATE_CAND_SENT_AND_RECEIVED, args)
|
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)
|
self.__state_changed(STATE_TRANSFERING)
|
||||||
raise nbxmpp.NodeProcessed
|
raise nbxmpp.NodeProcessed
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -140,6 +140,7 @@ class StateTransfering(JingleFileTransferStates):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __start_IBB_transfer(self, con):
|
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')
|
fp = open(self.jft.file_props.file_name, 'r')
|
||||||
con.OpenStream( self.jft.file_props.sid, self.jft.session.peerjid, fp,
|
con.OpenStream( self.jft.file_props.sid, self.jft.session.peerjid, fp,
|
||||||
blocksize=4096)
|
blocksize=4096)
|
||||||
|
|
|
@ -184,6 +184,7 @@ class ConnectionBytestream:
|
||||||
if nbxmpp.NS_BYTESTREAM in file_props.stream_methods:
|
if nbxmpp.NS_BYTESTREAM in file_props.stream_methods:
|
||||||
field.setValue(nbxmpp.NS_BYTESTREAM)
|
field.setValue(nbxmpp.NS_BYTESTREAM)
|
||||||
else:
|
else:
|
||||||
|
file_props.transport_sid = file_props.sid
|
||||||
field.setValue(nbxmpp.NS_IBB)
|
field.setValue(nbxmpp.NS_IBB)
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
|
|
||||||
|
@ -249,6 +250,7 @@ class ConnectionBytestream:
|
||||||
raise nbxmpp.NodeProcessed
|
raise nbxmpp.NodeProcessed
|
||||||
if field.getValue() == nbxmpp.NS_IBB:
|
if field.getValue() == nbxmpp.NS_IBB:
|
||||||
sid = file_props.sid
|
sid = file_props.sid
|
||||||
|
file_props.transport_sid = sid
|
||||||
fp = open(file_props.file_name, 'r')
|
fp = open(file_props.file_name, 'r')
|
||||||
self.OpenStream(sid, file_props.receiver, fp)
|
self.OpenStream(sid, file_props.receiver, fp)
|
||||||
raise nbxmpp.NodeProcessed
|
raise nbxmpp.NodeProcessed
|
||||||
|
@ -780,7 +782,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
blocksize = stanza.getTagAttr('open', 'block-size')
|
blocksize = stanza.getTagAttr('open', 'block-size')
|
||||||
log.debug('StreamOpenHandler called sid->%s blocksize->%s' % (sid,
|
log.debug('StreamOpenHandler called sid->%s blocksize->%s' % (sid,
|
||||||
blocksize))
|
blocksize))
|
||||||
file_props = FilesProp.getFileProp(self.name, sid)
|
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
|
||||||
try:
|
try:
|
||||||
blocksize = int(blocksize)
|
blocksize = int(blocksize)
|
||||||
except:
|
except:
|
||||||
|
@ -851,8 +853,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
file_props.disconnect_cb = None
|
file_props.disconnect_cb = None
|
||||||
file_props.continue_cb = None
|
file_props.continue_cb = None
|
||||||
syn = nbxmpp.Protocol('iq', to, 'set', payload=[nbxmpp.Node(
|
syn = nbxmpp.Protocol('iq', to, 'set', payload=[nbxmpp.Node(
|
||||||
nbxmpp.NS_IBB + ' open', {'sid': sid, 'block-size': blocksize,
|
nbxmpp.NS_IBB + ' open', {'sid': file_props.transport_sid,
|
||||||
'stanza': 'iq'})])
|
'block-size': blocksize, 'stanza': 'iq'})])
|
||||||
self.connection.send(syn)
|
self.connection.send(syn)
|
||||||
file_props.syn_id = syn.getID()
|
file_props.syn_id = syn.getID()
|
||||||
return file_props
|
return file_props
|
||||||
|
@ -878,7 +880,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
continue
|
continue
|
||||||
chunk = file_props.fp.read(file_props.block_size)
|
chunk = file_props.fp.read(file_props.block_size)
|
||||||
if chunk:
|
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.b64encode(chunk.encode(
|
'seq': file_props.seq}, base64.b64encode(chunk.encode(
|
||||||
'utf-8')).decode('utf-8'))
|
'utf-8')).decode('utf-8'))
|
||||||
file_props.seq += 1
|
file_props.seq += 1
|
||||||
|
@ -901,7 +904,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
self.connection.send(nbxmpp.Protocol('iq',
|
self.connection.send(nbxmpp.Protocol('iq',
|
||||||
file_props.direction[1:], 'set',
|
file_props.direction[1:], 'set',
|
||||||
payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close',
|
payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close',
|
||||||
{'sid':sid})]))
|
{'sid': file_props.transport_sid})]))
|
||||||
file_props.completed = True
|
file_props.completed = True
|
||||||
|
|
||||||
def IBBMessageHandler(self, conn, stanza):
|
def IBBMessageHandler(self, conn, stanza):
|
||||||
|
@ -920,7 +923,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
seq = ''
|
seq = ''
|
||||||
data = ''
|
data = ''
|
||||||
err = None
|
err = None
|
||||||
file_props = FilesProp.getFileProp(self.name, sid)
|
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
|
||||||
if file_props is None:
|
if file_props is None:
|
||||||
err = nbxmpp.ERR_ITEM_NOT_FOUND
|
err = nbxmpp.ERR_ITEM_NOT_FOUND
|
||||||
else:
|
else:
|
||||||
|
@ -957,15 +960,12 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
sid = stanza.getTagAttr('close', 'sid')
|
sid = stanza.getTagAttr('close', 'sid')
|
||||||
log.debug('StreamCloseHandler called sid->%s' % sid)
|
log.debug('StreamCloseHandler called sid->%s' % sid)
|
||||||
# look in sending files
|
# look in sending files
|
||||||
file_props = FilesProp.getFileProp(self.name, sid)
|
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
|
||||||
if file_props:
|
if file_props:
|
||||||
reply = stanza.buildReply('result')
|
reply = stanza.buildReply('result')
|
||||||
reply.delChild('close')
|
reply.delChild('close')
|
||||||
conn.send(reply)
|
conn.send(reply)
|
||||||
# look in receiving files
|
# look in receiving files
|
||||||
reply = stanza.buildReply('result')
|
|
||||||
reply.delChild('close')
|
|
||||||
conn.send(reply)
|
|
||||||
file_props.fp.close()
|
file_props.fp.close()
|
||||||
file_props.completed = file_props.received_len >= file_props.size
|
file_props.completed = file_props.received_len >= file_props.size
|
||||||
if not file_props.completed:
|
if not file_props.completed:
|
||||||
|
@ -1005,7 +1005,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
||||||
else:
|
else:
|
||||||
if stanza.getTag('data'):
|
if stanza.getTag('data'):
|
||||||
sid = stanza.getTagAttr('data', 'sid')
|
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,
|
if file_props.connected and self.IBBMessageHandler(conn,
|
||||||
stanza):
|
stanza):
|
||||||
reply = stanza.buildReply('result')
|
reply = stanza.buildReply('result')
|
||||||
|
|
Loading…
Reference in New Issue