Changeset

3854:25c34c9f755c

mod_rest: Add mapping of XEP-0092: Software Version
author Kim Alvefur <zash@zash.se>
date Sat, 25 Jan 2020 00:40:38 +0100
parents 3853:fb29d7cd698b
children 3855:0e1e900577c4
files mod_rest/example/app.py mod_rest/jsonmap.lib.lua
diffstat 2 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/example/app.py	Sat Jan 25 00:37:06 2020 +0100
+++ b/mod_rest/example/app.py	Sat Jan 25 00:40:38 2020 +0100
@@ -44,6 +44,9 @@
                     {"items": [{"jid": "example.org", "name": "Example Dot Org"}]}
                 )
 
+            elif "version" in data:
+                return jsonify({"version": {"name": "app.py", "version": "0"}})
+
     return Response(status=501)
 
 
--- a/mod_rest/jsonmap.lib.lua	Sat Jan 25 00:37:06 2020 +0100
+++ b/mod_rest/jsonmap.lib.lua	Sat Jan 25 00:40:38 2020 +0100
@@ -41,6 +41,28 @@
 	-- XEP-0199
 	ping = {"bool_tag", "urn:xmpp:ping", "ping"},
 
+	-- XEP-0092: Software Version
+	version = {"func", "jabber:iq:version", "query",
+		function (s)
+			return {
+				name = s:get_child_text("name");
+				version = s:get_child_text("version");
+				os = s:get_child_text("os");
+			}
+		end,
+		function (s)
+			local v = st.stanza("query", { xmlns = "jabber:iq:version" });
+			if type(s) == "table" then
+				v:text_tag("name", s.name);
+				v:text_tag("version", s.version);
+				if s.os then
+					v:text_tag("os", s.os);
+				end
+			end
+			return v;
+		end
+	};
+
 	-- XEP-0030
 	disco = {
 		"func", "http://jabber.org/protocol/disco#info", "query",
@@ -135,6 +157,7 @@
 	disco = "iq",
 	items = "iq",
 	ping = "iq",
+	version = "iq",
 
 	body = "message",
 	html = "message",