comparison sat/memory/disco.py @ 2830:770ec685ff1f

core (disco): added missing disco extensions when generating the cap hash.
author Goffi <goffi@goffi.org>
date Fri, 01 Mar 2019 19:28:11 +0100
parents 003b8b4b56a7
children 2224fbbd45dd
comparison
equal deleted inserted replaced
2829:649cb3fd7711 2830:770ec685ff1f
354 hash algorithm is the one described in XEP-0115 354 hash algorithm is the one described in XEP-0115
355 @param services: iterable of disco.DiscoIdentity/disco.DiscoFeature, as returned by discoHandler.info 355 @param services: iterable of disco.DiscoIdentity/disco.DiscoFeature, as returned by discoHandler.info
356 356
357 """ 357 """
358 s = [] 358 s = []
359 # identities
359 byte_identities = [ 360 byte_identities = [
360 ByteIdentity(service) 361 ByteIdentity(service)
361 for service in services 362 for service in services
362 if isinstance(service, disco.DiscoIdentity) 363 if isinstance(service, disco.DiscoIdentity)
363 ] # FIXME: lang must be managed here 364 ] # FIXME: lang must be managed here
365 byte_identities.sort(key=lambda i: i.idType) 366 byte_identities.sort(key=lambda i: i.idType)
366 byte_identities.sort(key=lambda i: i.category) 367 byte_identities.sort(key=lambda i: i.category)
367 for identity in byte_identities: 368 for identity in byte_identities:
368 s.append(str(identity)) 369 s.append(str(identity))
369 s.append("<") 370 s.append("<")
371 # features
370 byte_features = [ 372 byte_features = [
371 service.encode("utf-8") 373 service.encode("utf-8")
372 for service in services 374 for service in services
373 if isinstance(service, disco.DiscoFeature) 375 if isinstance(service, disco.DiscoFeature)
374 ] 376 ]
375 byte_features.sort() # XXX: the default sort has the same behaviour as the requested RFC 4790 i;octet sort 377 byte_features.sort() # XXX: the default sort has the same behaviour as the requested RFC 4790 i;octet sort
376 for feature in byte_features: 378 for feature in byte_features:
377 s.append(feature) 379 s.append(feature)
378 s.append("<") 380 s.append("<")
379 # TODO: manage XEP-0128 data form here 381
382 # extensions
383 ext = services.extensions.values()
384 ext.sort(key=lambda f: f.formNamespace.encode('utf-8'))
385 for extension in ext:
386 s.append(extension.formNamespace.encode('utf-8'))
387 s.append("<")
388 fields = extension.fieldList
389 fields.sort(key=lambda f: f.var.encode('utf-8'))
390 for field in fields:
391 s.append(field.var.encode('utf-8'))
392 s.append("<")
393 values = [v.encode('utf-8') for v in field.values]
394 values.sort()
395 for value in values:
396 s.append(value)
397 s.append("<")
398
380 cap_hash = b64encode(sha1("".join(s)).digest()) 399 cap_hash = b64encode(sha1("".join(s)).digest())
381 log.debug(_(u"Capability hash generated: [%s]") % cap_hash) 400 log.debug(_(u"Capability hash generated: [{cap_hash}]").format(cap_hash=cap_hash))
382 return cap_hash 401 return cap_hash
383 402
384 @defer.inlineCallbacks 403 @defer.inlineCallbacks
385 def _discoInfos( 404 def _discoInfos(
386 self, entity_jid_s, node=u"", use_cache=True, profile_key=C.PROF_KEY_NONE 405 self, entity_jid_s, node=u"", use_cache=True, profile_key=C.PROF_KEY_NONE