core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
This commit is contained in:
parent
7ffb8efb92
commit
b9e3707412
1 changed files with 91 additions and 0 deletions
|
|
@ -118,6 +118,7 @@ class SAT(service.Service):
|
|||
self.bridge.register_method("menuLaunch", self._launchMenu)
|
||||
self.bridge.register_method("discoInfos", self.memory.disco._discoInfos)
|
||||
self.bridge.register_method("discoItems", self.memory.disco._discoItems)
|
||||
self.bridge.register_method("discoFindByFeatures", self._findByFeatures)
|
||||
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)
|
||||
|
|
@ -670,6 +671,60 @@ class SAT(service.Service):
|
|||
def findFeaturesSet(self, *args, **kwargs):
|
||||
return self.memory.disco.findFeaturesSet(*args, **kwargs)
|
||||
|
||||
def _findByFeatures(self, namespace, service, roster, own_jid, profile_key):
|
||||
client = self.getClient(profile_key)
|
||||
return self.findByFeatures(client, namespace, service, roster, own_jid)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def findByFeatures(self, client, namespaces, service, roster, own_jid):
|
||||
"""retrieve all services or contacts managing a set a features
|
||||
|
||||
@param namespaces(list[unicode]): features which must be handled
|
||||
@param service(bool): if True return service from our roster
|
||||
@param roster(bool): if True, return entities in roster
|
||||
full jid of all matching resources available will be returned
|
||||
@param own_jid(bool): if True, return profile's jid resources
|
||||
@return (tuple(dict[jid.JID(), tuple[unicode, unicode, unicode]]*3)): found entities in a tuple with:
|
||||
- service entities
|
||||
- own entities
|
||||
- roster entities
|
||||
"""
|
||||
if not namespaces:
|
||||
raise exceptions.DataError("namespaces must not be empty")
|
||||
found_service = {}
|
||||
found_own = {}
|
||||
found_roster = {}
|
||||
if service:
|
||||
services_jids = yield self.findFeaturesSet(client, namespaces)
|
||||
for service_jid in services_jids:
|
||||
infos = yield self.getDiscoInfos(client, service_jid)
|
||||
identities = [(cat, type_, name or u'') for (cat, type_), name in infos.identities.iteritems()]
|
||||
found_service[service_jid.full()] = identities
|
||||
|
||||
jids = []
|
||||
if roster:
|
||||
jids.extend(client.roster.getJids())
|
||||
if own_jid:
|
||||
jids.append(client.jid.userhostJID())
|
||||
|
||||
for found, jids in ((found_own, [client.jid.userhostJID()]),
|
||||
(found_roster, client.roster.getJids())):
|
||||
for jid_ in jids:
|
||||
if jid_.resource:
|
||||
resources = [jid_.resource]
|
||||
else:
|
||||
try:
|
||||
resources = self.memory.getAllResources(client, jid_)
|
||||
except exceptions.UnknownEntityError:
|
||||
continue
|
||||
for resource in resources:
|
||||
full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource))
|
||||
infos = yield self.getDiscoInfos(client, full_jid)
|
||||
if infos.features.issuperset(namespaces):
|
||||
identities = [(cat, type_, name or u'') for (cat, type_), name in infos.identities.iteritems()]
|
||||
found[full_jid.full()] = identities
|
||||
|
||||
defer.returnValue((found_service, found_own, found_roster))
|
||||
|
||||
## Generic HMI ##
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue