From 7bc9f73c736d558386cfbce9d57a7dddd0b5479b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Jun 2018 19:57:46 +0200 Subject: util.dataforms: Add a simple function for identifying form types This is meant to allow identifying forms without parsing them completely. --- util/dataforms.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'util/dataforms.lua') diff --git a/util/dataforms.lua b/util/dataforms.lua index 8c5b8ee2..7b832f78 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -249,8 +249,24 @@ field_readers["hidden"] = return field_tag:get_child_text("value"); end + +local function get_form_type(form) + if not st.is_stanza(form) then + return nil, "not a stanza object"; + elseif form.attr.xmlns ~= "jabber:x:data" or form.name ~= "x" then + return nil, "not a dataform element"; + end + for field in form:childtags("field") do + if field.attr.var == "FORM_TYPE" then + return field:get_child_text("value"); + end + end + return ""; +end + return { new = new; + get_type = get_form_type; }; -- cgit v1.2.3