Diff

plugins/private.lua @ 155:9c9af7a196ed

plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
author Kim Alvefur <zash@zash.se>
date Sat, 20 Nov 2010 17:27:03 +0100
parent 149:f5c524412939
child 250:a5ac643a7fd6
line wrap: on
line diff
--- a/plugins/private.lua	Thu Nov 11 03:13:51 2010 +0000
+++ b/plugins/private.lua	Sat Nov 20 17:27:03 2010 +0100
@@ -1,12 +1,20 @@
+-- Implements XEP-0049: Private XML Storage
+
 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);
+			:tag("query", { xmlns = xmlns_private });
+		if data then
+			if data.name == name and data.attr and data.attr.xmlns == xmlns then
+				iq:add_child(data);
+			else
+				iq:tag(name, { xmlns = xmlns })
+					:add_child(data);
+			end
+		end
+		self:send_iq(iq, callback);
 	end
 	
 	function stream:private_get(name, xmlns, callback)