From 40709658994b6603968042c9dfebff7363f6ea71 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 0767f241531940a9a66eb4be285ee26cd44b57a0 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 4196cca0e08cb9c3404f8b10db51714d1abc0286 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 f3f1a3c44ece8b6cfbad0cb0f73cfac9f38bc72c 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 5cfdac70c61ae6562f72868ef7b55129b166aa80 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