# HG changeset patch # User Kim Alvefur # Date 1616368887 -3600 # Node ID ea1fd703bb275089988989c290e6a09e315f82f8 # Parent 073f5397c1d2faa83a07d6cac313118df44acb10 mod_rest: Convert XEP-0039 to datamapping diff -r 073f5397c1d2 -r ea1fd703bb27 mod_rest/jsonmap.lib.lua --- a/mod_rest/jsonmap.lib.lua Sun Mar 21 23:54:06 2021 +0100 +++ b/mod_rest/jsonmap.lib.lua Mon Mar 22 00:21:27 2021 +0100 @@ -353,30 +353,6 @@ 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 byxmlname = {}; diff -r 073f5397c1d2 -r ea1fd703bb27 mod_rest/res/schema-xmpp.json --- a/mod_rest/res/schema-xmpp.json Sun Mar 21 23:54:06 2021 +0100 +++ b/mod_rest/res/schema-xmpp.json Mon Mar 22 00:21:27 2021 +0100 @@ -75,6 +75,42 @@ "x_name_is_value" : true } }, + "stats" : { + "description" : "Simple statistics gathering, array of (name, unit, value) tuples.", + "items" : { + "properties" : { + "name" : { + "type" : "string", + "xml" : { + "attribute" : true + } + }, + "unit" : { + "type" : "string", + "xml" : { + "attribute" : true + } + }, + "value" : { + "type" : "number", + "xml" : { + "attribute" : true + } + } + }, + "type" : "object", + "xml" : { + "name" : "stat" + } + }, + "title" : "XEP-0039: Statistics Gathering", + "type" : "array", + "xml" : { + "name" : "query", + "namespace" : "http://jabber.org/protocol/stats", + "wrapped" : true + } + }, "version" : { "description" : "Ask about software version information", "properties" : {