mod_mix_pam: Fix ID and mix host tracking
This commit is contained in:
parent
fd9735faba
commit
5decc47af9
@ -120,7 +120,7 @@ local function handle_client_join(event)
|
|||||||
});
|
});
|
||||||
join_iq:add_child(join);
|
join_iq:add_child(join);
|
||||||
|
|
||||||
add_state(stanza.attr.id, jid.resource(from));
|
add_state(stanza.attr.id, origin);
|
||||||
|
|
||||||
module:send(join_iq);
|
module:send(join_iq);
|
||||||
return true;
|
return true;
|
||||||
@ -152,7 +152,7 @@ local function handle_client_leave(event)
|
|||||||
});
|
});
|
||||||
leave_iq:add_child(leave);
|
leave_iq:add_child(leave);
|
||||||
|
|
||||||
add_state(stanza.attr.id, jid.resource(from));
|
add_state(stanza.attr.id, origin);
|
||||||
|
|
||||||
module:send(leave_iq);
|
module:send(leave_iq);
|
||||||
return true;
|
return true;
|
||||||
@ -196,12 +196,12 @@ local function handle_mix_join(event)
|
|||||||
|
|
||||||
-- TODO: Error handling?
|
-- TODO: Error handling?
|
||||||
rm_add_to_roster(origin, stanza.attr.from, {
|
rm_add_to_roster(origin, stanza.attr.from, {
|
||||||
subscription = "both",
|
subscription = "from",
|
||||||
groups = {},
|
groups = {},
|
||||||
mix_spid = spid,
|
mix_spid = spid,
|
||||||
});
|
});
|
||||||
rm_roster_push(jid.node(stanza.attr.to), module_host, stanza.attr.from);
|
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;
|
return true;
|
||||||
end
|
end
|
||||||
@ -248,7 +248,8 @@ module:hook("iq/bare", function(event)
|
|||||||
return handle_mix_join(event);
|
return handle_mix_join(event);
|
||||||
elseif has_state(event.stanza.attr.id) then
|
elseif has_state(event.stanza.attr.id) then
|
||||||
local tmp = st.clone(event.stanza);
|
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);
|
module:send(tmp);
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
@ -283,24 +284,6 @@ 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
|
||||||
@ -313,14 +296,18 @@ 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, item in pairs(rm_load_roster(jid.bare(stanza.attr.from))) do
|
for contact, roster_item in pairs(roster) do
|
||||||
if item["mix_spid"] ~= nil then
|
if roster_item["mix_spid"] ~= nil then
|
||||||
local roster_item = child_with_attrs(query, "item", nil, { jid = contact });
|
for _, item in ipairs(query:childtags("item")) do
|
||||||
if roster_item then
|
if item.attr.jid == contact then
|
||||||
roster_item:tag("channel", { xmlns = mix_roster_xmlns, ["participant-id"] = item["mix_spid"] });
|
item:tag("channel", {
|
||||||
else
|
xmlns = mix_roster_xmlns,
|
||||||
module:log("warn", "Could not find %s during annotated roster query!");
|
["participant-id"] = roster_item["mix_spid"],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user