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 | 287b09ab3187ffca7b9c4f40dcfdf986d0464a81 (patch) | |
tree | 310757ceed83a7082170040da32f32ba15a9928e /plugins | |
parent | 8942bafa1a3be077f3dece4f8f49f9d08375f11d (diff) | |
download | prosody-287b09ab3187ffca7b9c4f40dcfdf986d0464a81.tar.gz prosody-287b09ab3187ffca7b9c4f40dcfdf986d0464a81.zip |
mod_pubsub: Add support for changing subscription options
Diffstat (limited to 'plugins')
-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 |