Comparison

plugins/mod_muc_mam.lua @ 9844:3de80fc511ab

mod_muc_mam: Validate that the FORM_TYPE of a query is as expected
author Kim Alvefur <zash@zash.se>
date Mon, 04 Mar 2019 13:13:37 +0100
parent 9552:87e25d352de3
child 9845:774b2ce62318
comparison
equal deleted inserted replaced
9839:9007ae90aeb1 9844:3de80fc511ab
19 local rsm = require "util.rsm"; 19 local rsm = require "util.rsm";
20 local jid_bare = require "util.jid".bare; 20 local jid_bare = require "util.jid".bare;
21 local jid_split = require "util.jid".split; 21 local jid_split = require "util.jid".split;
22 local jid_prep = require "util.jid".prep; 22 local jid_prep = require "util.jid".prep;
23 local dataform = require "util.dataforms".new; 23 local dataform = require "util.dataforms".new;
24 local get_form_type = require "util.dataforms".get_type;
24 25
25 local mod_muc = module:depends"muc"; 26 local mod_muc = module:depends"muc";
26 local get_room_from_jid = mod_muc.get_room_from_jid; 27 local get_room_from_jid = mod_muc.get_room_from_jid;
27 28
28 local is_stanza = st.is_stanza; 29 local is_stanza = st.is_stanza;
129 130
130 -- Search query parameters 131 -- Search query parameters
131 local qstart, qend; 132 local qstart, qend;
132 local form = query:get_child("x", "jabber:x:data"); 133 local form = query:get_child("x", "jabber:x:data");
133 if form then 134 if form then
134 local err; 135 local form_type, err = get_form_type(form);
136 if form_type ~= xmlns_mam then
137 origin.send(st.error_reply(stanza, "modify", "bad-request", "Unexpected FORM_TYPE, expected '"..xmlns_mam.."'"));
138 return true;
139 end
135 form, err = query_form:data(form); 140 form, err = query_form:data(form);
136 if err then 141 if err then
137 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); 142 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err))));
138 return true; 143 return true;
139 end 144 end