prevent transfer to offline contact, remove
listener when last there are no more senders
This commit is contained in:
parent
618ae1488b
commit
a51c320245
|
@ -825,6 +825,25 @@ class Connection:
|
||||||
self.dispatch('FILE_REQUEST', (jid, file_props))
|
self.dispatch('FILE_REQUEST', (jid, file_props))
|
||||||
raise common.xmpp.NodeProcessed
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
|
def _siErrorCB(self, con, iq_obj):
|
||||||
|
gajim.log.debug('_siErrorCB')
|
||||||
|
si = iq_obj.getTag('si')
|
||||||
|
profile = si.getAttr('profile')
|
||||||
|
if profile != common.xmpp.NS_FILE:
|
||||||
|
return
|
||||||
|
id = iq_obj.getAttr('id')
|
||||||
|
if not self.files_props.has_key(id):
|
||||||
|
# no such jid
|
||||||
|
return
|
||||||
|
file_props = self.files_props[id]
|
||||||
|
if file_props is None:
|
||||||
|
# file properties for jid is none
|
||||||
|
return
|
||||||
|
jid = iq_obj.getFrom().getStripped().encode('utf8')
|
||||||
|
file_props['error'] = -3
|
||||||
|
self.dispatch('FILE_REQUEST_ERROR', (jid, file_props))
|
||||||
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
def send_file_rejection(self, file_props):
|
def send_file_rejection(self, file_props):
|
||||||
''' informs sender that we refuse to download the file '''
|
''' informs sender that we refuse to download the file '''
|
||||||
iq = common.xmpp.Protocol(name = 'iq', to = str(file_props['sender']),
|
iq = common.xmpp.Protocol(name = 'iq', to = str(file_props['sender']),
|
||||||
|
@ -1261,6 +1280,8 @@ class Connection:
|
||||||
common.xmpp.NS_ROSTER)
|
common.xmpp.NS_ROSTER)
|
||||||
con.RegisterHandler('iq', self._siSetCB, 'set',
|
con.RegisterHandler('iq', self._siSetCB, 'set',
|
||||||
common.xmpp.NS_SI)
|
common.xmpp.NS_SI)
|
||||||
|
con.RegisterHandler('iq', self._siErrorCB, 'error',
|
||||||
|
common.xmpp.NS_SI)
|
||||||
con.RegisterHandler('iq', self._siResultCB, 'result',
|
con.RegisterHandler('iq', self._siResultCB, 'result',
|
||||||
common.xmpp.NS_SI)
|
common.xmpp.NS_SI)
|
||||||
con.RegisterHandler('iq', self._discoGetCB, 'get',
|
con.RegisterHandler('iq', self._discoGetCB, 'get',
|
||||||
|
|
|
@ -323,16 +323,21 @@ running instance of Gajim. \nFile Transfer will be canceled.\n==================
|
||||||
del(self.readers[idx])
|
del(self.readers[idx])
|
||||||
|
|
||||||
def remove_sender(self, idx, do_disconnect = True):
|
def remove_sender(self, idx, do_disconnect = True):
|
||||||
''' Remove reciver from the list of senders and decrease the
|
''' Remove sender from the list of senders and decrease the
|
||||||
number of active connections with 1'''
|
number of active connections with 1'''
|
||||||
if idx != -1:
|
if idx != -1:
|
||||||
if self.senders.has_key(idx):
|
if self.senders.has_key(idx):
|
||||||
if do_disconnect:
|
if do_disconnect:
|
||||||
self.senders[idx].disconnect()
|
self.senders[idx].disconnect()
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
del(self.senders[idx])
|
del(self.senders[idx])
|
||||||
if self.connected > 0:
|
if self.connected > 0:
|
||||||
self.connected -= 1
|
self.connected -= 1
|
||||||
|
if len(self.senders) == 0 and self.listener is not None:
|
||||||
|
self.listener.disconnect()
|
||||||
|
self.listener = None
|
||||||
|
self.connected -= 1
|
||||||
|
|
||||||
class Socks5:
|
class Socks5:
|
||||||
def __init__(self, host, port, initiator, target, sid):
|
def __init__(self, host, port, initiator, target, sid):
|
||||||
|
@ -712,7 +717,7 @@ class Socks5Sender(Socks5):
|
||||||
self.file_props['disconnect_cb'] = None
|
self.file_props['disconnect_cb'] = None
|
||||||
if self.queue is not None:
|
if self.queue is not None:
|
||||||
self.queue.remove_sender(self.queue_idx, False)
|
self.queue.remove_sender(self.queue_idx, False)
|
||||||
|
|
||||||
class Socks5Listener:
|
class Socks5Listener:
|
||||||
def __init__(self, host, port):
|
def __init__(self, host, port):
|
||||||
self.host, self.port = host, port
|
self.host, self.port = host, port
|
||||||
|
@ -735,6 +740,12 @@ class Socks5Listener:
|
||||||
return None
|
return None
|
||||||
self.started = True
|
self.started = True
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
try:
|
||||||
|
self._serv.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def accept_conn(self):
|
def accept_conn(self):
|
||||||
_sock = self._serv.accept()
|
_sock = self._serv.accept()
|
||||||
_sock[0].setblocking(False)
|
_sock[0].setblocking(False)
|
||||||
|
|
Loading…
Reference in New Issue