Mercurial > libervia-web
diff src/browser/sat_browser/plugin_sec_otr.py @ 589:a5019e62c3e9 frontends_multi_profiles
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
/!\ not finished, partially working and highly instable
- add collections module with an OrderedDict like class
- SatWebFrontend inherit from QuickApp
- general sat_frontends tools.jid module is used
- bridge/json methods have moved to json module
- UniBox is partially removed (should be totally removed before merge to trunk)
- Signals are now register with the generic registerSignal method (which is called mainly in QuickFrontend)
- the generic getOrCreateWidget method from QuickWidgetsManager is used instead of Libervia's specific methods
- all Widget are now based more or less directly on QuickWidget
- with the new QuickWidgetsManager.getWidgets method, it's no more necessary to check all widgets which are instance of a particular class
- ChatPanel and related moved to chat module
- MicroblogPanel and related moved to blog module
- global and overcomplicated send method has been disabled: each class should manage its own sending
- for consistency with other frontends, former ContactPanel has been renamed to ContactList and vice versa
- for the same reason, ChatPanel has been renamed to Chat
- for compatibility with QuickFrontend, a fake profile is used in several places, it is set to C.PROF_KEY_NONE (real profile is managed server side for obvious security reasons)
- changed default url for web panel to SàT website, and contact address to generic SàT contact address
- ContactList is based on QuickContactList, UI changes are done in update method
- bride call (now json module) have been greatly improved, in particular call can be done in the same way as for other frontends (bridge.method_name(arg1, arg2, ..., callback=cb, errback=eb). Blocking method must be called like async methods due to javascript architecture
- in bridge calls, a callback can now exists without errback
- hard reload on BridgeSignals remote error has been disabled, a better option should be implemented
- use of constants where that make sens, some style improvments
- avatars are temporarily disabled
- lot of code disabled, will be fixed or removed before merge
- various other changes, check diff for more details
server side: manage remote exception on getEntityData, removed getProfileJid call, added getWaitingConf, added getRoomsSubjects
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 24 Jan 2015 01:45:39 +0100 |
parents | 0a06cf833f5a |
children | 1c0d5a87c554 |
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_sec_otr.py Thu Oct 23 16:56:36 2014 +0200 +++ b/src/browser/sat_browser/plugin_sec_otr.py Sat Jan 24 01:45:39 2015 +0100 @@ -29,7 +29,7 @@ log = getLogger(__name__) from constants import Const as C -import jid +from sat_frontends.tools import jid import otrjs_wrapper as otr import dialog import panels @@ -127,7 +127,7 @@ @param host (satWebFrontend) @param account (Account) - @param other_jid (JID): JID of the person your chat correspondent + @param other_jid (jid.JID): JID of the person your chat correspondent """ super(Context, self).__init__(account, other_jid) self.host = host @@ -157,14 +157,14 @@ log.debug("message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg)) if not encrypted: if self.state == otr.context.STATE_ENCRYPTED: - log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer.full()}) + log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer}) self.host.newMessageCb(self.peer, RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT, C.MESS_TYPE_INFO, self.host.whoami, {}) self.host.newMessageCb(self.peer, msg, "chat", self.host.whoami, {}) def sendMessageCb(self, msg, meta=None): assert isinstance(self.peer, jid.JID) log.debug("message to send%s: %s" % ((' (attached meta data: %s)' % meta) if meta else '', msg)) - self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer.full(), msg, '', 'chat', {'send_only': 'true'}) + self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer, msg, '', 'chat', {'send_only': 'true'}) def messageErrorCb(self, error): log.error('error occured: %s' % error) @@ -173,7 +173,7 @@ if status == otr.context.STATUS_AKE_INIT: return - other_jid_s = self.peer.full() + other_jid_s = self.peer feedback = _(u"Error: the state of the conversation with %s is unknown!") trust = self.getCurrentTrust() @@ -196,7 +196,7 @@ def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) - title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer.full()) + title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer) old_trust = self.getCurrentTrust() if type_ == 'abort': msg = AUTH_ABORTED_TXT @@ -236,7 +236,7 @@ self.setCurrentTrust('fingerprint' if confirm else '') text = (AUTH_INFO_TXT + "<i>" + AUTH_FINGERPRINT_TXT + "</i>" + AUTH_FINGERPRINT_VERIFY).format(you=self.host.whoami, your_fp=priv_key.fingerprint(), other=self.peer, other_fp=other_key.fingerprint(), eol=DIALOG_EOL) - title = AUTH_OTHER_TITLE.format(jid=self.peer.full()) + title = AUTH_OTHER_TITLE.format(jid=self.peer) dialog.ConfirmDialog(setTrust, text, title, AddStyleName="maxWidthLimit").show() def smpAuthCb(self, type_, data, act=None): @@ -261,7 +261,7 @@ # make us need the dirty self.smpAuthAbort. else: log.error("FIXME: unmanaged ambiguous 'act' value in Context.smpAuthCb!") - title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer.full()) + title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer) if type_ == 'question': if act == 'asked': def cb(question, answer=None): @@ -297,7 +297,7 @@ class Account(otr.context.Account): def __init__(self, host): - log.debug(u"new account: %s" % host.whoami.full()) + log.debug(u"new account: %s" % host.whoami) if not host.whoami.resource: log.warning("Account created without resource") super(Account, self).__init__(host.whoami) @@ -337,17 +337,17 @@ def getContextForUser(self, other_jid, start=True): """Get the context for the given JID - @param other_jid (JID): your correspondent + @param other_jid (jid.JID): your correspondent @param start (bool): start non-existing context if True @return: Context """ log.debug(u"getContextForUser [%s]" % other_jid) if not other_jid.resource: log.error("getContextForUser called with a bare jid") - running_sessions = [jid.bareJID() for jid in self.contexts.keys() if self.contexts[jid].state == otr.context.STATE_ENCRYPTED] + running_sessions = [jid_.bareJID() for jid_ in self.contexts.keys() if self.contexts[jid_].state == otr.context.STATE_ENCRYPTED] if start or (other_jid in running_sessions): users_ml = DIALOG_USERS_ML.format(subject=D_("OTR issue in Libervia: getContextForUser called with a bare jid in an encrypted context")) - text = RESOURCE_ISSUE.format(eol=DIALOG_EOL, jid=other_jid.full(), users_ml=users_ml) + text = RESOURCE_ISSUE.format(eol=DIALOG_EOL, jid=other_jid, users_ml=users_ml) dialog.InfoDialog(RESOURCE_ISSUE_TITLE, text, AddStyleName="maxWidthLimit").show() return None # never start an OTR session with a bare JID if start: @@ -380,7 +380,7 @@ def infoTextCallback(self, other_jid, cb): """Get the current info text for a conversation and run a callback. - @param other_jid (JID): JID of the correspondant + @param other_jid (jid.JID): JID of the correspondant @paam cb (callable): method to be called with the computed info text """ def gotResource(other_jid): @@ -414,21 +414,24 @@ for context in self.context_manager.contexts.values(): context.disconnect() - def fixResource(self, jid, cb): + def fixResource(self, jid_, cb): # FIXME: it's dirty, but libervia doesn't manage resources correctly now, refactoring is planed - if jid.resource: - self.last_resources[jid.bare] = jid.resource - cb(jid) - elif jid.bare in self.last_resources: - jid.setResource(self.last_resources[jid.bare]) - cb(jid) + if jid_.resource: + self.last_resources[jid_.bare] = jid_.resource + cb(jid_) + elif jid_.bare in self.last_resources: + # FIXME: to be removed: must use new resource system + # jid_.setResource(self.last_resources[jid_.bare]) + cb(jid_) else: - def gotResource(resource): - if resource: - jid.setResource(resource) - self.last_resources[jid.bare] = jid.resource - cb(jid) - self.host.bridge.call('getLastResource', gotResource, jid.full()) + pass # FIXME: to be removed: must use new resource system + # def gotResource(resource): + # if resource: + # jid_.setResource(resource) + # self.last_resources[jid_.bare] = jid_.resource + # cb(jid_) + # + # self.host.bridge.call('getLastResource', gotResource, jid_) def messageReceivedTrigger(self, from_jid, msg, msg_type, to_jid, extra): if msg_type == C.MESS_TYPE_INFO: @@ -441,19 +444,19 @@ def decrypt(context): context.receiveMessage(msg) - def cb(jid): - otrctx = self.context_manager.getContextForUser(jid, start=False) + def cb(jid_): + otrctx = self.context_manager.getContextForUser(jid_, start=False) if otrctx is None: def confirm(confirm): if confirm: - self.host.getOrCreateLiberviaWidget(panels.ChatPanel, {'item': jid}) - decrypt(self.context_manager.startContext(jid)) + self.host.getOrCreateLiberviaWidget(panels.ChatPanel, {'item': jid_}) + decrypt(self.context_manager.startContext(jid_)) else: # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True pass key = self.context_manager.account.privkey msg = QUERY_RECEIVED + QUERY_SLOWDOWN + (QUERY_KEY if key else QUERY_NO_KEY) + QUERY_CONFIRM - dialog.ConfirmDialog(confirm, msg.format(jid=jid.full(), eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() + dialog.ConfirmDialog(confirm, msg.format(jid=jid_, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() else: # do not ask if the context exist decrypt(otrctx) @@ -462,19 +465,19 @@ return False # interrupt the main process def sendMessageTrigger(self, to_jid, msg, msg_type, extra): - def cb(jid): - otrctx = self.context_manager.getContextForUser(jid, start=False) + def cb(jid_): + otrctx = self.context_manager.getContextForUser(jid_, start=False) if otrctx is not None and otrctx.state != otr.context.STATE_PLAINTEXT: if otrctx.state == otr.context.STATE_ENCRYPTED: log.debug(u"encrypting message") otrctx.sendMessage(msg) - self.host.newMessageCb(self.host.whoami, msg, msg_type, jid, extra) + self.host.newMessageCb(self.host.whoami, msg, msg_type, jid_, extra) else: feedback = SEND_PLAIN_IN_FINISHED_CONTEXT - dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid.full()), feedback, AddStyleName="maxWidthLimit").show() + dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid), feedback, AddStyleName="maxWidthLimit").show() else: log.debug(u"sending message unencrypted") - self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid.full(), msg, '', msg_type, extra) + self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid, msg, '', msg_type, extra) if msg_type == 'groupchat': return True @@ -489,14 +492,14 @@ def endSession(self, other_jid, profile, finish=False): """Finish or disconnect an OTR session - @param other_jid (JID): str + @param other_jid (jid.JID): str @param finish: if True, finish the session but do not disconnect it @return: True if the session has been finished or disconnected, False if there was nothing to do """ def cb(other_jid): def not_available(): if not finish: - self.host.newMessageCb(other_jid, END_PLAIN.format(jid=other_jid.full()), C.MESS_TYPE_INFO, self.host.whoami, {}) + self.host.newMessageCb(other_jid, END_PLAIN.format(jid=other_jid), C.MESS_TYPE_INFO, self.host.whoami, {}) priv_key = self.context_manager.account.privkey if priv_key is None: @@ -526,16 +529,16 @@ if otrctx: otrctx.sendQueryMessage() - def cb(jid): + def cb(jid_): key = self.context_manager.account.privkey if key is None: def confirm(confirm): if confirm: - query(jid) + query(jid_) msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM - dialog.ConfirmDialog(confirm, msg.format(jid=jid.full(), eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() + dialog.ConfirmDialog(confirm, msg.format(jid=jid_, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() else: # on query reception we ask always, if we initiate we just ask the first time - query(jid) + query(jid_) try: other_jid = menu_data['jid']