aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2013-01-25 01:32:14 +0100
committerFlorian Zeitz <florob@babelmonkeys.de>2013-01-25 01:32:14 +0100
commit75ef4319b9df8318842565cd34d3e9c8927b7f77 (patch)
tree3607f9b61fa33d68c4fd61c89b49d602332b150f
parent73a7d5a1ceffdb27ca723f4117f9888f5a52c4aa (diff)
downloadprosody-75ef4319b9df8318842565cd34d3e9c8927b7f77.tar.gz
prosody-75ef4319b9df8318842565cd34d3e9c8927b7f77.zip
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
-rw-r--r--plugins/mod_pubsub.lua21
-rw-r--r--util/pubsub.lua27
2 files changed, 29 insertions, 19 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua
index c840c7c2..56fabaec 100644
--- a/plugins/mod_pubsub.lua
+++ b/plugins/mod_pubsub.lua
@@ -6,6 +6,7 @@ local uuid_generate = require "util.uuid".generate;
local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
+local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false);
local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false);
@@ -201,15 +202,12 @@ end
function handlers.set_purge(origin, stanza, purge)
local node, notify = purge.attr.node, purge.attr.notify;
notify = (notify == "1") or (notify == "true");
- local reply, notifier;
+ local reply;
if not node then
origin.send(st.error_reply(stanza, "modify", "bad-request"));
return true;
end
- if notify then
- notifier = st.stanza("purge");
- end
- local ok, ret = service:purge(node, stanza.attr.from, notifier);
+ local ok, ret = service:purge(node, stanza.attr.from, notify);
if ok then
reply = st.reply(stanza);
else
@@ -218,12 +216,14 @@ function handlers.set_purge(origin, stanza, purge)
return origin.send(reply);
end
-function simple_broadcast(node, jids, item)
- item = st.clone(item);
- item.attr.xmlns = nil; -- Clear the pubsub namespace
+function simple_broadcast(kind, node, jids, item)
+ if item then
+ item = st.clone(item);
+ item.attr.xmlns = nil; -- Clear the pubsub namespace
+ end
local message = st.message({ from = module.host, type = "headline" })
:tag("event", { xmlns = xmlns_pubsub_event })
- :tag("items", { node = node })
+ :tag(kind, { node = node })
:add_child(item);
for jid in pairs(jids) do
module:log("debug", "Sending notification to %s", jid);
@@ -232,7 +232,8 @@ function simple_broadcast(node, jids, item)
end
end
-module:hook("iq/host/http://jabber.org/protocol/pubsub:pubsub", handle_pubsub_iq);
+module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
+module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
local disco_info;
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)