terminate e2e sessions (from chat and private chat) when we get an offline presence. Fixes #6956

This commit is contained in:
Yann Leboulanger 2011-08-30 14:52:59 +02:00
parent e194394479
commit 912a3fa413
2 changed files with 22 additions and 2 deletions

View File

@ -770,6 +770,8 @@ class ConnectionHandlersBase:
self._nec_iq_error_received) self._nec_iq_error_received)
gajim.ged.register_event_handler('presence-received', ged.CORE, gajim.ged.register_event_handler('presence-received', ged.CORE,
self._nec_presence_received) 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, gajim.ged.register_event_handler('message-received', ged.CORE,
self._nec_message_received) self._nec_message_received)
gajim.ged.register_event_handler('decrypted-message-received', ged.CORE, gajim.ged.register_event_handler('decrypted-message-received', ged.CORE,
@ -780,6 +782,8 @@ class ConnectionHandlersBase:
self._nec_iq_error_received) self._nec_iq_error_received)
gajim.ged.remove_event_handler('presence-received', ged.CORE, gajim.ged.remove_event_handler('presence-received', ged.CORE,
self._nec_presence_received) 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, gajim.ged.remove_event_handler('message-received', ged.CORE,
self._nec_message_received) self._nec_message_received)
gajim.ged.remove_event_handler('decrypted-message-received', ged.CORE, 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 # there won't be any sessions here if the contact terminated
# their sessions before going offline (which we do) # their sessions before going offline (which we do)
for sess in self.get_sessions(jid): 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 continue
if sess.control: if sess.control:
sess.control.no_autonegotiation = False sess.control.no_autonegotiation = False
if sess.enable_encryption:
sess.terminate_e2e()
if gajim.config.get('log_contact_status_changes') and \ if gajim.config.get('log_contact_status_changes') and \
gajim.config.should_log(self.name, obj.jid): gajim.config.should_log(self.name, obj.jid):
@ -940,6 +949,15 @@ class ConnectionHandlersBase:
self.dispatch('DB_ERROR', (pritext, sectext)) self.dispatch('DB_ERROR', (pritext, sectext))
our_jid = gajim.get_jid_from_account(self.name) 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): def _nec_message_received(self, obj):
if obj.conn.name != self.name: if obj.conn.name != self.name:
return return

View File

@ -1148,8 +1148,10 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
return xmpp.DataField(name=name, typ='hidden', value=dhs) return xmpp.DataField(name=name, typ='hidden', value=dhs)
def terminate_e2e(self): def terminate_e2e(self):
self.terminate()
self.enable_encryption = False self.enable_encryption = False
if self.control:
self.control.print_session_details()
self.terminate()
def acknowledge_termination(self): def acknowledge_termination(self):
StanzaSession.acknowledge_termination(self) StanzaSession.acknowledge_termination(self)