Mercurial > libervia-backend
changeset 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 |
files | src/core/xmpp.py src/plugins/plugin_sec_otr.py |
diffstat | 2 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/xmpp.py Fri Sep 05 11:01:14 2014 +0200 +++ b/src/core/xmpp.py Fri Sep 05 11:16:38 2014 +0200 @@ -328,6 +328,10 @@ int(priority), statuses, self.parent.profile) + # uncomment these two lines if you need the trigger + #if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile): + # return + # now it's time to notify frontends self.host.bridge.presenceUpdate(entity.full(), show or "", int(priority), statuses, @@ -344,6 +348,9 @@ del statuses[None] self.host.memory.setPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile) + if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile): + return + # now it's time to notify frontends self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile)
--- 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