send correct error message when we decline a FT, and print error message when we get it. Fixes #2330

This commit is contained in:
Yann Leboulanger 2006-09-14 12:19:40 +00:00
parent 5764374e5d
commit e18e1079a9
4 changed files with 25 additions and 15 deletions

View file

@ -90,7 +90,7 @@ class ConnectionBytestream:
if contact.jid == receiver_jid: if contact.jid == receiver_jid:
file_props['error'] = -5 file_props['error'] = -5
self.remove_transfer(file_props) self.remove_transfer(file_props)
self.dispatch('FILE_REQUEST_ERROR', (contact.jid, file_props)) self.dispatch('FILE_REQUEST_ERROR', (contact.jid, file_props, ''))
sender_jid = unicode(file_props['sender']).split('/')[0] sender_jid = unicode(file_props['sender']).split('/')[0]
if contact.jid == sender_jid: if contact.jid == sender_jid:
file_props['error'] = -3 file_props['error'] = -3
@ -179,7 +179,8 @@ class ConnectionBytestream:
sha_str, self._result_socks5_sid, file_props['sid']) sha_str, self._result_socks5_sid, file_props['sid'])
if listener == None: if listener == None:
file_props['error'] = -5 file_props['error'] = -5
self.dispatch('FILE_REQUEST_ERROR', (unicode(receiver), file_props)) self.dispatch('FILE_REQUEST_ERROR', (unicode(receiver), file_props,
''))
self._connect_error(unicode(receiver), file_props['sid'], self._connect_error(unicode(receiver), file_props['sid'],
file_props['sid'], code = 406) file_props['sid'], code = 406)
return return
@ -221,8 +222,8 @@ class ConnectionBytestream:
iq = common.xmpp.Protocol(name = 'iq', iq = common.xmpp.Protocol(name = 'iq',
to = unicode(file_props['sender']), typ = 'error') to = unicode(file_props['sender']), typ = 'error')
iq.setAttr('id', file_props['request-id']) iq.setAttr('id', file_props['request-id'])
err = common.xmpp.ErrorNode(code = '406', typ = 'auth', name = err = common.xmpp.ErrorNode(code = '403', typ = 'cancel', name =
'not-acceptable') 'forbidden', text = 'Offer Declined')
iq.addChild(node=err) iq.addChild(node=err)
self.connection.send(iq) self.connection.send(iq)
@ -314,8 +315,8 @@ class ConnectionBytestream:
if file_props is not None: if file_props is not None:
self.disconnect_transfer(file_props) self.disconnect_transfer(file_props)
file_props['error'] = -3 file_props['error'] = -3
self.dispatch('FILE_REQUEST_ERROR', (to, file_props)) self.dispatch('FILE_REQUEST_ERROR', (to, file_props, msg))
def _proxy_auth_ok(self, proxy): def _proxy_auth_ok(self, proxy):
'''cb, called after authentication to proxy server ''' '''cb, called after authentication to proxy server '''
file_props = self.files_props[proxy['sid']] file_props = self.files_props[proxy['sid']]
@ -344,7 +345,7 @@ class ConnectionBytestream:
return return
file_props = self.files_props[id] file_props = self.files_props[id]
file_props['error'] = -4 file_props['error'] = -4
self.dispatch('FILE_REQUEST_ERROR', (jid, file_props)) self.dispatch('FILE_REQUEST_ERROR', (jid, file_props, ''))
raise common.xmpp.NodeProcessed raise common.xmpp.NodeProcessed
def _bytestreamSetCB(self, con, iq_obj): def _bytestreamSetCB(self, con, iq_obj):
@ -561,7 +562,7 @@ class ConnectionBytestream:
return return
jid = helpers.get_jid_from_iq(iq_obj) jid = helpers.get_jid_from_iq(iq_obj)
file_props['error'] = -3 file_props['error'] = -3
self.dispatch('FILE_REQUEST_ERROR', (jid, file_props)) self.dispatch('FILE_REQUEST_ERROR', (jid, file_props, ''))
raise common.xmpp.NodeProcessed raise common.xmpp.NodeProcessed
class ConnectionDisco: class ConnectionDisco:
@ -1133,7 +1134,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
raise common.xmpp.NodeProcessed raise common.xmpp.NodeProcessed
def _ErrorCB(self, con, iq_obj): def _ErrorCB(self, con, iq_obj):
errmsg = iq_obj.getError() errmsg = iq_obj.getErrorMsg()
errcode = iq_obj.getErrorCode() errcode = iq_obj.getErrorCode()
jid_from = helpers.get_full_jid_from_iq(iq_obj) jid_from = helpers.get_full_jid_from_iq(iq_obj)
id = unicode(iq_obj.getID()) id = unicode(iq_obj.getID())

