mod_mix_pam: Remove tracking of bound resources

This commit is contained in:
PapaTutuWawa 2021-05-17 13:09:52 +02:00
parent 2c89d00c09
commit 482890a9a1

View File

@ -255,35 +255,6 @@ module:hook("iq/bare", function(event)
end
end);
local user_resources = {}; -- [bare jid] -> array of bound resources
module:hook("resource-bind", function(event)
local session_jid, resource = jid.bare(event.session.full_jid), event.session.resource;
if user_resources[session_jid] ~= nil then
for _, r in pairs(user_resources) do
if r == resource then return; end
end
table.insert(user_resources[session_jid], resource);
else
user_resources[session_jid] = { resource };
end
module:log("debug", "Caught resource %s of %s", resource, session_jid);
end);
module:hook("resource-unbind", function(event)
local session_jid, resource = jid.bare(event.session.full_jid), event.session.resource;
for i, r in pairs(user_resources[session_jid]) do
if r == resource then
table.remove(user_resources[session_jid], i);
return;
end
end
module:log("debug", "Unbind of not recorded resource %s (%s)", resource, session_jid);
end);
module:hook("roster-get", function(event)
-- NOTE: Currently this requires a patch to make mod_roster emit
-- the roster-get event
@ -321,19 +292,12 @@ module:hook("message/bare", function(event)
if not is_mix_host(jid_host) then return; end
if not is_mix_message(stanza) then return; end
-- MIX-CORE says that if the message cannot be delivered, it should
-- just be dropped
if user_resources[stanza.attr.to] == nil then
module:log("debug", "Skipping %s: No resource bound", stanza.attr.to);
return true;
end
-- Per XEP we know that stanza.attr.to is the user's bare JID
for _, resource in pairs(user_resources[stanza.attr.to]) do
for _, session in pairs(prosody.bare_sessions[stanza.attr.to].sessions) do
-- TODO: Only send to resources that advertise support for MIX (When MIX clients are available for testing)
local msg = st.clone(stanza);
msg.attr.to = stanza.attr.to.."/"..resource;
module:send(msg);
msg.attr.to = stanza.attr.to.."/"..session.resource;
session:send(msg);
module:log("debug", "Sent message to %s", msg.attr.to);
end
return true;