Mercurial > libervia-backend
diff src/plugins/plugin_sec_otr.py @ 1170:2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 05 Sep 2014 11:16:38 +0200 |
parents | a3354063dfb6 |
children | 0abce7f17782 |
line wrap: on
line diff
--- a/src/plugins/plugin_sec_otr.py Fri Sep 05 11:01:14 2014 +0200 +++ b/src/plugins/plugin_sec_otr.py Fri Sep 05 11:16:38 2014 +0200 @@ -120,6 +120,11 @@ if self.state != potr.context.STATE_PLAINTEXT: super(Context, self).disconnect() + def finish(self): + """Finish the session - avoid to send any message but the user still has to end the session himself.""" + if self.state == potr.context.STATE_ENCRYPTED: + self.processTLVs([potr.proto.DisconnectTLV()]) + 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) @@ -203,6 +208,7 @@ host.importMenu((MAIN_MENU, D_("End session")), self._endSession, security_limit=0, help_string=D_("Finish an OTR session"), type_=C.MENU_SINGLE) host.importMenu((MAIN_MENU, D_("Authenticate")), self._authenticate, security_limit=0, help_string=D_("Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE) host.importMenu((MAIN_MENU, D_("Drop private key")), self._dropPrivKey, security_limit=0, type_=C.MENU_SINGLE) + host.trigger.add("presenceReceived", self.presenceReceivedTrigger) def _fixPotr(self): # FIXME: potr fix for bad unicode handling @@ -457,3 +463,11 @@ log.debug(u"sending message unencrypted") return True + def presenceReceivedTrigger(self, entity, show, priority, statuses, profile): + if show != "unavailable": + return + if not entity.resource: + entity.resource = self.host.memory.getLastResource(entity, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored + otrctx = self.context_managers[profile].getContextForUser(entity) + otrctx.disconnect() + return True