Merge 0.10->trunk
[prosody.git] / plugins / muc / muc.lib.lua
index cb182fecc2950e029f132570a3ad79c65e07af58..8fec0ffca557ba63a0ede668a67a9db4640ab1c4 100644 (file)
@@ -546,7 +546,7 @@ function room_mt:handle_iq_to_occupant(origin, stanza)
        if (type == "error" or type == "result") then
                do -- deconstruct_stanza_id
                        if not occupant then return nil; end
-                       local from_jid, id, to_jid_hash = (base64.decode(stanza.attr.id) or ""):match("^(.+)%z(.*)%z(.+)$");
+                       local from_jid, id, to_jid_hash = (base64.decode(stanza.attr.id) or ""):match("^(%Z+)%z(%Z*)%z(.+)$");
                        if not(from == from_jid or from == jid_bare(from_jid)) then return nil; end
                        local from_occupant_jid = self:get_occupant_jid(from_jid);
                        if from_occupant_jid == nil then return nil; end
@@ -644,11 +644,11 @@ function room_mt:process_form(origin, stanza)
        if form.attr.type == "cancel" then
                origin.send(st.reply(stanza));
        elseif form.attr.type == "submit" then
-               local fields;
+               local fields, errors, present;
                if form.tags[1] == nil then -- Instant room
-                       fields = {};
+                       fields, present = {}, {};
                else
-                       fields = self:get_form_layout(stanza.attr.from):data(form);
+                       fields, errors, present = self:get_form_layout(stanza.attr.from):data(form);
                        if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then
                                origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration"));
                                return true;
@@ -666,6 +666,11 @@ function room_mt:process_form(origin, stanza)
                        return true;
                end
                module:fire_event("muc-config-submitted", event);
+               for submitted_field in pairs(present) do
+                       event.field, event.value = submitted_field, fields[submitted_field];
+                       module:fire_event("muc-config-submitted/"..submitted_field, event);
+               end
+               event.field, event.value = nil, nil;
 
                if self.save then self:save(true); end
                origin.send(st.reply(stanza));
@@ -723,6 +728,9 @@ end
 
 function room_mt:handle_admin_query_set_command(origin, stanza)
        local item = stanza.tags[1].tags[1];
+       if not item then
+               origin.send(st.error_reply(stanza, "cancel", "bad-request"));
+       end
        if item.attr.jid then -- Validate provided JID
                item.attr.jid = jid_prep(item.attr.jid);
                if not item.attr.jid then