aboutsummaryrefslogtreecommitdiffstats
path: root/util/datamapper.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-20 20:45:06 +0100
committerKim Alvefur <zash@zash.se>2021-03-20 20:45:06 +0100
commitf5962d7193fbd92687248ef97b4673248defc751 (patch)
tree2ebebcbac764078d4f3e17072cdad64ebe3df0b2 /util/datamapper.lua
parent87474145e51cd0460e8c6608c2dcb7a712d9ef3c (diff)
downloadprosody-f5962d7193fbd92687248ef97b4673248defc751.tar.gz
prosody-f5962d7193fbd92687248ef97b4673248defc751.zip
util.datamapper: Finally implement support for parsing arrays
Diffstat (limited to 'util/datamapper.lua')
-rw-r--r--util/datamapper.lua22
1 files changed, 9 insertions, 13 deletions
diff --git a/util/datamapper.lua b/util/datamapper.lua
index 32d01050..943daee1 100644
--- a/util/datamapper.lua
+++ b/util/datamapper.lua
@@ -27,7 +27,7 @@ local value_goes = {}
local function unpack_propschema(propschema, propname, current_ns)
local proptype = "string"
- local value_where = "in_text_tag"
+ local value_where = propname and "in_text_tag" or "in_text"
local name = propname
local namespace = current_ns
local prefix
@@ -158,21 +158,17 @@ function parse_object(schema, s)
end
function parse_array(schema, s)
- local proptype, value_where, child_name, namespace = unpack_propschema(schema.items, nil, s.attr.xmlns)
+ local proptype, value_where, child_name, namespace, prefix, single_attribute, enums = unpack_propschema(schema.items, nil, s.attr.xmlns)
+ local attr_name
+ if value_where == "in_single_attribute" then
+ value_where = "in_attribute";
+ attr_name = single_attribute;
+ end
local out = {}
for c in s:childtags(child_name, namespace) do
- local value;
- if value_where == "in_text_tag" then
- value = c:get_text();
- else
- error("NYI")
- end
-
- value = totype(proptype, value)
+ local value = extract_value(c, value_where, proptype, attr_name or child_name, namespace, prefix, single_attribute, enums)
- if value ~= nil then
- table.insert(out, value);
- end
+ table.insert(out, totype(proptype, value));
end
return out
end