From 5ca2c3be1da01c7aa1c6a40f1eeb6b630f838895 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 7 Sep 2009 20:33:24 +0500 Subject: MUC: Added support for requesting various lists (owner, admin, voice, etc). --- plugins/muc/muc.lib.lua | 61 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 14 deletions(-) (limited to 'plugins/muc') diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 7133d133..8cf20b09 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -318,24 +318,57 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha else origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); end - elseif stanza.name == "iq" and type == "set" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#admin" then + elseif stanza.name == "iq" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#admin" then local actor = stanza.attr.from; local affiliation = self:get_affiliation(actor); local current_nick = self._jid_nick[actor]; local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation); - local item = stanza.tags[1].tags[1]; + local item = stanza.tags[1] and stanza.tags[1].tags[1]; if item and item.name == "item" then - local callback = function() origin.send(st.reply(stanza)); end - if item.attr.affiliation and item.attr.jid and not item.attr.role and not item.attr.nick then - local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); - if not success then origin.send(st.error_reply(stanza, errtype, err)); end - elseif item.attr.role and item.attr.nick and not item.attr.affiliation and not item.attr.jid then - local success, errtype, err = self:set_role(actor, item.attr.nick, item.attr.role, callback); - if not success then origin.send(st.error_reply(stanza, errtype, err)); end - else - origin.send(st.error_reply(stanza, "cancel", "bad-request")); + if type == "set" then + local callback = function() origin.send(st.reply(stanza)); end + if item.attr.affiliation and item.attr.jid and not item.attr.role and not item.attr.nick then + local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); + if not success then origin.send(st.error_reply(stanza, errtype, err)); end + elseif item.attr.role and item.attr.nick and not item.attr.affiliation and not item.attr.jid then + local success, errtype, err = self:set_role(actor, item.attr.nick, item.attr.role, callback); + if not success then origin.send(st.error_reply(stanza, errtype, err)); end + else + origin.send(st.error_reply(stanza, "cancel", "bad-request")); + end + elseif type == "get" then + local _aff = item.attr.affiliation; + local _rol = item.attr.role; + if _aff and not _rol then + if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then + local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); + for jid, affiliation in pairs(self._affiliations) do + if affiliation == _aff then + reply:tag("item", {affiliation = _aff, jid = jid}):up(); + end + end + origin.send(reply); + else + origin.send(st.error_reply(stanza, "auth", "forbidden")); + end + elseif _rol and not _aff then + if role == "moderator" then -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? + if _rol == "none" then _rol = nil; end + local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); + for nick, occupant in pairs(self._occupants) do + if occupant.role == _rol then + reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); + end + end + origin.send(reply); + else + origin.send(st.error_reply(stanza, "auth", "forbidden")); + end + else + origin.send(st.error_reply(stanza, "cancel", "bad-request")); + end end - else + elseif type == "set" or type == "get" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); end elseif stanza.name == "message" and type == "groupchat" then @@ -410,7 +443,7 @@ function room_mt:set_affiliation(actor, jid, affiliation, callback) local role = self:get_default_role(affiliation); local p = st.presence({type = "unavailable"}) :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) - :tag("item", {affiliation=affiliation, role=role or "none"}):up(); + :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up(); local x = p.tags[1]; local item = x.tags[1]; if not role then -- getting kicked @@ -457,7 +490,7 @@ function room_mt:set_role(actor, nick, role, callback) if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end local p = st.presence({from = nick, type = "unavailable"}) :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) - :tag("item", {affiliation=occupant.affiliation, nick=nick, role=role or "none"}):up(); + :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}):up(); if not role then -- kick self._occupants[nick] = nil; for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick -- cgit v1.2.3