aboutsummaryrefslogtreecommitdiffstats
path: root/util/pubsub.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-09-28 01:45:59 +0200
committerKim Alvefur <zash@zash.se>2014-09-28 01:45:59 +0200
commit54252eecb4fb38317f51087c591aa878ad19df71 (patch)
tree450a30981494c9345ce33e1c0df9f9b7604944b4 /util/pubsub.lua
parentd8283439b246eaa29d7a7e1ba9bb0aa06ee49c69 (diff)
downloadprosody-54252eecb4fb38317f51087c591aa878ad19df71.tar.gz
prosody-54252eecb4fb38317f51087c591aa878ad19df71.zip
util.pubsub: Add support for node configuration
Diffstat (limited to 'util/pubsub.lua')
-rw-r--r--util/pubsub.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 3c67be90..424a48c6 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -11,11 +11,14 @@ local default_config = { __index = {
get_affiliation = function () end;
capabilities = {};
} };
+local default_node_config = { __index = {
+} };
function new(config)
config = config or {};
return setmetatable({
config = setmetatable(config, default_config);
+ node_defaults = setmetatable(config.node_defaults or {}, default_node_config);
affiliations = {};
subscriptions = {};
nodes = {};
@@ -204,7 +207,7 @@ function service:get_subscription(node, actor, jid)
return true, node_obj.subscribers[jid];
end
-function service:create(node, actor)
+function service:create(node, actor, options)
-- Access checking
if not self:may(node, actor, "create") then
return false, "forbidden";
@@ -218,7 +221,7 @@ function service:create(node, actor)
self.nodes[node] = {
name = node;
subscribers = {};
- config = {};
+ config = setmetatable(options or {}, {__index=self.node_defaults});
affiliations = {};
};
setmetatable(self.nodes[node], { __index = { data = self.data[node] } }); -- COMPAT
@@ -411,4 +414,21 @@ function service:set_node_capabilities(node, actor, capabilities)
return true;
end
+function service:set_node_config(node, actor, new_config)
+ if not self:may(node, actor, "configure") then
+ return false, "forbidden";
+ end
+
+ local node_obj = self.nodes[node];
+ if not node_obj then
+ return false, "item-not-found";
+ end
+
+ for k,v in pairs(new_config) do
+ node_obj.config[k] = v;
+ end
+
+ return true;
+end
+
return _M;