From 912a3fa41323a6f8df606d449386a94b86b2c8af Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 30 Aug 2011 14:52:59 +0200 Subject: [PATCH] terminate e2e sessions (from chat and private chat) when we get an offline presence. Fixes #6956 --- src/common/connection_handlers.py | 20 +++++++++++++++++++- src/common/stanza_session.py | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 482a2edae..e5db8b2a4 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -770,6 +770,8 @@ class ConnectionHandlersBase: self._nec_iq_error_received) gajim.ged.register_event_handler('presence-received', ged.CORE, self._nec_presence_received) + gajim.ged.register_event_handler('gc-presence-received', ged.CORE, + self._nec_gc_presence_received) gajim.ged.register_event_handler('message-received', ged.CORE, self._nec_message_received) gajim.ged.register_event_handler('decrypted-message-received', ged.CORE, @@ -780,6 +782,8 @@ class ConnectionHandlersBase: self._nec_iq_error_received) gajim.ged.remove_event_handler('presence-received', ged.CORE, self._nec_presence_received) + gajim.ged.remove_event_handler('gc-presence-received', ged.CORE, + self._nec_gc_presence_received) gajim.ged.remove_event_handler('message-received', ged.CORE, self._nec_message_received) gajim.ged.remove_event_handler('decrypted-message-received', ged.CORE, @@ -921,10 +925,15 @@ class ConnectionHandlersBase: # there won't be any sessions here if the contact terminated # their sessions before going offline (which we do) for sess in self.get_sessions(jid): - if obj.fjid != str(sess.jid): + sess_fjid = str(sess.jid) + if sess.resource: + sess_fjid += '/' + sess.resource + if obj.fjid != sess_fjid: continue if sess.control: sess.control.no_autonegotiation = False + if sess.enable_encryption: + sess.terminate_e2e() if gajim.config.get('log_contact_status_changes') and \ gajim.config.should_log(self.name, obj.jid): @@ -940,6 +949,15 @@ class ConnectionHandlersBase: self.dispatch('DB_ERROR', (pritext, sectext)) our_jid = gajim.get_jid_from_account(self.name) + def _nec_gc_presence_received(self, obj): + if obj.conn.name != self.name: + return + for sess in self.get_sessions(obj.fjid): + if obj.fjid != sess.jid: + continue + if sess.enable_encryption: + sess.terminate_e2e() + def _nec_message_received(self, obj): if obj.conn.name != self.name: return diff --git a/src/common/stanza_session.py b/src/common/stanza_session.py index 34fcd979f..3cceec8c6 100644 --- a/src/common/stanza_session.py +++ b/src/common/stanza_session.py @@ -1148,8 +1148,10 @@ class EncryptedStanzaSession(ArchivingStanzaSession): return xmpp.DataField(name=name, typ='hidden', value=dhs) def terminate_e2e(self): - self.terminate() self.enable_encryption = False + if self.control: + self.control.print_session_details() + self.terminate() def acknowledge_termination(self): StanzaSession.acknowledge_termination(self)