Software /
code /
prosody
Comparison
util/dataforms.lua @ 8863:64fa8d80c09f
util.dataforms: Remove string conversion to let util.stanza validate types
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 02 Jun 2018 19:49:15 +0200 |
parent | 8555:4f0f5b49bb03 |
child | 8864:cf2f66b233d1 |
comparison
equal
deleted
inserted
replaced
8862:900dff5ef498 | 8863:64fa8d80c09f |
---|---|
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local setmetatable = setmetatable; | 9 local setmetatable = setmetatable; |
10 local ipairs = ipairs; | 10 local ipairs = ipairs; |
11 local tostring, type, next = tostring, type, next; | 11 local type, next = type, next; |
12 local t_concat = table.concat; | 12 local t_concat = table.concat; |
13 local st = require "util.stanza"; | 13 local st = require "util.stanza"; |
14 local jid_prep = require "util.jid".prep; | 14 local jid_prep = require "util.jid".prep; |
15 | 15 |
16 local _ENV = nil; | 16 local _ENV = nil; |
47 -- Assume an XML snippet | 47 -- Assume an XML snippet |
48 form:tag("value") | 48 form:tag("value") |
49 :add_child(value) | 49 :add_child(value) |
50 :up(); | 50 :up(); |
51 else | 51 else |
52 form:tag("value"):text(tostring(value)):up(); | 52 form:tag("value"):text(value):up(); |
53 end | 53 end |
54 elseif field_type == "boolean" then | 54 elseif field_type == "boolean" then |
55 form:tag("value"):text((value and "1") or "0"):up(); | 55 form:tag("value"):text((value and "1") or "0"):up(); |
56 elseif field_type == "fixed" then | 56 elseif field_type == "fixed" then |
57 form:tag("value"):text(value):up(); | 57 form:tag("value"):text(value):up(); |
77 if value == val.value or val.default and (not has_default) then | 77 if value == val.value or val.default and (not has_default) then |
78 form:tag("value"):text(val.value):up(); | 78 form:tag("value"):text(val.value):up(); |
79 has_default = true; | 79 has_default = true; |
80 end | 80 end |
81 else | 81 else |
82 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | 82 form:tag("option", { label= val }):tag("value"):text(val):up():up(); |
83 end | 83 end |
84 end | 84 end |
85 end | 85 end |
86 if (field.options or formtype == "result") and value then | 86 if (field.options or formtype == "result") and value then |
87 form:tag("value"):text(value):up(); | 87 form:tag("value"):text(value):up(); |
93 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 93 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
94 if not field.options and val.default then | 94 if not field.options and val.default then |
95 form:tag("value"):text(val.value):up(); | 95 form:tag("value"):text(val.value):up(); |
96 end | 96 end |
97 else | 97 else |
98 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | 98 form:tag("option", { label= val }):tag("value"):text(val):up():up(); |
99 end | 99 end |
100 end | 100 end |
101 end | 101 end |
102 if (field.options or formtype == "result") and value then | 102 if (field.options or formtype == "result") and value then |
103 for _, val in ipairs(value) do | 103 for _, val in ipairs(value) do |