mod_mix_pam: Cleanup of the roster portion
This commit is contained in:
parent
15c1179f4d
commit
c7b9dc2432
@ -283,6 +283,24 @@ module:hook("resource-unbind", function(event)
|
|||||||
module:log("debug", "Unbind of not recorded resource %s (%s)", resource, session_jid);
|
module:log("debug", "Unbind of not recorded resource %s (%s)", resource, session_jid);
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
local function child_with_attrs(stanza, childtag, xmlns, attrs)
|
||||||
|
-- Helper function: Like stanza:childtags, but returns only the first
|
||||||
|
-- child whose attributes are in attrs (and match the values in attrs).
|
||||||
|
-- Otherwise, nil is returned.
|
||||||
|
for _, child in ipairs(stanza:childtags(childtag, xmlns)) do
|
||||||
|
for attr_name, attr_value in pairs(attrs) do
|
||||||
|
if child.attrs[attr_name] ~= nil and child.attrs[attr_name] == attr_value then
|
||||||
|
return child;
|
||||||
|
else
|
||||||
|
-- We already now that this is not the child we're looking for
|
||||||
|
break;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
end
|
||||||
|
|
||||||
module:hook("roster-get", function(event)
|
module:hook("roster-get", function(event)
|
||||||
-- NOTE: Currently this requires a patch to make mod_roster emit
|
-- NOTE: Currently this requires a patch to make mod_roster emit
|
||||||
-- the roster-get event
|
-- the roster-get event
|
||||||
@ -295,18 +313,14 @@ module:hook("roster-get", function(event)
|
|||||||
module:log("debug", "Annotated roster request received");
|
module:log("debug", "Annotated roster request received");
|
||||||
|
|
||||||
-- User requested the roster with an <annotate/>
|
-- User requested the roster with an <annotate/>
|
||||||
local roster = rm_load_roster(jid.bare(stanza.attr.from));
|
|
||||||
local query = event.reply:get_child("query", "jabber:iq:roster");
|
local query = event.reply:get_child("query", "jabber:iq:roster");
|
||||||
for contact, roster_item in pairs(roster) do
|
for contact, item in pairs(rm_load_roster(jid.bare(stanza.attr.from))) do
|
||||||
if roster_item["mix_spid"] ~= nil then
|
if item["mix_spid"] ~= nil then
|
||||||
for _, item in ipairs(query:childtags("item")) do
|
local roster_item = child_with_attrs(query, "item", nil, { jid = contact });
|
||||||
if item.attr.jid == contact then
|
if roster_item then
|
||||||
item:tag("channel", {
|
roster_item:tag("channel", { xmlns = mix_roster_xmlns, ["participant-id"] = item["mix_spid"] });
|
||||||
xmlns = mix_roster_xmlns,
|
else
|
||||||
["participant-id"] = roster_item["mix_spid"],
|
module:log("warn", "Could not find %s during annotated roster query!");
|
||||||
});
|
|
||||||
break;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user