Changeset

154:a4dc96890729

plugins.pubsub, squishy: New pubsub plugin (basic)
author Matthew Wild <mwild1@gmail.com>
date Tue, 16 Nov 2010 11:49:42 +0000
parents 153:f7c705485a2a
children 156:ab0f0326b2b4
files plugins/pubsub.lua squishy
diffstat 2 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/pubsub.lua	Tue Nov 16 11:49:42 2010 +0000
@@ -0,0 +1,46 @@
+local jid_bare = require "util.jid".bare;
+
+local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
+local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
+local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
+
+local pubsub = {};
+local pubsub_mt = { __index = pubsub };
+
+function verse.plugins.pubsub(stream)
+	stream.pubsub = setmetatable({ stream = stream }, pubsub_mt);
+end
+
+function pubsub:subscribe(server, node, jid, callback)
+	self.stream:send_iq(verse.iq({ to = server, type = "set" })
+		:tag("pubsub", { xmlns = xmlns_pubsub })
+			:tag("subscribe", { node = node, jid = jid or jid_bare(self.stream.jid) })
+	, function (result)
+		if callback then
+			if result.attr.type == "result" then
+				callback(true);
+			else
+				callback(false, result:get_error());
+			end
+		end
+	  end
+	);
+end
+
+function pubsub:publish(server, node, id, item, callback)
+	self.stream:send_iq(verse.iq({ to = server, type = "set" })
+		:tag("pubsub", { xmlns = xmlns_pubsub })
+			:tag("publish", { node = node })
+				:tag("item", { id = id })
+					:add_child(item)
+	, function (result)
+		if callback then
+			if result.attr.type == "result" then
+				callback(true);
+			else
+				callback(false, result:get_error());
+			end
+		end
+	  end
+	);
+end
--- a/squishy	Thu Nov 11 03:13:51 2010 +0000
+++ b/squishy	Tue Nov 16 11:49:42 2010 +0000
@@ -28,6 +28,7 @@
 Module "verse.plugins.sasl"	   "plugins/sasl.lua"
 Module "verse.plugins.bind"	   "plugins/bind.lua"
 Module "verse.plugins.legacy"	   "plugins/legacy.lua"
+Module "verse.plugins.pubsub"	   "plugins/pubsub.lua"
 Module "verse.plugins.version"	   "plugins/version.lua"
 Module "verse.plugins.ping"	   "plugins/ping.lua"
 Module "verse.plugins.session"     "plugins/session.lua"