Software /
code /
prosody
Diff
util/dataforms.lua @ 8864:cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
This is meant to allow identifying forms without parsing them
completely.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 02 Jun 2018 19:57:46 +0200 |
parent | 8863:64fa8d80c09f |
child | 8945:cbeb1a045eb6 |
line wrap: on
line diff
--- a/util/dataforms.lua Sat Jun 02 19:49:15 2018 +0200 +++ b/util/dataforms.lua Sat Jun 02 19:57:46 2018 +0200 @@ -249,8 +249,24 @@ 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; };