fix error reply when S5B cannot be established. Fixes #8315

This commit is contained in:
Yann Leboulanger 2016-03-28 20:52:24 +02:00
parent eba838bdac
commit 8a3d743b6f
1 changed files with 12 additions and 15 deletions

View File

@ -364,8 +364,8 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
from common.connection_handlers_events import FileRequestErrorEvent
gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self,
jid=receiver, file_props=file_props, error_msg=''))
self._connect_error(receiver, file_props.sid,
file_props.sid, code=406)
self._connect_error(file_props.sid, error='not-acceptable',
error_type='modify')
else:
iq = nbxmpp.Iq(to=receiver, typ='set')
file_props.request_id = 'id_' + file_props.sid
@ -557,7 +557,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
file_props.hash_ = hash_id
return
def _connect_error(self,sid, code=404):
def _connect_error(self, sid, error, error_type, msg=None):
"""
Called when there is an error establishing BS connection, or when
connection is rejected
@ -568,23 +568,17 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
if file_props is None:
log.error('can not send iq error on failed transfer')
return
msg_dict = {
404: 'Could not connect to given hosts',
405: 'Cancel',
406: 'Not acceptable',
}
msg = msg_dict[code]
if file_props.type_ == 's':
to = file_props.receiver
else:
to = file_props.sender
iq = nbxmpp.Iq(to=to, typ='error')
iq.setAttr('id', file_props.sid)
iq = nbxmpp.Iq(to=to, typ='error')
iq.setAttr('id', file_props.request_id)
err = iq.setTag('error')
err.setAttr('code', str(code))
err.setData(msg)
err.setAttr('type', error_type)
err.setTag(error, namespace=nbxmpp.NS_STANZAS)
self.connection.send(iq)
if code == 404:
if msg:
self.disconnect_transfer(file_props)
file_props.error = -3
from common.connection_handlers_events import \
@ -667,9 +661,12 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
raise nbxmpp.NodeProcessed
file_props.streamhosts = streamhosts
def _connection_error(sid):
self._connect_error(sid, 'item-not-found', 'cancel',
msg='Could not connect to given hosts')
if file_props.type_ == 'r':
gajim.socks5queue.connect_to_hosts(self.name, sid,
self.send_success_connect_reply, self._connect_error)
self.send_success_connect_reply, _connection_error)
raise nbxmpp.NodeProcessed
def _ResultCB(self, con, iq_obj):