# HG changeset patch # User Kim Alvefur # Date 1582925921 -3600 # Node ID 3c3d216c6f6dd52e0fbc4b29e32ca0c38a34fb9e # Parent ea59c9455f932d427b54fb0c5bd7faa6db83c290 mod_rest: Add JSON mapping of XEP-0039: Statistics Gathering diff -r ea59c9455f93 -r 3c3d216c6f6d mod_rest/jsonmap.lib.lua --- a/mod_rest/jsonmap.lib.lua Fri Feb 28 22:24:49 2020 +0100 +++ b/mod_rest/jsonmap.lib.lua Fri Feb 28 22:38:41 2020 +0100 @@ -344,6 +344,31 @@ return form; end }; + + -- XEP-0039: Statistics Gathering + stats = { type = "func", xmlns = "http://jabber.org/protocol/stats", tagname = "query", + st2json = function (s) + local o = array(); + for stat in s:childtags("stat") do + o:push({ + name = stat.attr.name; + unit = stat.attr.unit; + value = stat.attr.value; + }); + end + return o; + end; + json2st = function (j) + local stats = st.stanza("query", { xmlns = "http://jabber.org/protocol/stats" }); + if type(j) == "table" then + for _, stat in ipairs(j) do + stats:tag("stat", { name = stat.name, unit = stat.unit, value = stat.value }):up(); + end + end + return stats; + end; + }; + }; local implied_kinds = {