comparison sat/memory/disco.py @ 3250:e4d3ba75b1b2

core (memory/disco): fixed types of disco extensions: typeCheck() is not automatically called on reception by Wokkel, as a result extensions fields values may be strings instead of the field type. TypeCheck is now explicitly called in memory.disco to avoid that. It is not called immediately on reception as the string value is needed to calculate the capability hash
author Goffi <goffi@goffi.org>
date Tue, 14 Apr 2020 20:25:05 +0200
parents 12486cd4fa8b
children 6cf4bd6972c2
comparison
equal deleted inserted replaced
3249:f16c96c7a91a 3250:e4d3ba75b1b2
85 def load(self): 85 def load(self):
86 def fillHashes(hashes): 86 def fillHashes(hashes):
87 for hash_, xml in hashes.items(): 87 for hash_, xml in hashes.items():
88 element = xml_tools.ElementParser()(xml) 88 element = xml_tools.ElementParser()(xml)
89 disco_info = disco.DiscoInfo.fromElement(element) 89 disco_info = disco.DiscoInfo.fromElement(element)
90 for ext_form in disco_info.extensions.values():
91 # wokkel doesn't call typeCheck on reception, so we do it here
92 ext_form.typeCheck()
90 if not disco_info.features and not disco_info.identities: 93 if not disco_info.features and not disco_info.identities:
91 log.warning( 94 log.warning(
92 _( 95 _(
93 "no feature/identity found in disco element (hash: {cap_hash}), ignoring: {xml}" 96 "no feature/identity found in disco element (hash: {cap_hash}), ignoring: {xml}"
94 ).format(cap_hash=hash_, xml=xml) 97 ).format(cap_hash=hash_, xml=xml)
178 )[C.ENTITY_CAP_HASH] 181 )[C.ENTITY_CAP_HASH]
179 except (KeyError, exceptions.UnknownEntityError): 182 except (KeyError, exceptions.UnknownEntityError):
180 # capability hash is not available, we'll compute one 183 # capability hash is not available, we'll compute one
181 def infosCb(disco_infos): 184 def infosCb(disco_infos):
182 cap_hash = self.generateHash(disco_infos) 185 cap_hash = self.generateHash(disco_infos)
186 for ext_form in disco_infos.extensions.values():
187 # wokkel doesn't call typeCheck on reception, so we do it here
188 # to avoid ending up with incorrect types. We have to do it after
189 # the hash has been generated (str value is needed to compute the
190 # hash)
191 ext_form.typeCheck()
183 self.hashes[cap_hash] = disco_infos 192 self.hashes[cap_hash] = disco_infos
184 self.host.memory.updateEntityData( 193 self.host.memory.updateEntityData(
185 jid_, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile 194 jid_, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile
186 ) 195 )
187 return disco_infos 196 return disco_infos
403 412
404 @defer.inlineCallbacks 413 @defer.inlineCallbacks
405 def _discoInfos( 414 def _discoInfos(
406 self, entity_jid_s, node="", use_cache=True, profile_key=C.PROF_KEY_NONE 415 self, entity_jid_s, node="", use_cache=True, profile_key=C.PROF_KEY_NONE
407 ): 416 ):
408 """ Discovery method for the bridge 417 """Discovery method for the bridge
409 @param entity_jid_s: entity we want to discover 418 @param entity_jid_s: entity we want to discover
410 @param use_cache(bool): if True, use cached data if available 419 @param use_cache(bool): if True, use cached data if available
411 @param node(unicode): optional node to use 420 @param node(unicode): optional node to use
412 421
413 @return: list of tuples 422 @return: list of tuples