aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/mod_pubsub.lua16
-rw-r--r--util/pubsub.lua9
2 files changed, 24 insertions, 1 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua
index 83ce0ad9..0475ea1d 100644
--- a/plugins/mod_pubsub.lua
+++ b/plugins/mod_pubsub.lua
@@ -28,6 +28,7 @@ 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];
@@ -99,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");
diff --git a/util/pubsub.lua b/util/pubsub.lua
index dc3f3432..4789dff9 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -17,7 +17,14 @@ function service:add_subscription(node, actor, jid)
end
function service:remove_subscription(node, actor, jid)
- self.nodes[node].subscribers[jid] = nil;
+ local node_obj = self.nodes[node];
+ if not node_obj then
+ return false, "item-not-found";
+ end
+ if not node_obj.subscribers[jid] then
+ return false, "not-subscribed";
+ end
+ node_obj.subscribers[jid] = nil;
return true;
end