diff options
author | Kim Alvefur <zash@zash.se> | 2018-07-14 20:18:49 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-07-14 20:18:49 +0200 |
commit | 2d45594efef229dd094f35c8f34d599396d7e2c1 (patch) | |
tree | 310757ceed83a7082170040da32f32ba15a9928e | |
parent | d870120a2fd7884c3cfe64af41a3d009af2fafb8 (diff) | |
download | prosody-2d45594efef229dd094f35c8f34d599396d7e2c1.tar.gz prosody-2d45594efef229dd094f35c8f34d599396d7e2c1.zip |
mod_pubsub: Add support for changing subscription options
-rw-r--r-- | plugins/mod_pubsub/pubsub.lib.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 5bebbeba..e1b61096 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -24,6 +24,7 @@ local pubsub_errors = { ["nodeid-required"] = { "modify", "bad-request", nil, "nodeid-required" }; ["item-not-found"] = { "cancel", "item-not-found" }; ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; + ["invalid-options"] = { "modify", "bad-request", nil, "invalid-options" }; ["forbidden"] = { "auth", "forbidden" }; ["not-allowed"] = { "cancel", "not-allowed" }; ["internal-server-error"] = { "wait", "internal-server-error" }; @@ -453,6 +454,35 @@ function handlers.get_options(origin, stanza, options, service) return true; end +function handlers.set_options(origin, stanza, options, service) + local node, jid = options.attr.node, options.attr.jid; + jid = jid_prep(jid); + if not (node and jid) then + origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid")); + return true; + end + local ok, ret = service:get_subscription(node, stanza.attr.from, jid); + if not ok then + origin.send(pubsub_error_reply(stanza, ret)); + return true; + elseif not ret then + origin.send(pubsub_error_reply(stanza, "not-subscribed")); + return true; + end + local new_subopts, err = options_form:data(options.tags[1]); + if not new_subopts then + origin.send(pubsub_error_reply(stanza, ret)); + return true; + end + local ok, err = service:add_subscription(node, stanza.attr.from, jid, new_subopts); + if not ok then + origin.send(pubsub_error_reply(stanza, err)); + return true; + end + origin.send(st.reply(stanza)); + return true; +end + function handlers.set_publish(origin, stanza, publish, service) local node = publish.attr.node; if not node then |