From e8b7778521a04e1adb99bd1e611c6a42365d5ff1 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 5 Feb 2008 14:50:21 +0000 Subject: [PATCH] detect jabber:iq:last and jabber:iq:version errors by IDs. fixes #3711 --- src/common/connection.py | 2 ++ src/common/connection_handlers.py | 22 +++++++++++++++++----- src/gajim.py | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 9606afc36..7d731e868 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1257,6 +1257,7 @@ class Connection(ConnectionHandlers): iq.setID(id) if groupchat_jid: self.groupchat_jids[id] = groupchat_jid + self.last_ids.append(id) self.connection.send(iq) def request_os_info(self, jid, resource, groupchat_jid=None): @@ -1277,6 +1278,7 @@ class Connection(ConnectionHandlers): iq.setID(id) if groupchat_jid: self.groupchat_jids[id] = groupchat_jid + self.version_ids.append(id) self.connection.send(iq) def get_settings(self): diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 375279b51..c984335e3 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1239,6 +1239,10 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, # keep the latest subscribed event for each jid to prevent loop when we # acknoledge presences self.subscribed_events = {} + # IDs of jabber:iq:last requests + self.last_ids = [] + # IDs of jabber:iq:version requests + self.version_ids = [] # keep track of sessions this connection has with other JIDs self.sessions = {} @@ -1297,15 +1301,19 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, def _ErrorCB(self, con, iq_obj): gajim.log.debug('ErrorCB') - if iq_obj.getQueryNS() == common.xmpp.NS_VERSION: - who = helpers.get_full_jid_from_iq(iq_obj) - jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who) + jid_from = helpers.get_full_jid_from_iq(iq_obj) + jid_stripped, resource = gajim.get_room_and_nick_from_fjid(jid_from) + id = unicode(iq_obj.getID()) + if id in self.version_ids: self.dispatch('OS_INFO', (jid_stripped, resource, '', '')) + self.version_ids.remove(id) + return + if id in self.last_ids: + self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, -1, '')) + self.last_ids.remove(id) return errmsg = iq_obj.getErrorMsg() errcode = iq_obj.getErrorCode() - jid_from = helpers.get_full_jid_from_iq(iq_obj) - id = unicode(iq_obj.getID()) self.dispatch('ERROR_ANSWER', (id, jid_from, errmsg, errcode)) def _PrivateCB(self, con, iq_obj): @@ -1420,6 +1428,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, del self.groupchat_jids[id] else: who = helpers.get_full_jid_from_iq(iq_obj) + if id in self.last_ids: + self.last_ids.remove(id) jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who) self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, seconds, status)) @@ -1441,6 +1451,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, else: who = helpers.get_full_jid_from_iq(iq_obj) jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who) + if id in self.version_ids: + self.version_ids.remove(id) self.dispatch('OS_INFO', (jid_stripped, resource, client_info, os_info)) def _TimeCB(self, con, iq_obj): diff --git a/src/gajim.py b/src/gajim.py index ad64b9b52..0b479a192 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1124,6 +1124,10 @@ class Interface: def handle_event_last_status_time(self, account, array): # ('LAST_STATUS_TIME', account, (jid, resource, seconds, status)) + tim = array[2] + if tim < 0: + # Ann error occured + return win = None if self.instances[account]['infos'].has_key(array[0]): win = self.instances[account]['infos'][array[0]] @@ -1132,7 +1136,7 @@ class Interface: if win: c = gajim.contacts.get_contact(account, array[0], array[1]) if c: # c can be none if it's a gc contact - c.last_status_time = time.localtime(time.time() - array[2]) + c.last_status_time = time.localtime(time.time() - tim) if array[3]: c.status = array[3] win.set_last_status_time()