Comparison

mod_delegation/mod_delegation.lua @ 1713:01e9465f8f80

mod_delegation: delegated features/identities removal for disco info requests on bare jid
author Goffi <goffi@goffi.org>
date Fri, 17 Apr 2015 21:06:51 +0200
parent 1712:c1973605d096
child 1714:3d83f5337a73
comparison
equal deleted inserted replaced
1712:c1973605d096 1713:01e9465f8f80
253 253
254 -- disabling internal features/identities 254 -- disabling internal features/identities
255 255
256 -- modules whose features/identities are managed by delegation 256 -- modules whose features/identities are managed by delegation
257 local disabled_modules = set.new() 257 local disabled_modules = set.new()
258 local disabled_identities = set.new()
258 259
259 local function identity_added(event) 260 local function identity_added(event)
260 local source = event.source 261 local source = event.source
261 if disabled_modules:contains(source) then 262 if disabled_modules:contains(source) then
262 local item = event.item 263 local item = event.item
263 local category, type_, name = item.category, item.type, item.name 264 local category, type_, name = item.category, item.type, item.name
264 module:log("debug", "Removing (%s/%s%s) identity because of delegation", category, type_, name and "/"..name or "") 265 module:log("debug", "Removing (%s/%s%s) identity because of delegation", category, type_, name and "/"..name or "")
266 disabled_identities:add(item)
265 source:remove_item("identity", item) 267 source:remove_item("identity", item)
266 end 268 end
267
268 end 269 end
269 270
270 local function feature_added(event) 271 local function feature_added(event)
271 local source, item = event.source, event.item 272 local source, item = event.source, event.item
272 for namespace, _ in pairs(ns_delegations) do 273 for namespace, _ in pairs(ns_delegations) do
349 350
350 module:hook("iq-result/host/"..iq_id, disco_main_result) 351 module:hook("iq-result/host/"..iq_id, disco_main_result)
351 module:hook("iq-error/host/"..iq_id, disco_main_error) 352 module:hook("iq-error/host/"..iq_id, disco_main_error)
352 module:send(iq) 353 module:send(iq)
353 end 354 end
355
356 -- disco to bare jids special case
357
358 module:hook("account-disco-info", function(event)
359 -- this event is called when a disco info request is done on a bare jid
360 -- we get the final reply and filter delegated features/identities
361 local reply = event.reply;
362 reply.tags[1]:maptags(function(child)
363 if child.name == 'feature' then
364 local feature_ns = child.attr.var
365 for namespace, _ in pairs(ns_delegations) do
366 if string.sub(feature_ns, 1, #namespace) == namespace then
367 module:log("debug", "Removing feature namespace %s which is delegated", feature_ns)
368 return nil
369 end
370 end
371 elseif child.name == 'identity' then
372 for item in disabled_identities:items() do
373 if item.category == child.attr.category
374 and item.type == child.attr.type
375 -- we don't check name, because mod_pep use a name for main disco, but not in account-disco-info hook
376 -- and item.name == child.attr.name
377 then
378 module:log("debug", "Removing (%s/%s%s) identity because of delegation", item.category, item.type, item.name and "/"..item.name or "")
379 return nil
380 end
381 end
382 end
383 return child
384 end)
385 end, -2^32);