plugins.private: Private XML storage support

Thu, 28 Oct 2010 19:37:22 +0100

author
Kim Alvefur <zash@zash.se>
date
Thu, 28 Oct 2010 19:37:22 +0100
changeset 149
f5c524412939
parent 148
386920f05808
child 150
728cc7f2f0c2

plugins.private: Private XML storage support

plugins/private.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/private.lua	Thu Oct 28 19:37:22 2010 +0100
@@ -0,0 +1,25 @@
+local xmlns_private = "jabber:iq:private";
+
+function verse.plugins.private(stream)
+	function stream:private_set(name, xmlns, data, callback)
+		local iq = verse.iq({ type = "set" })
+			:tag("query", { xmlns = xmlns_private })
+				:tag(name, { xmlns = xmlns });
+		if data then iq:add_child(data); end
+		self:send_iq(iq, function () callback(); end);
+	end
+	
+	function stream:private_get(name, xmlns, callback)
+		self:send_iq(verse.iq({type="get"})
+			:tag("query", { xmlns = xmlns_private })
+				:tag(name, { xmlns = xmlns }),
+			function (reply)
+				if reply.attr.type == "result" then
+					local query = reply:get_child("query", xmlns_private);
+					local result = query:get_child(name, xmlns);
+					callback(result);
+				end
+			end);
+	end
+end
+

mercurial