Comparison

plugins/mod_muc_mam.lua @ 11876:52a1b885044e

mod_muc_mam: Use util.dataforms timestamp validation
author Kim Alvefur <zash@zash.se>
date Tue, 26 Oct 2021 13:35:04 +0200
parent 11818:c443abff04d8
child 11968:6e1af07921d1
comparison
equal deleted inserted replaced
11875:210a785dfa8a 11876:52a1b885044e
29 29
30 local is_stanza = st.is_stanza; 30 local is_stanza = st.is_stanza;
31 local tostring = tostring; 31 local tostring = tostring;
32 local time_now = os.time; 32 local time_now = os.time;
33 local m_min = math.min; 33 local m_min = math.min;
34 local timestamp, timestamp_parse, datestamp = import( "util.datetime", "datetime", "parse", "date"); 34 local timestamp, datestamp = import("util.datetime", "datetime", "date");
35 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); 35 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
36 36
37 local cleanup_after = module:get_option_string("muc_log_expires_after", "1w"); 37 local cleanup_after = module:get_option_string("muc_log_expires_after", "1w");
38 local cleanup_interval = module:get_option_number("muc_log_cleanup_interval", 4 * 60 * 60); 38 local cleanup_interval = module:get_option_number("muc_log_cleanup_interval", 4 * 60 * 60);
39 39
102 end); 102 end);
103 end 103 end
104 104
105 -- Note: We ignore the 'with' field as this is internally used for stanza types 105 -- Note: We ignore the 'with' field as this is internally used for stanza types
106 local query_form = dataform { 106 local query_form = dataform {
107 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; }; 107 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam };
108 { name = "with"; type = "jid-single"; }; 108 { name = "with"; type = "jid-single" };
109 { name = "start"; type = "text-single" }; 109 { name = "start"; type = "text-single"; datatype = "xs:dateTime" };
110 { name = "end"; type = "text-single"; }; 110 { name = "end"; type = "text-single"; datatype = "xs:dateTime" };
111 }; 111 };
112 112
113 -- Serve form 113 -- Serve form
114 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) 114 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event)
115 local origin, stanza = event.origin, event.stanza; 115 local origin, stanza = event.origin, event.stanza;
162 return true; 162 return true;
163 end 163 end
164 qstart, qend = form["start"], form["end"]; 164 qstart, qend = form["start"], form["end"];
165 qbefore, qafter = form["before-id"], form["after-id"]; 165 qbefore, qafter = form["before-id"], form["after-id"];
166 qids = form["ids"]; 166 qids = form["ids"];
167 end
168
169 if qstart or qend then -- Validate timestamps
170 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend))
171 if (qstart and not vstart) or (qend and not vend) then
172 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid timestamp"))
173 return true;
174 end
175 qstart, qend = vstart, vend;
176 end 167 end
177 168
178 -- RSM stuff 169 -- RSM stuff
179 local qset = rsm.get(query); 170 local qset = rsm.get(query);
180 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); 171 local qmax = m_min(qset and qset.max or default_max_items, max_max_items);