Mercurial > prosody-modules
comparison mod_rest/jsonmap.lib.lua @ 4519:ea1fd703bb27
mod_rest: Convert XEP-0039 to datamapping
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 22 Mar 2021 00:21:27 +0100 |
parents | 073f5397c1d2 |
children | b68b801ddc50 |
comparison
equal
deleted
inserted
replaced
4518:073f5397c1d2 | 4519:ea1fd703bb27 |
---|---|
351 end | 351 end |
352 return form; | 352 return form; |
353 end | 353 end |
354 }; | 354 }; |
355 | 355 |
356 -- XEP-0039: Statistics Gathering | |
357 stats = { type = "func", xmlns = "http://jabber.org/protocol/stats", tagname = "query", | |
358 st2json = function (s) | |
359 local o = array(); | |
360 for stat in s:childtags("stat") do | |
361 o:push({ | |
362 name = stat.attr.name; | |
363 unit = stat.attr.unit; | |
364 value = stat.attr.value; | |
365 }); | |
366 end | |
367 return o; | |
368 end; | |
369 json2st = function (j) | |
370 local stats = st.stanza("query", { xmlns = "http://jabber.org/protocol/stats" }); | |
371 if type(j) == "table" then | |
372 for _, stat in ipairs(j) do | |
373 stats:tag("stat", { name = stat.name, unit = stat.unit, value = stat.value }):up(); | |
374 end | |
375 end | |
376 return stats; | |
377 end; | |
378 }; | |
379 | |
380 }; | 356 }; |
381 | 357 |
382 local byxmlname = {}; | 358 local byxmlname = {}; |
383 for k, spec in pairs(field_mappings) do | 359 for k, spec in pairs(field_mappings) do |
384 for _, replace in pairs(schema.properties) do | 360 for _, replace in pairs(schema.properties) do |