plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection

This commit is contained in:
souliane 2014-09-05 11:16:38 +02:00
commit af2554a508
2 changed files with 21 additions and 0 deletions

View file

@ -328,6 +328,10 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
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 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
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)

View file

@ -120,6 +120,11 @@ class Context(potr.context.Context):
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 @@ class OTR(object):
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 @@ class OTR(object):
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