Software / code / prosody-modules
Comparison
mod_rest/jsonmap.lib.lua @ 3923:3c3d216c6f6d
mod_rest: Add JSON mapping of XEP-0039: Statistics Gathering
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 28 Feb 2020 22:38:41 +0100 |
| parent | 3922:ea59c9455f93 |
| child | 3932:8b34222216f4 |
comparison
equal
deleted
inserted
replaced
| 3922:ea59c9455f93 | 3923:3c3d216c6f6d |
|---|---|
| 342 end | 342 end |
| 343 end | 343 end |
| 344 return form; | 344 return form; |
| 345 end | 345 end |
| 346 }; | 346 }; |
| 347 | |
| 348 -- XEP-0039: Statistics Gathering | |
| 349 stats = { type = "func", xmlns = "http://jabber.org/protocol/stats", tagname = "query", | |
| 350 st2json = function (s) | |
| 351 local o = array(); | |
| 352 for stat in s:childtags("stat") do | |
| 353 o:push({ | |
| 354 name = stat.attr.name; | |
| 355 unit = stat.attr.unit; | |
| 356 value = stat.attr.value; | |
| 357 }); | |
| 358 end | |
| 359 return o; | |
| 360 end; | |
| 361 json2st = function (j) | |
| 362 local stats = st.stanza("query", { xmlns = "http://jabber.org/protocol/stats" }); | |
| 363 if type(j) == "table" then | |
| 364 for _, stat in ipairs(j) do | |
| 365 stats:tag("stat", { name = stat.name, unit = stat.unit, value = stat.value }):up(); | |
| 366 end | |
| 367 end | |
| 368 return stats; | |
| 369 end; | |
| 370 }; | |
| 371 | |
| 347 }; | 372 }; |
| 348 | 373 |
| 349 local implied_kinds = { | 374 local implied_kinds = { |
| 350 disco = "iq", | 375 disco = "iq", |
| 351 items = "iq", | 376 items = "iq", |