Software /
code /
prosody
File
tools/form2table.lua @ 13110:d5f322dd424b 0.12
mod_s2s: Add event where resolver for s2sout can be tweaked
Could be used to implement custom connection methods (c.f. mod_onions)
without needing to duplicate the rest of route_to_new_session().
Adds a feature to enable detection since it can be difficult to detect
support for an event otherwise.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Aug 2022 03:26:32 +0200 |
parent | 11194:9d1ce6f28401 |
child | 13142:879a6a33c21b |
line wrap: on
line source
-- Read an XML dataform and spit out a serialized Lua table of it local function from_stanza(stanza) local layout = { title = stanza:get_child_text("title"); instructions = stanza:get_child_text("instructions"); }; for tag in stanza:childtags("field") do local field = { name = tag.attr.var; type = tag.attr.type; label = tag.attr.label; desc = tag:get_child_text("desc"); required = tag:get_child("required") and true or nil; value = tag:get_child_text("value"); options = nil; }; if field.type == "list-single" or field.type == "list-multi" then local options = {}; for option in tag:childtags("option") do options[#options+1] = { label = option.attr.label, value = option:get_child_text("value") }; end field.options = options; end if field.type == "jid-multi" or field.type == "list-multi" or field.type == "text-multi" then local values = {}; for value in tag:childtags("value") do values[#values+1] = value:get_text(); end if field.type == "text-multi" then values = table.concat(values, "\n"); end field.value = values; end if field.type == "boolean" then field.value = field.value == "true" or field.value == "1"; end layout[#layout+1] = field; end return layout; end print("dataforms.new " .. require "util.serialization".serialize(from_stanza(require "util.xml".parse(io.read("*a"))), { unquoted = true }))