aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-12 01:33:15 +0100
committerKim Alvefur <zash@zash.se>2021-03-12 01:33:15 +0100
commit9d25c9c9acf15902082d7d2520f9e161431ddde2 (patch)
treed8dcafcf4b439841d2fc566f657bdab25cc8a3fd /teal-src
parent465a8b8b1a2f9424d2f8ff9620279d051b741a78 (diff)
downloadprosody-9d25c9c9acf15902082d7d2520f9e161431ddde2.tar.gz
prosody-9d25c9c9acf15902082d7d2520f9e161431ddde2.zip
util.datamapper: Enumerated elements
E.g. error conditions or chat states.
Diffstat (limited to 'teal-src')
-rw-r--r--teal-src/util/datamapper.tl21
1 files changed, 20 insertions, 1 deletions
diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl
index 7aec331b..fac2acce 100644
--- a/teal-src/util/datamapper.tl
+++ b/teal-src/util/datamapper.tl
@@ -42,6 +42,7 @@ local function parse_object (schema : js.schema_t, s : st.stanza_t) : table
local is_text = false
local name_is_value = false;
local single_attribute : string
+ local enums : { any }
local proptype : js.schema_t.type_e
if propschema is js.schema_t then
@@ -72,10 +73,28 @@ local function parse_object (schema : js.schema_t, s : st.stanza_t) : table
-- XXX Custom extension
single_attribute = propschema.xml.x_single_attribute
end
+ if propschema["const"] then
+ enums = { propschema["const"] }
+ elseif propschema["enum"] then
+ enums = propschema["enum"]
+ end
end
if name_is_value then
- local c = s:get_child(nil, namespace);
+ local c : st.stanza_t
+ if proptype == "boolean" then
+ c = s:get_child(name, namespace);
+ elseif enums and proptype == "string" then
+ -- XXX O(n²) ?
+ -- Probably better to flip the table and loop over :childtags(nil, ns), should be 2xO(n)
+ -- BUT works first, optimize later
+ for i = 1, #enums do
+ c = s:get_child(enums[i] as string, namespace);
+ if c then break end
+ end
+ else
+ c = s:get_child(nil, namespace);
+ end
if c and proptype == "string" then
out[prop] = c.name;
elseif proptype == "boolean" and c then