aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pubsub.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_pubsub.lua')
-rw-r--r--plugins/mod_pubsub.lua43
1 files changed, 40 insertions, 3 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua
index f92d27aa..0953de28 100644
--- a/plugins/mod_pubsub.lua
+++ b/plugins/mod_pubsub.lua
@@ -25,8 +25,10 @@ function handle_pubsub_iq(event)
end
local pubsub_errors = {
+ ["conflict"] = { "cancel", "conflict" };
["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" };
["item-not-found"] = { "cancel", "item-not-found" };
+ ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
};
function pubsub_error_reply(stanza, error)
local e = pubsub_errors[error];
@@ -50,7 +52,7 @@ function handlers.get_items(origin, stanza, items)
:tag("pubsub", { xmlns = xmlns_pubsub })
:add_child(data);
else
- reply = st.error_reply(stanza, "cancel", "item-not-found", "Item could not be found in this node");
+ reply = pubsub_error_reply(stanza, "item-not-found");
end
return origin.send(reply);
end
@@ -63,7 +65,7 @@ function handlers.set_create(origin, stanza, create)
if ok then
reply = st.reply(stanza);
else
- reply = st.error_reply(stanza, "cancel", ret);
+ reply = pubsub_error_reply(stanza, ret);
end
else
repeat
@@ -74,7 +76,7 @@ function handlers.set_create(origin, stanza, create)
:tag("pubsub", { xmlns = xmlns_pubsub })
:tag("create", { node = node });
end
- origin.send(reply);
+ return origin.send(reply);
end
function handlers.set_subscribe(origin, stanza, subscribe)
@@ -98,6 +100,21 @@ function handlers.set_subscribe(origin, stanza, subscribe)
return origin.send(reply);
end
+function handlers.set_unsubscribe(origin, stanza, unsubscribe)
+ local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid;
+ if jid_bare(jid) ~= jid_bare(stanza.attr.from) then
+ return origin.send(pubsub_error_reply(stanza, "invalid-jid"));
+ end
+ local ok, ret = service:remove_subscription(node, stanza.attr.from, jid);
+ local reply;
+ if ok then
+ reply = st.reply(stanza);
+ else
+ reply = pubsub_error_reply(stanza, ret);
+ end
+ return origin.send(reply);
+end
+
function handlers.set_publish(origin, stanza, publish)
local node = publish.attr.node;
local item = publish:get_child("item");
@@ -115,7 +132,27 @@ function handlers.set_publish(origin, stanza, publish)
return origin.send(reply);
end
+function handlers.set_retract(origin, stanza, retract)
+ local node, notify = retract.attr.node, retract.attr.notify;
+ notify = (notify == "1") or (notify == "true");
+ local item = retract:get_child("item");
+ local id = item and item.attr.id
+ local reply, notifier;
+ if notify then
+ notifier = st.stanza("retract", { id = id });
+ end
+ local ok, ret = service:retract(node, stanza.attr.from, id, notifier);
+ if ok then
+ reply = st.reply(stanza);
+ else
+ reply = pubsub_error_reply(stanza, ret);
+ end
+ return origin.send(reply);
+end
+
function simple_broadcast(node, jids, item)
+ item = st.clone(item);
+ item.attr.xmlns = nil; -- Clear the pubsub namespace
local message = st.message({ from = module.host, type = "headline" })
:tag("event", { xmlns = xmlns_pubsub_event })
:tag("items", { node = node })