comparison mod_delegation/mod_delegation.lua @ 1717:e22cd2205fc1

mod_delegation: reset features/identities/extensions before doing a disco nesting
author Goffi <goffi@goffi.org>
date Sat, 18 Apr 2015 00:13:10 +0200
parents 29dfdfc767b4
children 48be6e7efbe8
comparison
equal deleted inserted replaced
1716:29dfdfc767b4 1717:e22cd2205fc1
368 end 368 end
369 369
370 for feature in query:childtags("feature") do 370 for feature in query:childtags("feature") do
371 local namespace = feature.attr.var 371 local namespace = feature.attr.var
372 if main then 372 if main then
373 if not module:has_feature(namespace) then -- we avoid doubling features in case of disconnection/reconnexion 373 module:add_feature(namespace)
374 module:add_feature(namespace)
375 end
376 else 374 else
377 bare_features:add(namespace) 375 bare_features:add(namespace)
378 end 376 end
379 end 377 end
380 for identity in query:childtags("identity") do 378 for identity in query:childtags("identity") do
381 local category, type_, name = identity.attr.category, identity.attr.type, identity.attr.name 379 local category, type_, name = identity.attr.category, identity.attr.type, identity.attr.name
382 if main then 380 if main then
383 if not module:has_identity(category, type_, name) then 381 module:add_identity(category, type_, name)
384 module:add_identity(category, type_, name)
385 end
386 else 382 else
387 local found=false 383 table.insert(bare_identities, {category=category, type=type_, name=name})
388 for _, item in ipairs(bare_identities) do
389 if item.category == category and item.type == type_ and item.name == name then
390 found=true
391 break
392 end
393 end
394 if not found then
395 table.insert(bare_identities, {category=category, type=type_, name=name})
396 end
397 end 384 end
398 end 385 end
399 for extension in query:childtags("x", _DATA_NS) do 386 for extension in query:childtags("x", _DATA_NS) do
400 if main then 387 if main then
401 module:add_extension(extension) 388 module:add_extension(extension)
416 module:log("warn", "Got an error while requesting disco for nesting to "..stanza.attr.from) 403 module:log("warn", "Got an error while requesting disco for nesting to "..stanza.attr.from)
417 module:log("warn", "Ignoring disco nesting") 404 module:log("warn", "Ignoring disco nesting")
418 end 405 end
419 406
420 function disco_nest(namespace, entity_jid) 407 function disco_nest(namespace, entity_jid)
408 -- manage discovery nesting (see ยง 7.2)
409
410 -- first we reset the current values
411 if module.items then
412 module.items['feature'] = nil
413 module.items['identity'] = nil
414 module.items['extension'] = nil
415 bare_features = set.new()
416 bare_identities = {}
417 bare_extensions = {}
418 end
419
421 for _, prefix in ipairs(_PREFIXES) do 420 for _, prefix in ipairs(_PREFIXES) do
422 local node = prefix..namespace 421 local node = prefix..namespace
423 422
424 local iq = st.iq({from=module.host, to=entity_jid, type='get'}) 423 local iq = st.iq({from=module.host, to=entity_jid, type='get'})
425 :tag('query', {xmlns=_DISCO_NS, node=node}) 424 :tag('query', {xmlns=_DISCO_NS, node=node})