# HG changeset patch # User Matthew Wild # Date 1289908182 0 # Node ID a4dc96890729242c3f15c205838c5f7b7a853ac8 # Parent f7c705485a2afb04079dab1a0aef0ee8987262cd plugins.pubsub, squishy: New pubsub plugin (basic) diff -r f7c705485a2a -r a4dc96890729 plugins/pubsub.lua --- /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 diff -r f7c705485a2a -r a4dc96890729 squishy --- 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"