Software /
code /
prosody
Changeset
6438:b1c40054b59d
mod_pubsub: Add support for node configuration
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Sep 2014 01:46:17 +0200 |
parents | 6437:3f1f11dfdf10 |
children | 6439:d58ad8bd244b |
files | plugins/mod_pubsub/mod_pubsub.lua plugins/mod_pubsub/pubsub.lib.lua |
diffstat | 2 files changed, 59 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pubsub/mod_pubsub.lua Sun Sep 28 01:45:59 2014 +0200 +++ b/plugins/mod_pubsub/mod_pubsub.lua Sun Sep 28 01:46:17 2014 +0200 @@ -64,6 +64,7 @@ get_items = { "retrieve-items" }; add_subscription = { "subscribe" }; get_subscriptions = { "retrieve-subscriptions" }; + set_configure = { "config-node" }; }; local function add_disco_features_from_service(service) @@ -195,6 +196,7 @@ retract = true; delete = true; get_nodes = true; + configure = true; subscribe = true; unsubscribe = true; @@ -215,6 +217,14 @@ }; }; + node_config_form = require"util.dataforms".new { + { + type = "hidden"; + name = "FORM_TYPE"; + value = "http://jabber.org/protocol/pubsub#node_config"; + }; + }; + autocreate_on_publish = autocreate_on_publish; autocreate_on_subscribe = autocreate_on_subscribe;
--- a/plugins/mod_pubsub/pubsub.lib.lua Sun Sep 28 01:45:59 2014 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Sun Sep 28 01:46:17 2014 +0200 @@ -3,6 +3,7 @@ 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 @@ ["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,51 @@ 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 + return _M;