core (disco): added discoInfos and discoItems bridge methods

This commit is contained in:
Goffi 2014-04-01 21:14:57 +02:00
commit e95d04b69e

View file

@ -114,7 +114,7 @@ class Discovery(object):
@param jid_: jid of the target, or None for profile's server
@param profile_key: %(doc_profile_key)s
@return: a Deferred which fire disco.DiscoInfo
@return: a Deferred which fire disco.DiscoItems
"""
client = self.host.getClient(profile_key)
if jid_ is None:
@ -212,3 +212,23 @@ class Discovery(object):
cap_hash = b64encode(sha1(''.join(s)).digest())
debug(_('Capability hash generated: [%s]') % cap_hash)
return cap_hash
@defer.inlineCallbacks
def _discoInfos(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):
""" Discovery method for the bridge
@param entity_jid_s: entity we want to discover
@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()]))
@defer.inlineCallbacks
def _discoItems(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):
""" Discovery method for the bridge
@param entity_jid_s: entity we want to discover
@return: list of tu"""
entity = jid.JID(entity_jid_s)
disco_items = yield self.getItems(entity, profile_key)
defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items])