Mercurial > libervia-backend
changeset 2443:81a45e7886c9
core: added a mechanism to associate short names to namespaces:
- new internal registerNamespace can be used by a plugin to associate a short name to a namespace
- new NamespacesGet bridge method retrieve those associations
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 19 Nov 2017 16:46:07 +0100 |
parents | b8ffb7f8056b |
children | 30278ea1ca7c |
files | frontends/src/bridge/dbus_bridge.py src/bridge/bridge_constructor/bridge_template.ini src/bridge/dbus_bridge.py src/core/sat_main.py src/plugins/plugin_misc_tickets.py |
diffstat | 5 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/bridge/dbus_bridge.py Sun Nov 19 16:41:59 2017 +0100 +++ b/frontends/src/bridge/dbus_bridge.py Sun Nov 19 16:46:07 2017 +0100 @@ -504,6 +504,20 @@ error_handler = lambda err:errback(dbus_to_bridge_exception(err)) return self.db_core_iface.messageSend(to_jid, message, subject, mess_type, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) + def namespacesGet(self, callback=None, errback=None): + if callback is None: + error_handler = None + else: + if errback is None: + errback = log.error + error_handler = lambda err:errback(dbus_to_bridge_exception(err)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.namespacesGet(**kwargs) + def paramsRegisterApp(self, xml, security_limit=-1, app='', callback=None, errback=None): if callback is None: error_handler = None
--- a/src/bridge/bridge_constructor/bridge_template.ini Sun Nov 19 16:41:59 2017 +0100 +++ b/src/bridge/bridge_constructor/bridge_template.ini Sun Nov 19 16:46:07 2017 +0100 @@ -763,3 +763,11 @@ doc_return=session informations, with at least the following keys: jid: current full jid started: date of creation of the session (Epoch time) + +[namespacesGet] +type=method +category=core +sig_in= +sig_out=a{ss} +doc=Get a dict to short name => whole namespaces +doc_return=namespaces mapping
--- a/src/bridge/dbus_bridge.py Sun Nov 19 16:41:59 2017 +0100 +++ b/src/bridge/dbus_bridge.py Sun Nov 19 16:46:07 2017 +0100 @@ -384,6 +384,12 @@ return self._callback("messageSend", unicode(to_jid), message, subject, unicode(mess_type), extra, unicode(profile_key), callback=callback, errback=errback) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, + in_signature='', out_signature='a{ss}', + async_callbacks=None) + def namespacesGet(self, ): + return self._callback("namespacesGet", ) + + @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, in_signature='sis', out_signature='', async_callbacks=None) def paramsRegisterApp(self, xml, security_limit=-1, app=''):
--- a/src/core/sat_main.py Sun Nov 19 16:41:59 2017 +0100 +++ b/src/core/sat_main.py Sun Nov 19 16:46:07 2017 +0100 @@ -55,6 +55,7 @@ self.initialised = defer.Deferred() self.profiles = {} self.plugins = {} + self._ns_map = {} # map for short name to whole namespace self.memory = Memory(self) self.trigger = trigger.TriggerManager() # trigger are used to change SàT behaviour @@ -118,6 +119,7 @@ self.bridge.register_method("saveParamsTemplate", self.memory.save_xml) self.bridge.register_method("loadParamsTemplate", self.memory.load_xml) self.bridge.register_method("sessionInfosGet", self.getSessionInfos) + self.bridge.register_method("namespacesGet", self.getNamespaces) self.memory.initialized.addCallback(self._postMemoryInit) @@ -955,6 +957,17 @@ languageSwitch() return help_string + # misc methods + + def registerNamespace(self, short_name, namespace): + """associate a namespace to a short name""" + if short_name in self._ns_map: + raise exceptions.ConflictError(u'this short name is already used') + self._ns_map[short_name] = namespace + + def getNamespaces(self): + return self._ns_map + def getSessionInfos(self, profile_key): """compile interesting data on current profile session""" client = self.getClient(profile_key)
--- a/src/plugins/plugin_misc_tickets.py Sun Nov 19 16:41:59 2017 +0100 +++ b/src/plugins/plugin_misc_tickets.py Sun Nov 19 16:46:07 2017 +0100 @@ -47,6 +47,7 @@ def __init__(self, host): log.info(_(u"Tickets plugin initialization")) self.host = host + host.registerNamespace('tickets', NS_TICKETS) self._p = self.host.plugins["XEP-0060"] self._s = self.host.plugins["PUBSUB_SCHEMA"] self._m = self.host.plugins["XEP-0277"]