aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pubsub/pubsub.lib.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-09-28 01:56:22 +0200
committerKim Alvefur <zash@zash.se>2014-09-28 01:56:22 +0200
commitb0190726e5b46b3accb081366c921839b8ee2441 (patch)
treecfaf4c445383819dc32ada72c88e3f18079d9b30 /plugins/mod_pubsub/pubsub.lib.lua
parent865f1b1e8f99ab70c45cb2a4f94df34a2cb190ea (diff)
parentbf317774d921f17f73443b59008970a68f756082 (diff)
downloadprosody-b0190726e5b46b3accb081366c921839b8ee2441.tar.gz
prosody-b0190726e5b46b3accb081366c921839b8ee2441.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins/mod_pubsub/pubsub.lib.lua')
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 4e9acd68..8a22fa69 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -3,6 +3,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_owner = "http://jabber.org/protocol/pubsub#owner";
local _M = {};
@@ -17,6 +18,7 @@ local pubsub_errors = {
["item-not-found"] = { "cancel", "item-not-found" };
["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
["forbidden"] = { "cancel", "forbidden" };
+ ["not-allowed"] = { "cancel", "not-allowed" };
};
local function pubsub_error_reply(stanza, error)
local e = pubsub_errors[error];
@@ -222,4 +224,59 @@ function handlers.set_purge(origin, stanza, purge, service)
return origin.send(reply);
end
+function handlers.get_configure(origin, stanza, config, service)
+ local node = config.attr.node;
+ if not node then
+ return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
+ end
+
+ if not service:may(node, actor, "configure") then
+ return origin.send(pubsub_error_reply(stanza, "forbidden"));
+ end
+
+ local node_obj = service.nodes[node];
+ if not node_obj then
+ return origin.send(pubsub_error_reply(stanza, "item-not-found"));
+ end
+
+ local form = self.config.node_config_form;
+ if not form then
+ return origin.send(pubsub_error_reply(stanza, "not-allowed"));
+ end
+
+ local reply = st.reply(stanza)
+ :tag("pubsub", { xmlns = xmlns_pubsub_owner })
+ :tag("configure", { node = node })
+ :add_child(form:form(node_obj.config));
+ return origin.send(reply);
+end
+
+function handlers.set_configure(origin, stanza, config, service)
+ local node = config.attr.node;
+ if not node then
+ return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
+ end
+ local form, node_obj = service:get_node_config_form(node, stanza.attr.from);
+ if not form then
+ return origin.send(pubsub_error_reply(stanza, node_obj));
+ end
+ local new_config, err = form:data(config.tags[1]);
+ if not new_config then
+ return origin.send(st.error_reply(stanza, "modify", "bad-request", err));
+ end
+ local ok, err = service:set_node_config(node, stanza.attr.from, new_config);
+ if not ok then
+ return origin.send(pubsub_error_reply(stanza, err));
+ end
+ return origin.send(st.reply(stanza));
+end
+
+function handlers.get_default(origin, stanza, default, service)
+ local reply = st.reply(stanza)
+ :tag("pubsub", { xmlns = xmlns_pubsub_owner })
+ :tag("configure", { node = node })
+ :add_child(form:form(service.node_default_config));
+ return origin.send(reply);
+end
+
return _M;