Software /
code /
prosody-modules
Comparison
mod_rest/jsonmap.lib.lua @ 4473:3b50a9a75fb6
mod_rest: Roundtrip disco and items when string or boolean is used
E.g. {disco:true} turns to <query/> and back to {disco:true}, same with
{items:true}. Similarily, {disco:"node"}, {items:"node"} turn into
<query node="node"/> and back.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 26 Feb 2021 22:05:25 +0100 |
parent | 4372:78de3c7acf58 |
child | 4499:8e644bf36627 |
comparison
equal
deleted
inserted
replaced
4472:f210f242cf17 | 4473:3b50a9a75fb6 |
---|---|
74 | 74 |
75 -- XEP-0030 | 75 -- XEP-0030 |
76 disco = { | 76 disco = { |
77 type = "func", xmlns = "http://jabber.org/protocol/disco#info", tagname = "query", | 77 type = "func", xmlns = "http://jabber.org/protocol/disco#info", tagname = "query", |
78 st2json = function (s) --> array of features | 78 st2json = function (s) --> array of features |
79 if s.tags[1] == nil then | |
80 return s.attr.node or true; | |
81 end | |
79 local identities, features, extensions = array(), array(), {}; | 82 local identities, features, extensions = array(), array(), {}; |
80 for tag in s:childtags() do | 83 for tag in s:childtags() do |
81 if tag.name == "identity" and tag.attr.category and tag.attr.type then | 84 if tag.name == "identity" and tag.attr.category and tag.attr.type then |
82 identities:push({ category = tag.attr.category, type = tag.attr.type, name = tag.attr.name }); | 85 identities:push({ category = tag.attr.category, type = tag.attr.type, name = tag.attr.name }); |
83 elseif tag.name == "feature" and tag.attr.var then | 86 elseif tag.name == "feature" and tag.attr.var then |
113 extension["FORM_TYPE"] = form_type; | 116 extension["FORM_TYPE"] = form_type; |
114 disco:add_child(field_mappings.formdata.json2st(extension)); | 117 disco:add_child(field_mappings.formdata.json2st(extension)); |
115 end | 118 end |
116 end | 119 end |
117 return disco; | 120 return disco; |
121 elseif type(s) == "string" then | |
122 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info", node = s }); | |
118 else | 123 else |
119 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info", }); | 124 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info", }); |
120 end | 125 end |
121 end; | 126 end; |
122 }; | 127 }; |
123 | 128 |
124 items = { | 129 items = { |
125 type = "func", xmlns = "http://jabber.org/protocol/disco#items", tagname = "query", | 130 type = "func", xmlns = "http://jabber.org/protocol/disco#items", tagname = "query", |
126 st2json = function (s) --> array of features | map with node | 131 st2json = function (s) --> array of features | map with node |
127 if s.attr.node and s.tags[1] == nil then | 132 if s.tags[1] == nil then |
128 return { node = s.attr.node }; | 133 return s.attr.node or true; |
129 end | 134 end |
130 | 135 |
131 local items = array(); | 136 local items = array(); |
132 for item in s:childtags("item") do | 137 for item in s:childtags("item") do |
133 items:push({ jid = item.attr.jid, node = item.attr.node, name = item.attr.name }); | 138 items:push({ jid = item.attr.jid, node = item.attr.node, name = item.attr.name }); |
143 elseif type(item) == "table" then | 148 elseif type(item) == "table" then |
144 disco:tag("item", { jid = item.jid, node = item.node, name = item.name }); | 149 disco:tag("item", { jid = item.jid, node = item.node, name = item.name }); |
145 end | 150 end |
146 end | 151 end |
147 return disco; | 152 return disco; |
153 elseif type(s) == "string" then | |
154 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", node = s }); | |
148 else | 155 else |
149 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", }); | 156 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", }); |
150 end | 157 end |
151 end; | 158 end; |
152 }; | 159 }; |