Author: asterix
Date: 2008-11-28 16:34:56 +0100 (Fri, 28 Nov 2008)
New Revision: 10714
Modified:
trunk/src/common/zeroconf/client_zeroconf.py
trunk/src/common/zeroconf/connection_zeroconf.py
trunk/src/gajim.py
Log:
better handling of sessions in zeroconf. Fixes #4529
Modified: trunk/src/common/zeroconf/client_zeroconf.py
===================================================================
--- trunk/src/common/zeroconf/client_zeroconf.py 2008-11-28 14:51:23 UTC (rev 10713)
+++ trunk/src/common/zeroconf/client_zeroconf.py 2008-11-28 15:34:56 UTC (rev 10714)
@@ -164,10 +164,11 @@
if on_not_ok:
on_not_ok('Connection to host could not be established.')
return
- if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
- self.conn_holder.number_of_awaiting_messages[self.fd] += 1
+ id = stanza.getThread()
+ if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
+ self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
else:
- self.conn_holder.number_of_awaiting_messages[self.fd] = 1
+ self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
def add_stanza(self, stanza, is_message=False):
if self.Connection:
@@ -178,15 +179,16 @@
self.stanzaqueue.append((stanza, is_message))
if is_message:
- if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
- self.conn_holder.number_of_awaiting_messages[self.fd] += 1
+ id = stanza.getThread()
+ if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
+ self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
else:
- self.conn_holder.number_of_awaiting_messages[self.fd] = 1
+ self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
return True
def on_message_sent(self, connection_id):
- self.conn_holder.number_of_awaiting_messages[connection_id] -= 1
+ self.conn_holder.ids_of_awaiting_messages[connection_id].pop(0)
def on_connect(self, conn):
self.Connection = conn
@@ -245,8 +247,8 @@
def on_disconnect(self):
if self.conn_holder:
- if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
- del self.conn_holder.number_of_awaiting_messages[self.fd]
+ if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
+ del self.conn_holder.ids_of_awaiting_messages[self.fd]
self.conn_holder.remove_connection(self.sock_hash)
if self.__dict__.has_key('Dispatcher'):
self.Dispatcher.PlugOut()
@@ -402,11 +404,11 @@
self._plug_idle()
def read_timeout(self):
- if self.client.conn_holder.number_of_awaiting_messages.has_key(self.fd) \
- and self.client.conn_holder.number_of_awaiting_messages[self.fd] > 0:
- self.client._caller.dispatch('MSGERROR',[unicode(self.client.to), -1,
- _('Connection to host could not be established: Timeout while sending data.'), None, None])
- self.client.conn_holder.number_of_awaiting_messages[self.fd] = 0
+ ids = self.client.conn_holder.ids_of_awaiting_messages
+ if self.fd in ids and len(ids[self.fd]) > 0:
+ for id in ids[self.fd]:
+ self._owner.Dispatcher.Event('', DATA_ERROR, (self.client.to, id))
+ ids[self.fd] = []
self.pollend()
def do_connect(self):
@@ -577,7 +579,7 @@
self.ip_to_hash = {}
self.hash_to_port = {}
self.listener = None
- self.number_of_awaiting_messages = {}
+ self.ids_of_awaiting_messages = {}
def connect(self, show, msg):
self.port = self.start_listener(self.caller.port)
Modified: trunk/src/common/zeroconf/connection_zeroconf.py
===================================================================
--- trunk/src/common/zeroconf/connection_zeroconf.py 2008-11-28 14:51:23 UTC (rev 10713)
+++ trunk/src/common/zeroconf/connection_zeroconf.py 2008-11-28 15:34:56 UTC (rev 10714)
@@ -376,7 +376,9 @@
return
if self.status in ('invisible', 'offline'):
- self.dispatch('MSGERROR', [unicode(jid), '-1', _('You are not connected or not visible to others. Your message could not be sent.'), None, None])
+ self.dispatch('MSGERROR', [unicode(jid), -1,
+ _('You are not connected or not visible to others. Your message '
+ 'could not be sent.'), None, None, session])
return
msgtxt = msg
@@ -475,13 +477,13 @@
def on_send_not_ok(reason):
reason += ' ' + _('Your message could not be sent.')
- self.dispatch('MSGERROR', [jid, '-1', reason, None, None, session])
+ self.dispatch('MSGERROR', [jid, -1, reason, None, None, session])
ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
on_not_ok=on_send_not_ok)
if ret == -1:
# Contact Offline
- self.dispatch('MSGERROR', [jid, '-1', _('Contact is offline. Your message could not be sent.'), None, None, session])
+ self.dispatch('MSGERROR', [jid, -1, _('Contact is offline. Your message could not be sent.'), None, None, session])
return ret
def send_stanza(self, stanza):
@@ -573,6 +575,13 @@
self.dispatch('STANZA_ARRIVED', unicode(data, errors = 'ignore'))
elif event == common.xmpp.transports.DATA_SENT:
self.dispatch('STANZA_SENT', unicode(data))
+ elif event == common.xmpp.transports.DATA_ERROR:
+ thread_id = data[1]
+ frm = unicode(data[0])
+ session = self.get_or_create_session(frm, thread_id)
+ self.dispatch('MSGERROR', [frm, -1,
+ _('Connection to host could not be established: Timeout while '
+ 'sending data.'), None, None, session])
# END ConnectionZeroconf
Modified: trunk/src/gajim.py
===================================================================
--- trunk/src/gajim.py 2008-11-28 14:51:23 UTC (rev 10713)
+++ trunk/src/gajim.py 2008-11-28 15:34:56 UTC (rev 10714)
@@ -947,7 +947,8 @@
if array[3]:
msg = _('error while sending %(message)s ( %(error)s )') % {
'message': array[3], 'error': msg}
- array[5].roster_message(jid, msg, array[4], msg_type='error')
+ if session:
+ session.roster_message(jid, msg, array[4], msg_type='error')
def handle_event_msgsent(self, account, array):
#('MSGSENT', account, (jid, msg, keyID))