From 533ab7a4ce6c55acd164cdcea6d8a6abe3db4bca Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 26 Oct 2021 13:35:04 +0200 Subject: mod_muc_mam: Use util.dataforms timestamp validation --- plugins/mod_muc_mam.lua | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'plugins/mod_muc_mam.lua') diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index 289359f4..1edcec22 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -31,7 +31,7 @@ local is_stanza = st.is_stanza; local tostring = tostring; local time_now = os.time; local m_min = math.min; -local timestamp, timestamp_parse, datestamp = import( "util.datetime", "datetime", "parse", "date"); +local timestamp, datestamp = import("util.datetime", "datetime", "date"); local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); local cleanup_after = module:get_option_string("muc_log_expires_after", "1w"); @@ -104,10 +104,10 @@ end -- Note: We ignore the 'with' field as this is internally used for stanza types local query_form = dataform { - { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; }; - { name = "with"; type = "jid-single"; }; - { name = "start"; type = "text-single" }; - { name = "end"; type = "text-single"; }; + { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam }; + { name = "with"; type = "jid-single" }; + { name = "start"; type = "text-single"; datatype = "xs:dateTime" }; + { name = "end"; type = "text-single"; datatype = "xs:dateTime" }; }; -- Serve form @@ -166,15 +166,6 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) qids = form["ids"]; end - if qstart or qend then -- Validate timestamps - local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend)) - if (qstart and not vstart) or (qend and not vend) then - origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid timestamp")) - return true; - end - qstart, qend = vstart, vend; - end - -- RSM stuff local qset = rsm.get(query); local qmax = m_min(qset and qset.max or default_max_items, max_max_items); -- cgit v1.2.3