Mercurial > prosody-modules
comparison mod_compat_muc_admin/mod_compat_muc_admin.lua @ 629:7d4cde86b12e
mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
| author | Marco Cirillo <maranda@lightwitch.org> |
|---|---|
| date | Tue, 27 Mar 2012 16:51:59 +0000 |
| parents | c72be31941fa |
| children | ab2a1564da9b |
comparison
equal
deleted
inserted
replaced
| 628:c72be31941fa | 629:7d4cde86b12e |
|---|---|
| 7 | 7 |
| 8 if not hosts[muc_host].modules.muc then -- Not a MUC host | 8 if not hosts[muc_host].modules.muc then -- Not a MUC host |
| 9 module:log("error", "this module can only be used on muc hosts."); return false; | 9 module:log("error", "this module can only be used on muc hosts."); return false; |
| 10 end | 10 end |
| 11 | 11 |
| 12 -- Constants and imported functions from muc.lib.lua | |
| 12 local xmlns_ma, xmlns_mo = "http://jabber.org/protocol/muc#admin", "http://jabber.org/protocol/muc#owner"; | 13 local xmlns_ma, xmlns_mo = "http://jabber.org/protocol/muc#admin", "http://jabber.org/protocol/muc#owner"; |
| 14 local kickable_error_conditions = { | |
| 15 ["gone"] = true; | |
| 16 ["internal-server-error"] = true; | |
| 17 ["item-not-found"] = true; | |
| 18 ["jid-malformed"] = true; | |
| 19 ["recipient-unavailable"] = true; | |
| 20 ["redirect"] = true; | |
| 21 ["remote-server-not-found"] = true; | |
| 22 ["remote-server-timeout"] = true; | |
| 23 ["service-unavailable"] = true; | |
| 24 ["malformed error"] = true; | |
| 25 }; | |
| 26 local function is_kickable_error(stanza) | |
| 27 local cond = get_error_condition(stanza); | |
| 28 return kickable_error_conditions[cond] and cond; | |
| 29 end | |
| 30 local function build_unavailable_presence_from_error(stanza) | |
| 31 local type, condition, text = stanza:get_error(); | |
| 32 local error_message = "Kicked: "..(condition and condition:gsub("%-", " ") or "presence error"); | |
| 33 if text then | |
| 34 error_message = error_message..": "..text; | |
| 35 end | |
| 36 return st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) | |
| 37 :tag('status'):text(error_message); | |
| 38 end | |
| 39 local function getText(stanza, path) return getUsingPath(stanza, path, true); end | |
| 13 | 40 |
| 14 -- COMPAT: iq condensed function | 41 -- COMPAT: iq condensed function |
| 15 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["compat_iq"] = function (self, origin, stanza, xmlns) | 42 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["compat_iq"] = function (self, origin, stanza, xmlns) |
| 16 local actor = stanza.attr.from; | 43 local actor = stanza.attr.from; |
| 17 local affiliation = self:get_affiliation(actor); | 44 local affiliation = self:get_affiliation(actor); |
| 95 if stanza.name == "iq" then | 122 if stanza.name == "iq" then |
| 96 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then | 123 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then |
| 97 origin.send(self:get_disco_info(stanza)); | 124 origin.send(self:get_disco_info(stanza)); |
| 98 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then | 125 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then |
| 99 origin.send(self:get_disco_items(stanza)); | 126 origin.send(self:get_disco_items(stanza)); |
| 100 elseif (xmlns == xmlns_ma or xmlns == xmlns_mo) then | 127 elseif xmlns == xmlns_ma or xmlns == xmlns_mo then |
| 101 if xmlns == xmlns_ma then | 128 if xmlns == xmlns_ma then |
| 102 self:compat_iq(origin, stanza, xmlns); | 129 self:compat_iq(origin, stanza, xmlns); |
| 103 elseif xmlns == xmlns_mo and stanza.tags[1].name == "query" and #stanza.tags[1].tags == 0 and | 130 elseif xmlns == xmlns_mo and (type == "set" or type == "get") and stanza.tags[1].name == "query" then |
| 104 stanza.attr.type == "get" then -- form request | 131 local owner_err = st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms"); |
| 105 if self:get_affiliation(stanza.attr.from) ~= "owner" then | 132 if #stanza.tags[1].tags == 0 and stanza.attr.type == "get" then |
| 106 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms")); | 133 if self:get_affiliation(stanza.attr.from) ~= "owner" then |
| 107 else | 134 origin.send(owner_err); |
| 108 self:send_form(origin, stanza); | 135 else self:send_form(origin, stanza); end |
| 109 end | 136 elseif stanza.attr.type == "set" and stanza.tags[1]:get_child("x", "jabber:x:data") then |
| 110 elseif xmlns == xmlns_mo and stanza.tags[1].name == "query" and stanza.tags[1]:get_child("x", "jabber:x:data") and | 137 if self:get_affiliation(stanza.attr.from) ~= "owner" then |
| 111 stanza.attr.type == "set" then | 138 origin.send(owner_err); |
| 112 if self:get_affiliation(stanza.attr.from) ~= "owner" then | 139 else self:process_form(origin, stanza); end |
| 113 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms")); | 140 elseif stanza.tags[1].tags[1].name == "destroy" then |
| 114 else | |
| 115 self:process_form(origin, stanza); | |
| 116 end | |
| 117 elseif xmlns == xmlns_mo and stanza.tags[1].tags[1] then | |
| 118 local child = stanza.tags[1].tags[1]; | |
| 119 if child.name == "destroy" then | |
| 120 if self:get_affiliation(stanza.attr.from) == "owner" then | 141 if self:get_affiliation(stanza.attr.from) == "owner" then |
| 121 local newjid = child.attr.jid; | 142 local newjid = child.attr.jid; |
| 122 local reason, password; | 143 local reason, password; |
| 123 for _,tag in ipairs(child.tags) do | 144 for _,tag in ipairs(child.tags) do |
| 124 if tag.name == "reason" then | 145 if tag.name == "reason" then |
| 127 password = #tag.tags == 0 and tag[1]; | 148 password = #tag.tags == 0 and tag[1]; |
| 128 end | 149 end |
| 129 end | 150 end |
| 130 self:destroy(newjid, reason, password); | 151 self:destroy(newjid, reason, password); |
| 131 origin.send(st.reply(stanza)); | 152 origin.send(st.reply(stanza)); |
| 132 else origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can destroy rooms")); end | 153 else origin.send(owner_err); end |
| 133 else | 154 else |
| 134 self:compat_iq(origin, stanza, xmlns); | 155 self:compat_iq(origin, stanza, xmlns); |
| 135 end | 156 end |
| 136 else | 157 else |
| 137 origin.send(st.error_reply(stanza, "modify", "bad-request")); | 158 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
| 217 else | 238 else |
| 218 if type == "error" or type == "result" then return; end | 239 if type == "error" or type == "result" then return; end |
| 219 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 240 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
| 220 end | 241 end |
| 221 end | 242 end |
| 222 | |
| 223 |
