comparison src/browser/sat_browser/plugin_sec_otr.py @ 624:9092e624bb27 frontends_multi_profiles

browser_side: fixes various issues
author souliane <souliane@mailoo.org>
date Sun, 22 Feb 2015 21:51:20 +0100
parents 1c0d5a87c554
children ebb602d8b3f2
comparison
equal deleted inserted replaced
623:4f7550a083b4 624:9092e624bb27
262 else: 262 else:
263 log.error("FIXME: unmanaged ambiguous 'act' value in Context.smpAuthCb!") 263 log.error("FIXME: unmanaged ambiguous 'act' value in Context.smpAuthCb!")
264 title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer) 264 title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer)
265 if type_ == 'question': 265 if type_ == 'question':
266 if act == 'asked': 266 if act == 'asked':
267 def cb(question, answer=None): 267 def cb(result, question, answer=None):
268 if question is False or not answer: # dialog cancelled or the answer is empty 268 if not result or not answer: # dialog cancelled or the answer is empty
269 return 269 return
270 self.smpAuthSecret(answer, question) 270 self.smpAuthSecret(answer, question)
271 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_DEFINE_TXT + "</i>" + AUTH_QUEST_DEFINE).format(eol=DIALOG_EOL) 271 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_DEFINE_TXT + "</i>" + AUTH_QUEST_DEFINE).format(eol=DIALOG_EOL)
272 dialog.PromptDialog(cb, [text, AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show() 272 dialog.PromptDialog(cb, [text, AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show()
273 else: 273 else:
274 def cb(answer): 274 def cb(result, answer):
275 if not answer: # dialog cancelled or the answer is empty 275 if not result or not answer: # dialog cancelled or the answer is empty
276 self.smpAuthAbort('answered') 276 self.smpAuthAbort('answered')
277 return 277 return
278 self.smpAuthSecret(answer) 278 self.smpAuthSecret(answer)
279 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data) 279 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data)
280 dialog.PromptDialog(cb, text + AUTH_SECRET_INPUT.format(eol=DIALOG_EOL), title=title, AddStyleName="maxWidthLimit").show() 280 dialog.PromptDialog(cb, [text + AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show()
281 elif type_ == 'trust': 281 elif type_ == 'trust':
282 self.setCurrentTrust('smp' if data else '', act) 282 self.setCurrentTrust('smp' if data else '', act)
283 elif type_ == 'abort': 283 elif type_ == 'abort':
284 self.setCurrentTrust('', act, 'abort') 284 self.setCurrentTrust('', act, 'abort')
285 285
342 @return: Context 342 @return: Context
343 """ 343 """
344 log.debug(u"getContextForUser [%s]" % other_jid) 344 log.debug(u"getContextForUser [%s]" % other_jid)
345 if not other_jid.resource: 345 if not other_jid.resource:
346 log.error("getContextForUser called with a bare jid") 346 log.error("getContextForUser called with a bare jid")
347 running_sessions = [jid_.bareJID() for jid_ in self.contexts.keys() if self.contexts[jid_].state == otr.context.STATE_ENCRYPTED] 347 running_sessions = [jid_.bare for jid_ in self.contexts.keys() if self.contexts[jid_].state == otr.context.STATE_ENCRYPTED]
348 if start or (other_jid in running_sessions): 348 if start or (other_jid in running_sessions):
349 users_ml = DIALOG_USERS_ML.format(subject=D_("OTR issue in Libervia: getContextForUser called with a bare jid in an encrypted context")) 349 users_ml = DIALOG_USERS_ML.format(subject=D_("OTR issue in Libervia: getContextForUser called with a bare jid in an encrypted context"))
350 text = RESOURCE_ISSUE.format(eol=DIALOG_EOL, jid=other_jid, users_ml=users_ml) 350 text = RESOURCE_ISSUE.format(eol=DIALOG_EOL, jid=other_jid, users_ml=users_ml)
351 dialog.InfoDialog(RESOURCE_ISSUE_TITLE, text, AddStyleName="maxWidthLimit").show() 351 dialog.InfoDialog(RESOURCE_ISSUE_TITLE, text, AddStyleName="maxWidthLimit").show()
352 return None # never start an OTR session with a bare JID 352 return None # never start an OTR session with a bare JID
483 return True 483 return True
484 self.fixResource(to_jid, cb) 484 self.fixResource(to_jid, cb)
485 return False # interrupt the main process 485 return False # interrupt the main process
486 486
487 def presenceReceivedTrigger(self, entity, show, priority, statuses): 487 def presenceReceivedTrigger(self, entity, show, priority, statuses):
488 if show == "unavailable": 488 if show == C.PRESENCE_UNAVAILABLE:
489 self.endSession(entity, finish=True) 489 self.endSession(entity, finish=True)
490 return True 490 return True
491 491
492 def endSession(self, other_jid, profile, finish=False): 492 def endSession(self, other_jid, profile, finish=False):
493 """Finish or disconnect an OTR session 493 """Finish or disconnect an OTR session
540 else: # on query reception we ask always, if we initiate we just ask the first time 540 else: # on query reception we ask always, if we initiate we just ask the first time
541 query(jid_) 541 query(jid_)
542 542
543 try: 543 try:
544 other_jid = menu_data['jid'] 544 other_jid = menu_data['jid']
545 if other_jid.bare not in self.host.contact_panel.connected: 545 contact_list = self.host.contact_list
546 if contact_list.getCache(other_jid.bare, C.PRESENCE_SHOW) is None:
546 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show() 547 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show()
547 return 548 return
548 self.fixResource(other_jid, cb) 549 self.fixResource(other_jid, cb)
549 except KeyError: 550 except KeyError:
550 log.error(_("jid key is not present !")) 551 log.error(_("jid key is not present !"))