Comparison

plugins/muc/muc.lib.lua @ 6982:c515f9491ce6

MUC: Process only options that are included in a form (Fixes #521)
author Kim Alvefur <zash@zash.se>
date Tue, 08 Dec 2015 20:19:30 +0100
parent 6924:c37ad3e1fdd9
child 6983:05ef46379165
comparison
equal deleted inserted replaced
6981:bcaa553de6e8 6982:c515f9491ce6
672 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end 672 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end
673 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end 673 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end
674 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end 674 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end
675 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end 675 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end
676 676
677 local fields = self:get_form_layout(stanza.attr.from):data(form); 677 local fields, errors, present = self:get_form_layout(stanza.attr.from):data(form);
678 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then 678 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then
679 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); 679 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration"));
680 return; 680 return;
681 end 681 end
682 682
683 local changed = {}; 683 local changed = {};
684 684
685 local function handle_option(name, field, allowed) 685 local function handle_option(name, field, allowed)
686 local new = fields[field]; 686 local new, err, included = fields[field], errors[field], present[field];
687 if new == nil then return; end 687 if not included then return; end
688 if allowed and not allowed[new] then return; end 688 if allowed and not allowed[new] then return; end
689 if new == self["get_"..name](self) then return; end 689 if new == self["get_"..name](self) then return; end
690 changed[name] = true; 690 changed[name] = true;
691 self["set_"..name](self, new); 691 self["set_"..name](self, new);
692 end 692 end