sends file request after hash mismatch
This commit is contained in:
parent
c28282300b
commit
e8df81ab31
|
@ -1973,12 +1973,13 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
typ='stream')
|
typ='stream')
|
||||||
raise xmpp.NodeProcessed
|
raise xmpp.NodeProcessed
|
||||||
file_tag = si.getTag('file')
|
file_tag = si.getTag('file')
|
||||||
for attribute in file_tag.getAttrs():
|
for child in file_tag.getChildren():
|
||||||
if attribute in ('name', 'size', 'hash', 'date'):
|
name = child.getName()
|
||||||
val = file_tag.getAttr(attribute)
|
if name in ('name', 'size', 'hash', 'date'):
|
||||||
|
val = child.getData()
|
||||||
if val is None:
|
if val is None:
|
||||||
continue
|
continue
|
||||||
self.file_props[attribute] = val
|
self.file_props[name] = val
|
||||||
file_desc_tag = file_tag.getTag('desc')
|
file_desc_tag = file_tag.getTag('desc')
|
||||||
if file_desc_tag is not None:
|
if file_desc_tag is not None:
|
||||||
self.file_props['desc'] = file_desc_tag.getData()
|
self.file_props['desc'] = file_desc_tag.getData()
|
||||||
|
|
|
@ -101,7 +101,7 @@ class ConnectionJingle(object):
|
||||||
# do we need to create a new jingle object
|
# do we need to create a new jingle object
|
||||||
if sid not in self._sessions:
|
if sid not in self._sessions:
|
||||||
#TODO: tie-breaking and other things...
|
#TODO: tie-breaking and other things...
|
||||||
newjingle = JingleSession(con=self, weinitiate=False, jid=jid,
|
newjingle = JingleSession(con=self, werequest=False, weinitiate=False, jid=jid,
|
||||||
iq_id=id_, sid=sid)
|
iq_id=id_, sid=sid)
|
||||||
self._sessions[sid] = newjingle
|
self._sessions[sid] = newjingle
|
||||||
|
|
||||||
|
@ -141,14 +141,14 @@ class ConnectionJingle(object):
|
||||||
jingle.start_session()
|
jingle.start_session()
|
||||||
return jingle.sid
|
return jingle.sid
|
||||||
|
|
||||||
def start_file_transfer(self, jid, file_props):
|
def start_file_transfer(self, jid, file_props, request=False):
|
||||||
logger.info("start file transfer with file: %s" % file_props)
|
logger.info("start file transfer with file: %s" % file_props)
|
||||||
contact = gajim.contacts.get_contact_with_highest_priority(self.name,
|
contact = gajim.contacts.get_contact_with_highest_priority(self.name,
|
||||||
gajim.get_jid_without_resource(jid))
|
gajim.get_jid_without_resource(jid))
|
||||||
if contact is None:
|
if contact is None:
|
||||||
return
|
return
|
||||||
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)
|
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)
|
||||||
jingle = JingleSession(self, weinitiate=True, jid=jid)
|
jingle = JingleSession(self, request, weinitiate=True, jid=jid)
|
||||||
# this is a file transfer
|
# this is a file transfer
|
||||||
jingle.session_type_FT = True
|
jingle.session_type_FT = True
|
||||||
self._sessions[jingle.sid] = jingle
|
self._sessions[jingle.sid] = jingle
|
||||||
|
|
|
@ -162,6 +162,46 @@ class JingleContent(object):
|
||||||
self.sent = True
|
self.sent = True
|
||||||
content.addChild(node=self.transport.make_transport())
|
content.addChild(node=self.transport.make_transport())
|
||||||
|
|
||||||
|
def _fill_content(self, content, action):
|
||||||
|
description_node = xmpp.simplexml.Node(
|
||||||
|
tag=xmpp.NS_JINGLE_FILE_TRANSFER + ' description')
|
||||||
|
|
||||||
|
if self.session.werequest:
|
||||||
|
simode = xmpp.simplexml.Node(tag='request')
|
||||||
|
else:
|
||||||
|
simode = xmpp.simplexml.Node(tag='offer')
|
||||||
|
|
||||||
|
file_tag = simode.setTag('file', namespace=xmpp.NS_FILE)
|
||||||
|
if 'name' in self.file_props:
|
||||||
|
node = xmpp.simplexml.Node(tag='name')
|
||||||
|
node.addData(self.file_props['name'])
|
||||||
|
file_tag.addChild(node=node)
|
||||||
|
if 'size' in self.file_props:
|
||||||
|
node = xmpp.simplexml.Node(tag='size')
|
||||||
|
node.addData(self.file_props['size'])
|
||||||
|
file_tag.addChild(node=node)
|
||||||
|
if 'hash' in self.file_props:
|
||||||
|
# TODO: use xep-300 for this bit
|
||||||
|
pass
|
||||||
|
desc = file_tag.setTag('desc')
|
||||||
|
if 'desc' in self.file_props:
|
||||||
|
desc.setData(self.file_props['desc'])
|
||||||
|
|
||||||
|
description_node.addChild(node=simode)
|
||||||
|
|
||||||
|
if self.use_security:
|
||||||
|
security = xmpp.simplexml.Node(
|
||||||
|
tag=xmpp.NS_JINGLE_XTLS + ' security')
|
||||||
|
# TODO: add fingerprint element
|
||||||
|
for m in ('x509', ): # supported authentication methods
|
||||||
|
method = xmpp.simplexml.Node(tag='method')
|
||||||
|
method.setAttr('name', m)
|
||||||
|
security.addChild(node=method)
|
||||||
|
content.addChild(node=security)
|
||||||
|
|
||||||
|
content.addChild(node=description_node)
|
||||||
|
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self.callbacks = None
|
self.callbacks = None
|
||||||
del self.session.contents[(self.creator, self.name)]
|
del self.session.contents[(self.creator, self.name)]
|
||||||
|
|
|
@ -132,6 +132,8 @@ class JingleFileTransfer(JingleContent):
|
||||||
return
|
return
|
||||||
h = xmpp.Hashes()
|
h = xmpp.Hashes()
|
||||||
hash_ = h.calculateHash(self.session.hash_algo, file_)
|
hash_ = h.calculateHash(self.session.hash_algo, file_)
|
||||||
|
# DEBUG
|
||||||
|
#hash_ = '1294809248109223'
|
||||||
if not hash_:
|
if not hash_:
|
||||||
# Hash alogrithm not supported
|
# Hash alogrithm not supported
|
||||||
return
|
return
|
||||||
|
@ -294,32 +296,6 @@ class JingleFileTransfer(JingleContent):
|
||||||
else:
|
else:
|
||||||
self.__state_changed(STATE_CAND_SENT, args)
|
self.__state_changed(STATE_CAND_SENT, args)
|
||||||
|
|
||||||
def _fill_content(self, content):
|
|
||||||
description_node = xmpp.simplexml.Node(
|
|
||||||
tag=xmpp.NS_JINGLE_FILE_TRANSFER + ' description')
|
|
||||||
|
|
||||||
sioffer = xmpp.simplexml.Node(tag='offer')
|
|
||||||
file_tag = sioffer.setTag('file', namespace=xmpp.NS_FILE)
|
|
||||||
file_tag.setAttr('name', self.file_props['name'])
|
|
||||||
file_tag.setAttr('size', self.file_props['size'])
|
|
||||||
desc = file_tag.setTag('desc')
|
|
||||||
if 'desc' in self.file_props:
|
|
||||||
desc.setData(self.file_props['desc'])
|
|
||||||
|
|
||||||
description_node.addChild(node=sioffer)
|
|
||||||
|
|
||||||
if self.use_security:
|
|
||||||
security = xmpp.simplexml.Node(
|
|
||||||
tag=xmpp.NS_JINGLE_XTLS + ' security')
|
|
||||||
# TODO: add fingerprint element
|
|
||||||
for m in ('x509', ): # supported authentication methods
|
|
||||||
method = xmpp.simplexml.Node(tag='method')
|
|
||||||
method.setAttr('name', m)
|
|
||||||
security.addChild(node=method)
|
|
||||||
content.addChild(node=security)
|
|
||||||
|
|
||||||
content.addChild(node=description_node)
|
|
||||||
|
|
||||||
def _store_socks5_sid(self, sid, hash_id):
|
def _store_socks5_sid(self, sid, hash_id):
|
||||||
# callback from socsk5queue.start_listener
|
# callback from socsk5queue.start_listener
|
||||||
self.file_props['hash'] = hash_id
|
self.file_props['hash'] = hash_id
|
||||||
|
|
|
@ -63,7 +63,7 @@ class JingleSession(object):
|
||||||
negotiated between an initiator and a responder.
|
negotiated between an initiator and a responder.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, con, weinitiate, jid, iq_id=None, sid=None):
|
def __init__(self, con, werequest, weinitiate, jid, iq_id=None, sid=None):
|
||||||
"""
|
"""
|
||||||
con -- connection object,
|
con -- connection object,
|
||||||
weinitiate -- boolean, are we the initiator?
|
weinitiate -- boolean, are we the initiator?
|
||||||
|
@ -83,6 +83,8 @@ class JingleSession(object):
|
||||||
self.responder = weinitiate and self.peerjid or self.ourjid
|
self.responder = weinitiate and self.peerjid or self.ourjid
|
||||||
# are we an initiator?
|
# are we an initiator?
|
||||||
self.weinitiate = weinitiate
|
self.weinitiate = weinitiate
|
||||||
|
# Are we requesting or offering a file?
|
||||||
|
self.werequest = werequest
|
||||||
# what state is session in? (one from JingleStates)
|
# what state is session in? (one from JingleStates)
|
||||||
self.state = JingleStates.ended
|
self.state = JingleStates.ended
|
||||||
if not sid:
|
if not sid:
|
||||||
|
|
|
@ -37,7 +37,6 @@ from common.protocol.bytestream import (is_transfer_active, is_transfer_paused,
|
||||||
is_transfer_stopped)
|
is_transfer_stopped)
|
||||||
from common.xmpp.protocol import NS_JINGLE_FILE_TRANSFER
|
from common.xmpp.protocol import NS_JINGLE_FILE_TRANSFER
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
log = logging.getLogger('gajim.filetransfer_window')
|
log = logging.getLogger('gajim.filetransfer_window')
|
||||||
|
|
||||||
C_IMAGE = 0
|
C_IMAGE = 0
|
||||||
|
@ -249,10 +248,14 @@ class FileTransfersWindow:
|
||||||
dialogs.ErrorDialog(_('File transfer stopped'), sectext)
|
dialogs.ErrorDialog(_('File transfer stopped'), sectext)
|
||||||
self.tree.get_selection().unselect_all()
|
self.tree.get_selection().unselect_all()
|
||||||
|
|
||||||
def show_hash_error(self, jid, file_props):
|
def show_hash_error(self, jid, file_props, account):
|
||||||
def on_yes(dummy):
|
def on_yes(dummy):
|
||||||
# TODO: Request the file to the sender
|
# Request the file to the sender
|
||||||
pass
|
sid = gajim.connections[account].start_file_transfer(jid,
|
||||||
|
file_props,
|
||||||
|
True)
|
||||||
|
file_props['sid'] = sid
|
||||||
|
|
||||||
|
|
||||||
if file_props['type'] == 'r':
|
if file_props['type'] == 'r':
|
||||||
file_name = os.path.basename(file_props['file-name'])
|
file_name = os.path.basename(file_props['file-name'])
|
||||||
|
|
|
@ -989,7 +989,7 @@ class Interface:
|
||||||
ft.show_stopped(jid, file_props,
|
ft.show_stopped(jid, file_props,
|
||||||
error_msg=_('Error opening file'))
|
error_msg=_('Error opening file'))
|
||||||
elif file_props['error'] == -10:
|
elif file_props['error'] == -10:
|
||||||
ft.show_hash_error(jid, file_props)
|
ft.show_hash_error(jid, file_props, account)
|
||||||
return
|
return
|
||||||
|
|
||||||
msg_type = ''
|
msg_type = ''
|
||||||
|
|
|
@ -1978,7 +1978,7 @@ class RosterWindow:
|
||||||
gajim.events.remove_events(account, jid, event)
|
gajim.events.remove_events(account, jid, event)
|
||||||
return True
|
return True
|
||||||
elif event.type_ == 'file-hash-error':
|
elif event.type_ == 'file-hash-error':
|
||||||
ft.show_hash_error(jid, data)
|
ft.show_hash_error(jid, data, account)
|
||||||
gajim.events.remove_events(account, jid, event)
|
gajim.events.remove_events(account, jid, event)
|
||||||
elif event.type_ == 'file-completed':
|
elif event.type_ == 'file-completed':
|
||||||
ft.show_completed(jid, data)
|
ft.show_completed(jid, data)
|
||||||
|
|
Loading…
Reference in New Issue