# HG changeset patch # User Goffi # Date 1429304375 -7200 # Node ID 159d16336f8757cae5b0e1754c33eac7c1836370 # Parent e5393b12dd0f631157eaec30dbb4e7c1a3ac958e core, bridge, jp: management of service discovery extensions (XEP-0128) diff -r e5393b12dd0f -r 159d16336f87 frontends/src/jp/cmd_info.py --- a/frontends/src/jp/cmd_info.py Fri Apr 17 10:39:41 2015 +0200 +++ b/frontends/src/jp/cmd_info.py Fri Apr 17 22:59:35 2015 +0200 @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from logging import debug, info, error, warning +from logging import debug, info, warning import base from sat.core.i18n import _ @@ -48,7 +48,7 @@ self.host.bridge.discoItems(jid, profile_key=self.host.profile, callback=lambda items: self.gotItems(infos, items), errback=self.error) def gotItems(self, infos, items): - features, identities = infos + features, identities, extensions = infos features.sort() identities.sort(key=lambda identity: identity[2]) items.sort(key=lambda item: item[2]) @@ -56,30 +56,51 @@ items_lst = [] for identity in identities: category, type_, name = identity - identities_lst.append(u"%(name)s(%(cat)s/%(type)s)" % - {'name': (name+' ') if name else '', - 'cat': category, - 'type': type_}) + identities_lst.append(u"{name}({cat}/{type_})".format( + name = (name+' ') if name else '', + cat = category, + type_ = type_)) for item in items: entity, node_id, name = item - items_lst.append(u"%(name)s[%(entity)s%(node_id)s]" % - {'name': (name+' ') if name else '', - 'entity': entity, - 'node_id': (', ' + node_id) if node_id else '' - }) + items_lst.append(u"{name}[{entity}{node_id}]".format( + name = (name+' ') if name else '', + entity = entity, + node_id = (', ' + node_id) if node_id else '' + )) + extensions_types = extensions.keys() + extensions_types.sort() + + extensions_tpl = [] + for type_ in extensions_types: + fields = [] + for field in extensions[type_]: + field_lines = [] + data, values = field + data_keys = data.keys() + data_keys.sort() + for key in data_keys: + field_lines.append(u'\t{key} = {value}'.format(key=key, value=data[key])) + for value in values: + field_lines.append(u'\tvalue = {value}'.format(value=value)) + fields.append(u'\n'.join(field_lines)) + extensions_tpl.append(u'{type_}\n{fields}'.format(type_=type_, + fields='\n\n'.join(fields))) template = [] if features: - template.append(_(u"Features:\n\n%(features)s")) + template.append(_(u"Features:\n\n{features}")) if identities: - template.append(_(u"Identities:\n\n%(identities)s")) + template.append(_(u"Identities:\n\n{identities}")) + if extensions_tpl: + template.append(_(u'Extensions:\n\n{extensions}')) if items: - template.append(_(u"Items:\n\n%(items)s")) + template.append(_(u"Items:\n\n{items}")) - print "\n--\n".join(template) % { 'features': '\n'.join(features), - 'identities': '\n'.join(identities_lst), - 'items': '\n'.join(items_lst), - } + print "\n--\n".join(template).format ( features = '\n'.join(features), + identities = '\n'.join(identities_lst), + extensions = '\n'.join(extensions_tpl), + items = '\n'.join(items_lst), + ) self.host.quit() diff -r e5393b12dd0f -r 159d16336f87 src/bridge/DBus.py --- a/src/bridge/DBus.py Fri Apr 17 10:39:41 2015 +0200 +++ b/src/bridge/DBus.py Fri Apr 17 22:59:35 2015 +0200 @@ -235,7 +235,7 @@ return self._callback("delContact", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, - in_signature='ss', out_signature='(asa(sss))', + in_signature='ss', out_signature='(asa(sss)a{sa(a{ss}as)})', async_callbacks=('callback', 'errback')) def discoInfos(self, entity_jid, profile_key, callback=None, errback=None): return self._callback("discoInfos", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback) diff -r e5393b12dd0f -r 159d16336f87 src/bridge/bridge_constructor/bridge_template.ini --- a/src/bridge/bridge_constructor/bridge_template.ini Fri Apr 17 10:39:41 2015 +0200 +++ b/src/bridge/bridge_constructor/bridge_template.ini Fri Apr 17 22:59:35 2015 +0200 @@ -614,11 +614,20 @@ type=method category=core sig_in=ss -sig_out=(asa(sss)) +sig_out=(asa(sss)a{sa(a{ss}as)}) doc=Discover infos on an entity doc_param_0=entity_jid: JID to discover doc_param_1=%(doc_profile_key)s -doc_return=discovery data +doc_return=discovery data: + - list of features + - list of identities (category, type, name) + - dictionary of extensions (FORM_TYPE as key), with value of: + - list of field which are: + - dictionary key/value where key can be: + * var + * label + * type + - list of values [discoItems] async= diff -r e5393b12dd0f -r 159d16336f87 src/memory/disco.py --- a/src/memory/disco.py Fri Apr 17 10:39:41 2015 +0200 +++ b/src/memory/disco.py Fri Apr 17 22:59:35 2015 +0200 @@ -254,7 +254,24 @@ @return: list of tu""" entity = jid.JID(entity_jid_s) disco_infos = yield self.getInfos(entity, profile_key) - defer.returnValue((disco_infos.features, [(cat, type_, name or '') for (cat, type_), name in disco_infos.identities.items()])) + extensions = {} + for form_type, form in disco_infos.extensions.items(): + fields = [] + for field in form.fieldList: + data = {'type': field.fieldType} + for attr in ('var', 'label', 'desc'): + value = getattr(field, attr) + if value is not None: + data[attr] = value + + values = [field.value] if field.value is not None else field.values + fields.append((data, values)) + + extensions[form_type or ""] = fields + + defer.returnValue((disco_infos.features, + [(cat, type_, name or '') for (cat, type_), name in disco_infos.identities.items()], + extensions)) @defer.inlineCallbacks def _discoItems(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):