comparison mod_rest/jsonmap.lib.lua @ 3907:d5ecb9b9cb3b

mod_rest: Update with namespace and name of XEP-0432
author Kim Alvefur <zash@zash.se>
date Tue, 25 Feb 2020 23:33:55 +0100
parents dbebc9226597
children 1df4900bbd29
comparison
equal deleted inserted replaced
3906:dbebc9226597 3907:d5ecb9b9cb3b
314 return st.stanza("query", { xmlns = "jabber:iq:oob" }):text_tag("url", s); 314 return st.stanza("query", { xmlns = "jabber:iq:oob" }):text_tag("url", s);
315 end 315 end
316 end; 316 end;
317 }; 317 };
318 318
319 -- XEP-XXXX: User-defined Data Transfer 319 -- XEP-0432: Simple JSON Messaging
320 payload = { type = "func", xmlns = "urn:xmpp:udt:0", tagname = "payload", 320 payload = { type = "func", xmlns = "urn:xmpp:json-msg:0", tagname = "payload",
321 st2json = function (s) 321 st2json = function (s)
322 local rawjson = s:get_child_text("json", "urn:xmpp:json:0"); 322 local rawjson = s:get_child_text("json", "urn:xmpp:json:0");
323 if not rawjson then return nil, "missing-json-payload"; end 323 if not rawjson then return nil, "missing-json-payload"; end
324 local parsed, err = json.decode(rawjson); 324 local parsed, err = json.decode(rawjson);
325 if not parsed then return nil, err; end 325 if not parsed then return nil, err; end
328 data = parsed; 328 data = parsed;
329 }; 329 };
330 end; 330 end;
331 json2st = function (s) 331 json2st = function (s)
332 if type(s) == "table" then 332 if type(s) == "table" then
333 return st.stanza("payload", { xmlns = "urn:xmpp:udt:0", datatype = s.datatype }) 333 return st.stanza("payload", { xmlns = "urn:xmpp:json-msg:0", datatype = s.datatype })
334 :tag("json", { xmlns = "urn:xmpp:json:0" }):text(json.encode(s.data)); 334 :tag("json", { xmlns = "urn:xmpp:json:0" }):text(json.encode(s.data));
335 end; 335 end;
336 end 336 end
337 }; 337 };
338 338