changeset 1169:a3354063dfb6

plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
author souliane <souliane@mailoo.org>
date Fri, 05 Sep 2014 11:01:14 +0200
parents 39572f9d5249
children 2df6427a5299
files src/plugins/plugin_sec_otr.py
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_sec_otr.py	Fri Sep 05 10:39:06 2014 +0200
+++ b/src/plugins/plugin_sec_otr.py	Fri Sep 05 11:01:14 2014 +0200
@@ -115,6 +115,11 @@
                                     profile=client.profile)
         # TODO: send signal to frontends
 
+    def disconnect(self):
+        """Disconnect the session."""
+        if self.state != potr.context.STATE_PLAINTEXT:
+            super(Context, self).disconnect()
+
 
 class Account(potr.context.Account):
     #TODO: manage trusted keys: if a fingerprint is not used anymore, we have no way to remove it from database yet (same thing for a correspondent jid)
@@ -240,6 +245,12 @@
 
     def profileDisconnected(self, profile):
         try:
+            for context in self.context_managers[profile].contexts.values():
+                context.disconnect()
+            del self.context_managers[profile]
+        except KeyError:
+            pass
+        try:
             self.skipped_profiles.remove(profile)
         except KeyError:
             pass
@@ -371,8 +382,7 @@
             if C.bool(data['answer']):
                 # we end all sessions
                 for context in ctxMng.contexts.values():
-                    if context.state not in (potr.context.STATE_FINISHED, potr.context.STATE_PLAINTEXT):
-                        context.disconnect()
+                    context.disconnect()
                 ctxMng.account.privkey = None
                 ctxMng.account.getPrivkey()  # as account.privkey is None, getPrivkey will generate a new key, and save it
                 return {'xmlui': xml_tools.note(_("Your private key has been dropped")).toXml()}