View file

@ -348,6 +348,13 @@ class Protocol(Node):
for tag in errtag.getChildren(): for tag in errtag.getChildren():
if tag.getName()<>'text': return tag.getName() if tag.getName()<>'text': return tag.getName()
return errtag.getData() return errtag.getData()
def getErrorMsg(self):
""" Return the textual description of the error (if present) or the error condition """
errtag=self.getTag('error')
if errtag:
for tag in errtag.getChildren():
if tag.getName()=='text': return tag.getData()
return self.getError()
def getErrorCode(self): def getErrorCode(self):
""" Return the error code. Obsolette. """ """ Return the error code. Obsolette. """
return self.getTagAttr('error','code') return self.getTagAttr('error','code')

View file

@ -213,7 +213,7 @@ class FileTransfersWindow:
_('Connection with peer cannot be established.')) _('Connection with peer cannot be established.'))
self.tree.get_selection().unselect_all() self.tree.get_selection().unselect_all()
def show_stopped(self, jid, file_props): def show_stopped(self, jid, file_props, error_msg = ''):
self.window.present() self.window.present()
self.window.window.focus() self.window.window.focus()
if file_props['type'] == 'r': if file_props['type'] == 'r':
@ -222,6 +222,8 @@ _('Connection with peer cannot be established.'))
file_name = file_props['name'] file_name = file_props['name']
sectext = '\t' + _('Filename: %s') % file_name sectext = '\t' + _('Filename: %s') % file_name
sectext += '\n\t' + _('Recipient: %s') % jid sectext += '\n\t' + _('Recipient: %s') % jid
if error_msg:
sectext += '\n\t' + _('Error message: %s') % error_msg
dialogs.ErrorDialog(_('File transfer stopped by the contact of the other side'), \ dialogs.ErrorDialog(_('File transfer stopped by the contact of the other side'), \
sectext) sectext)
self.tree.get_selection().unselect_all() self.tree.get_selection().unselect_all()

View file

@ -273,7 +273,7 @@ class Interface:
on_response_no = (response, account, data[3], 'no')) on_response_no = (response, account, data[3], 'no'))
def handle_event_error_answer(self, account, array): def handle_event_error_answer(self, account, array):
#('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode)) #('ERROR_ANSWER', account, (id, jid_from, errmsg, errcode))
id, jid_from, errmsg, errcode = array id, jid_from, errmsg, errcode = array
if unicode(errcode) in ('403', '406') and id: if unicode(errcode) in ('403', '406') and id:
# show the error dialog # show the error dialog
@ -285,7 +285,7 @@ class Interface:
file_props = ft.files_props['s'][sid] file_props = ft.files_props['s'][sid]
file_props['error'] = -4 file_props['error'] = -4
self.handle_event_file_request_error(account, self.handle_event_file_request_error(account,
(jid_from, file_props)) (jid_from, file_props, errmsg))
conn = gajim.connections[account] conn = gajim.connections[account]
conn.disconnect_transfer(file_props) conn.disconnect_transfer(file_props)
return return
@ -1169,15 +1169,15 @@ class Interface:
self.roster.draw_contact(jid, account) self.roster.draw_contact(jid, account)
def handle_event_file_request_error(self, account, array): def handle_event_file_request_error(self, account, array):
jid = array[0] # ('FILE_REQUEST_ERROR', account, (jid, file_props, error_msg))
file_props = array[1] jid, file_props, errmsg = array
ft = self.instances['file_transfers'] ft = self.instances['file_transfers']
ft.set_status(file_props['type'], file_props['sid'], 'stop') ft.set_status(file_props['type'], file_props['sid'], 'stop')
errno = file_props['error'] errno = file_props['error']
if helpers.allow_popup_window(account): if helpers.allow_popup_window(account):
if errno in (-4, -5): if errno in (-4, -5):
ft.show_stopped(jid, file_props) ft.show_stopped(jid, file_props, errmsg)
else: else:
ft.show_request_error(file_props) ft.show_request_error(file_props)
return return