From fb589d8634dd86e2f110801d71ae93925500d4d6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 24 Jan 2013 00:58:03 +0100 Subject: mod_pubsub, util.pubsub: Implement the purge action --- util/pubsub.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/pubsub.lua b/util/pubsub.lua index 8ff458e7..17795cf1 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -259,13 +259,21 @@ function service:retract(node, actor, id, retract) if (not node_obj) or (not node_obj.data[id]) then return false, "item-not-found"; end - node_obj.data[id] = nil; + if id then + node_obj.data[id] = nil; + else + node_obj.data = {}; -- Purge + end if retract then self.config.broadcaster(node, node_obj.subscribers, retract); end return true end +function service:purge(node, actor, purge) + return self:retract(node, actor, nil, purge); +end + function service:get_items(node, actor, id) -- Access checking if not self:may(node, actor, "get_items") then -- cgit v1.2.3 From 73a7d5a1ceffdb27ca723f4117f9888f5a52c4aa Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 26 Jan 2013 03:39:18 +0500 Subject: util.xmppstream: Include error stanza in error message if no error handler is available. --- util/xmppstream.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util') diff --git a/util/xmppstream.lua b/util/xmppstream.lua index f1793b4f..4909678c 100644 --- a/util/xmppstream.lua +++ b/util/xmppstream.lua @@ -45,7 +45,7 @@ function new_sax_handlers(session, stream_callbacks) local cb_streamopened = stream_callbacks.streamopened; local cb_streamclosed = stream_callbacks.streamclosed; - local cb_error = stream_callbacks.error or function(session, e) error("XML stream error: "..tostring(e)); end; + local cb_error = stream_callbacks.error or function(session, e, stanza) error("XML stream error: "..tostring(e)..(stanza and ": "..tostring(stanza) or ""),2); end; local cb_handlestanza = stream_callbacks.handlestanza; local stream_ns = stream_callbacks.stream_ns or xmlns_streams; -- cgit v1.2.3 From 75ef4319b9df8318842565cd34d3e9c8927b7f77 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Fri, 25 Jan 2013 01:32:14 +0100 Subject: mod_pubsub, util.pubsub: Don't send purge notifications in an element --- util/pubsub.lua | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'util') diff --git a/util/pubsub.lua b/util/pubsub.lua index 17795cf1..c77140b9 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -245,7 +245,7 @@ function service:publish(node, actor, id, item) end node_obj.data[id] = item; self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); - self.config.broadcaster(node, node_obj.subscribers, item); + self.config.broadcaster("items", node, node_obj.subscribers, item); return true; end @@ -259,19 +259,28 @@ function service:retract(node, actor, id, retract) if (not node_obj) or (not node_obj.data[id]) then return false, "item-not-found"; end - if id then - node_obj.data[id] = nil; - else - node_obj.data = {}; -- Purge - end + node_obj.data[id] = nil; if retract then - self.config.broadcaster(node, node_obj.subscribers, retract); + self.config.broadcaster("items", node, node_obj.subscribers, retract); end return true end -function service:purge(node, actor, purge) - return self:retract(node, actor, nil, purge); +function service:purge(node, actor, notify) + -- Access checking + if not self:may(node, actor, "retract") then + return false, "forbidden"; + end + -- + local node_obj = self.nodes[node]; + if not node_obj then + return false, "item-not-found"; + end + node_obj.data = {}; -- Purge + if notify then + self.config.broadcaster("purge", node, node_obj.subscribers); + end + return true end function service:get_items(node, actor, id) -- cgit v1.2.3 From c8529ea3ab6f37c22fa3573b27ec8a44a32806a6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 26 Jan 2013 03:54:18 +0500 Subject: util.pubsub: Fix nil access error in get_subscriptions. --- util/pubsub.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util') diff --git a/util/pubsub.lua b/util/pubsub.lua index c77140b9..3d97d4ed 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -338,7 +338,7 @@ function service:get_subscriptions(node, actor, jid) if node then -- Return only subscriptions to this node if subscribed_nodes[node] then ret[#ret+1] = { - node = subscribed_node; + node = subscribed_nodes[node]; jid = jid; subscription = node_obj.subscribers[jid]; }; -- cgit v1.2.3 From 517296667e0fa74dd441892cf9750101ae31e814 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 31 Jan 2013 18:41:01 +0100 Subject: mod_pubsub, util.pubsub: Add delete action --- util/pubsub.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'util') diff --git a/util/pubsub.lua b/util/pubsub.lua index 3d97d4ed..e7fc86b1 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -226,6 +226,18 @@ function service:create(node, actor) 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 -- cgit v1.2.3