# HG changeset patch # User Kim Alvefur # Date 1580849354 -3600 # Node ID 562b34050561db648f5533f7b1cc4267724a3c65 # Parent 75b330d4fa6f0ebceaf8ef9703ebacedb60484d5 mod_rest: Add basic support for XEP-0050: Ad-Hoc commands (no forms) This allows calling simple commands like the one provided by mod_uptime diff -r 75b330d4fa6f -r 562b34050561 mod_rest/jsonmap.lib.lua --- a/mod_rest/jsonmap.lib.lua Sat Feb 01 13:03:18 2020 +0100 +++ b/mod_rest/jsonmap.lib.lua Tue Feb 04 21:49:14 2020 +0100 @@ -126,6 +126,50 @@ end; }; + -- XEP-0050: Ad-Hoc Commands + command = {"func", "http://jabber.org/protocol/commands", "command", + function (s) + local cmd = { + action = s.attr.action, + node = s.attr.node, + sessionid = s.attr.sessionid, + status = s.attr.status, + }; + local actions = s:get_child("actions"); + local note = s:get_child("note"); + -- TODO -- local form = s:get_child("x", "jabber:x:data"); + if actions then + cmd.actions = { + execute = actions.attr.execute, + }; + for action in actions:childtags() do + cmd.actions[action.name] = true + end + elseif note then + cmd.note = { + type = note.attr.type; + text = note:get_text(); + }; + end + return cmd; + end; + function (s) + if type(s) == "table" and s ~= json.null then + local cmd = st.stanza("command", { + xmlns = "http://jabber.org/protocol/commands", + action = s.action, + node = s.node, + sessionid = s.sessionid, + status = s.status, + }); + return cmd; + elseif type(s) == "string" then -- assume node + return st.stanza("command", { xmlns = "http://jabber.org/protocol/commands", node = s }); + end + -- else .. missing required attribute + end; + }; + -- XEP-0066: Out of Band Data oob_url = {"func", "jabber:iq:oob", "query", function (s) @@ -165,6 +209,7 @@ items = "iq", ping = "iq", version = "iq", + command = "iq", body = "message", html = "message",