comparison mod_rest/jsonmap.lib.lua @ 3823:31b1797a78e1

mod_rest: Add support for XEP-XXXX: User-defined Data Transfer
author Kim Alvefur <zash@zash.se>
date Thu, 02 Jan 2020 09:30:47 +0100
parents f0a1d113dce4
children 1b9834500123
comparison
equal deleted inserted replaced
3822:f0a1d113dce4 3823:31b1797a78e1
1 local array = require "util.array"; 1 local array = require "util.array";
2 local jid = require "util.jid"; 2 local jid = require "util.jid";
3 local json = require "util.json";
3 local st = require "util.stanza"; 4 local st = require "util.stanza";
4 local xml = require "util.xml"; 5 local xml = require "util.xml";
5 6
6 local simple_types = { 7 local simple_types = {
7 -- basic message 8 -- basic message
101 if type(s) == "string" then 102 if type(s) == "string" then
102 return st.stanza("query", { xmlns = "jabber:iq:oob" }):text_tag("url", s); 103 return st.stanza("query", { xmlns = "jabber:iq:oob" }):text_tag("url", s);
103 end 104 end
104 end; 105 end;
105 }; 106 };
107
108 -- XEP-XXXX: User-defined Data Transfer
109 payload = {"func", "urn:xmpp:udt:0", "payload",
110 function (s)
111 local rawjson = s:get_child_text("json", "urn:xmpp:json:0");
112 if not rawjson then return nil, "missing-json-payload"; end
113 local parsed, err = json.decode(rawjson);
114 if not parsed then return nil, err; end
115 return {
116 datatype = s.attr.datatype;
117 data = parsed;
118 };
119 end;
120 function (s)
121 if type(s) == "table" then
122 return st.stanza("payload", { xmlns = "urn:xmpp:udt:0", datatype = s.datatype })
123 :tag("json", { xmlns = "urn:xmpp:json:0" }):text(json.encode(s.data));
124 end;
125 end
126 };
127
106 }; 128 };
107 129
108 local implied_kinds = { 130 local implied_kinds = {
109 disco = "iq", 131 disco = "iq",
110 items = "iq", 132 items = "iq",