Software /
code /
prosody
Diff
util/datamapper.lua @ 11453:f0037234b2e9
util.datamapper: Enumerated elements
E.g. error conditions or chat states.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Mar 2021 01:33:15 +0100 |
parent | 11451:ee4f2296e7df |
child | 11454:1d9c1893cc5e |
line wrap: on
line diff
--- a/util/datamapper.lua Wed Mar 10 00:19:45 2021 +0100 +++ b/util/datamapper.lua Fri Mar 12 01:33:15 2021 +0100 @@ -20,6 +20,7 @@ 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 @@ 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