From c1e71508c47601202660c743c17bbbf0f9f92cf1 Mon Sep 17 00:00:00 2001 From: souliane Date: Fri, 5 Sep 2014 11:01:14 +0200 Subject: [PATCH] plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection --- src/plugins/plugin_sec_otr.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/plugin_sec_otr.py b/src/plugins/plugin_sec_otr.py index 7b1abe21..c0375dec 100644 --- a/src/plugins/plugin_sec_otr.py +++ b/src/plugins/plugin_sec_otr.py @@ -115,6 +115,11 @@ class Context(potr.context.Context): 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) @@ -239,6 +244,12 @@ class OTR(object): ctxMng.account.loadTrusts() 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: @@ -371,8 +382,7 @@ class OTR(object): 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()}