comparison mod_rest/jsonmap.lib.lua @ 3877:562b34050561

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
author Kim Alvefur <zash@zash.se>
date Tue, 04 Feb 2020 21:49:14 +0100
parents 93f71ab6cb00
children 9a3dfe0bf9fd
comparison
equal deleted inserted replaced
3876:75b330d4fa6f 3877:562b34050561
124 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", }); 124 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", });
125 end 125 end
126 end; 126 end;
127 }; 127 };
128 128
129 -- XEP-0050: Ad-Hoc Commands
130 command = {"func", "http://jabber.org/protocol/commands", "command",
131 function (s)
132 local cmd = {
133 action = s.attr.action,
134 node = s.attr.node,
135 sessionid = s.attr.sessionid,
136 status = s.attr.status,
137 };
138 local actions = s:get_child("actions");
139 local note = s:get_child("note");
140 -- TODO -- local form = s:get_child("x", "jabber:x:data");
141 if actions then
142 cmd.actions = {
143 execute = actions.attr.execute,
144 };
145 for action in actions:childtags() do
146 cmd.actions[action.name] = true
147 end
148 elseif note then
149 cmd.note = {
150 type = note.attr.type;
151 text = note:get_text();
152 };
153 end
154 return cmd;
155 end;
156 function (s)
157 if type(s) == "table" and s ~= json.null then
158 local cmd = st.stanza("command", {
159 xmlns = "http://jabber.org/protocol/commands",
160 action = s.action,
161 node = s.node,
162 sessionid = s.sessionid,
163 status = s.status,
164 });
165 return cmd;
166 elseif type(s) == "string" then -- assume node
167 return st.stanza("command", { xmlns = "http://jabber.org/protocol/commands", node = s });
168 end
169 -- else .. missing required attribute
170 end;
171 };
172
129 -- XEP-0066: Out of Band Data 173 -- XEP-0066: Out of Band Data
130 oob_url = {"func", "jabber:iq:oob", "query", 174 oob_url = {"func", "jabber:iq:oob", "query",
131 function (s) 175 function (s)
132 return s:get_child_text("url"); 176 return s:get_child_text("url");
133 end; 177 end;
163 local implied_kinds = { 207 local implied_kinds = {
164 disco = "iq", 208 disco = "iq",
165 items = "iq", 209 items = "iq",
166 ping = "iq", 210 ping = "iq",
167 version = "iq", 211 version = "iq",
212 command = "iq",
168 213
169 body = "message", 214 body = "message",
170 html = "message", 215 html = "message",
171 replace = "message", 216 replace = "message",
172 state = "message", 217 state = "message",