Changeset

5320:518d864b2ab8

mod_pubsub, util.pubsub: Add delete action
author Kim Alvefur <zash@zash.se>
date Thu, 31 Jan 2013 18:41:01 +0100
parents 5319:d20861bf900b
children 5321:33813f000015 5322:8d525f58f916
files plugins/mod_pubsub.lua util/pubsub.lua
diffstat 2 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pubsub.lua	Thu Jan 31 15:48:55 2013 +0100
+++ b/plugins/mod_pubsub.lua	Thu Jan 31 18:41:01 2013 +0100
@@ -119,6 +119,22 @@
 	return origin.send(reply);
 end
 
+function handlers.set_delete(origin, stanza, delete)
+	local node = delete.attr.node;
+
+	local reply, notifier;
+	if not node then
+		return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
+	end
+	local ok, ret = service:delete(node, stanza.attr.from);
+	if ok then
+		reply = st.reply(stanza);
+	else
+		reply = pubsub_error_reply(stanza, ret);
+	end
+	return origin.send(reply);
+end
+
 function handlers.set_subscribe(origin, stanza, subscribe)
 	local node, jid = subscribe.attr.node, subscribe.attr.jid;
 	if not (node and jid) then
@@ -258,6 +274,7 @@
 	retract = { "delete-items", "retract-items" };
 	purge = { "purge-nodes" };
 	publish = { "publish", autocreate_on_publish and "auto-create" };
+	delete = { "delete-nodes" };
 	get_items = { "retrieve-items" };
 	add_subscription = { "subscribe" };
 	get_subscriptions = { "retrieve-subscriptions" };
@@ -418,6 +435,7 @@
 			create = true;
 			publish = true;
 			retract = true;
+			delete = true;
 			get_nodes = true;
 			
 			subscribe = true;
--- a/util/pubsub.lua	Thu Jan 31 15:48:55 2013 +0100
+++ b/util/pubsub.lua	Thu Jan 31 18:41:01 2013 +0100
@@ -226,6 +226,18 @@
 	return ok, err;
 end
 
+function service:delete(node, actor)
+	-- Access checking
+	if not self:may(node, actor, "delete") then
+		return false, "forbidden";
+	end
+	--
+	local node_obj = self.nodes[node];
+	self.nodes[node] = nil;
+	self.config.broadcaster("delete", node, node_obj.subscribers);
+	return true;
+end
+
 function service:publish(node, actor, id, item)
 	-- Access checking
 	if not self:may(node, actor, "publish") then