mod_mix_pam: Fix ID and mix host tracking

This commit is contained in:
PapaTutuWawa 2021-02-28 11:31:40 +01:00
parent fd9735faba
commit 5decc47af9

View File

@ -120,7 +120,7 @@ local function handle_client_join(event)
});
join_iq:add_child(join);
add_state(stanza.attr.id, jid.resource(from));
add_state(stanza.attr.id, origin);
module:send(join_iq);
return true;
@ -152,7 +152,7 @@ local function handle_client_leave(event)
});
leave_iq:add_child(leave);
add_state(stanza.attr.id, jid.resource(from));
add_state(stanza.attr.id, origin);
module:send(leave_iq);
return true;
@ -196,12 +196,12 @@ local function handle_mix_join(event)
-- TODO: Error handling?
rm_add_to_roster(origin, stanza.attr.from, {
subscription = "both",
subscription = "from",
groups = {},
mix_spid = spid,
});
rm_roster_push(jid.node(stanza.attr.to), module_host, stanza.attr.from);
add_mix_host(jid.bare(stanza.attr.from));
add_mix_host(jid.host(stanza.attr.from));
return true;
end
@ -248,7 +248,8 @@ module:hook("iq/bare", function(event)
return handle_mix_join(event);
elseif has_state(event.stanza.attr.id) then
local tmp = st.clone(event.stanza);
tmp.attr.to = tmp.attr.to.."/"..pop_state(tmp.attr.id);
local origin = pop_state(tmp.attr.id);
tmp.attr.to = tmp.attr.to.."/"..origin.resource;
module:send(tmp);
return true;
end
@ -283,24 +284,6 @@ module:hook("resource-unbind", function(event)
module:log("debug", "Unbind of not recorded resource %s (%s)", resource, session_jid);
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)
-- NOTE: Currently this requires a patch to make mod_roster emit
-- the roster-get event
@ -313,14 +296,18 @@ module:hook("roster-get", function(event)
module:log("debug", "Annotated roster request received");
-- 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");
for contact, item in pairs(rm_load_roster(jid.bare(stanza.attr.from))) do
if item["mix_spid"] ~= nil then
local roster_item = child_with_attrs(query, "item", nil, { jid = contact });
if roster_item then
roster_item:tag("channel", { xmlns = mix_roster_xmlns, ["participant-id"] = item["mix_spid"] });
else
module:log("warn", "Could not find %s during annotated roster query!");
for contact, roster_item in pairs(roster) do
if roster_item["mix_spid"] ~= nil then
for _, item in ipairs(query:childtags("item")) do
if item.attr.jid == contact then
item:tag("channel", {
xmlns = mix_roster_xmlns,
["participant-id"] = roster_item["mix_spid"],
});
break;
end
end
end
end