diff options
author | Kim Alvefur <zash@zash.se> | 2021-03-12 01:33:15 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-03-12 01:33:15 +0100 |
commit | 9d25c9c9acf15902082d7d2520f9e161431ddde2 (patch) | |
tree | d8dcafcf4b439841d2fc566f657bdab25cc8a3fd /util/datamapper.lua | |
parent | 465a8b8b1a2f9424d2f8ff9620279d051b741a78 (diff) | |
download | prosody-9d25c9c9acf15902082d7d2520f9e161431ddde2.tar.gz prosody-9d25c9c9acf15902082d7d2520f9e161431ddde2.zip |
util.datamapper: Enumerated elements
E.g. error conditions or chat states.
Diffstat (limited to 'util/datamapper.lua')
-rw-r--r-- | util/datamapper.lua | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/util/datamapper.lua b/util/datamapper.lua index 35788499..092497d7 100644 --- a/util/datamapper.lua +++ b/util/datamapper.lua @@ -20,6 +20,7 @@ local function parse_object(schema, s) local is_text = false local name_is_value = false; local single_attribute + local enums local proptype if type(propschema) == "table" then @@ -50,10 +51,28 @@ local function parse_object(schema, s) 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 + if proptype == "boolean" then + c = s:get_child(name, namespace); + elseif enums and proptype == "string" then + + for i = 1, #enums do + c = s:get_child(enums[i], 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 |