comparison src/memory/disco.py @ 963:723f28cd15c7

core (disco): added discoInfos and discoItems bridge methods
author Goffi <goffi@goffi.org>
date Tue, 01 Apr 2014 21:14:57 +0200
parents 0e8c2414f89c
children 4a8903021fda
comparison
equal deleted inserted replaced
962:b280cf4cdf25 963:723f28cd15c7
112 def getItems(self, jid_=None, profile_key=C.PROF_KEY_NONE): 112 def getItems(self, jid_=None, profile_key=C.PROF_KEY_NONE):
113 """get disco items from jid_, cache them for our own server 113 """get disco items from jid_, cache them for our own server
114 114
115 @param jid_: jid of the target, or None for profile's server 115 @param jid_: jid of the target, or None for profile's server
116 @param profile_key: %(doc_profile_key)s 116 @param profile_key: %(doc_profile_key)s
117 @return: a Deferred which fire disco.DiscoInfo 117 @return: a Deferred which fire disco.DiscoItems
118 """ 118 """
119 client = self.host.getClient(profile_key) 119 client = self.host.getClient(profile_key)
120 if jid_ is None: 120 if jid_ is None:
121 jid_ = jid.JID(client.jid.host) 121 jid_ = jid.JID(client.jid.host)
122 # we cache items only for our own server 122 # we cache items only for our own server
210 s.append('<') 210 s.append('<')
211 #TODO: manage XEP-0128 data form here 211 #TODO: manage XEP-0128 data form here
212 cap_hash = b64encode(sha1(''.join(s)).digest()) 212 cap_hash = b64encode(sha1(''.join(s)).digest())
213 debug(_('Capability hash generated: [%s]') % cap_hash) 213 debug(_('Capability hash generated: [%s]') % cap_hash)
214 return cap_hash 214 return cap_hash
215
216 @defer.inlineCallbacks
217 def _discoInfos(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):
218 """ Discovery method for the bridge
219 @param entity_jid_s: entity we want to discover
220
221 @return: list of tu"""
222 entity = jid.JID(entity_jid_s)
223 disco_infos = yield self.getInfos(entity, profile_key)
224 defer.returnValue((disco_infos.features, [(cat, type_, name or '') for (cat, type_), name in disco_infos.identities.items()]))
225
226 @defer.inlineCallbacks
227 def _discoItems(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):
228 """ Discovery method for the bridge
229 @param entity_jid_s: entity we want to discover
230
231 @return: list of tu"""
232 entity = jid.JID(entity_jid_s)
233 disco_items = yield self.getItems(entity, profile_key)
234 defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items])