Comparison

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
comparison
equal deleted inserted replaced
8863:64fa8d80c09f 8864:cf2f66b233d1
247 field_readers["hidden"] = 247 field_readers["hidden"] =
248 function (field_tag) 248 function (field_tag)
249 return field_tag:get_child_text("value"); 249 return field_tag:get_child_text("value");
250 end 250 end
251 251
252
253 local function get_form_type(form)
254 if not st.is_stanza(form) then
255 return nil, "not a stanza object";
256 elseif form.attr.xmlns ~= "jabber:x:data" or form.name ~= "x" then
257 return nil, "not a dataform element";
258 end
259 for field in form:childtags("field") do
260 if field.attr.var == "FORM_TYPE" then
261 return field:get_child_text("value");
262 end
263 end
264 return "";
265 end
266
252 return { 267 return {
253 new = new; 268 new = new;
269 get_type = get_form_type;
254 }; 270 };
255 271
256 272
257 --[=[ 273 --[=[
258 274