Software /
code /
prosody
Comparison
plugins/mod_pubsub/pubsub.lib.lua @ 6446:011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Sep 2014 02:47:54 +0200 |
parent | 6445:f1ad3923368c |
child | 6447:8c2dc2ac5a40 |
comparison
equal
deleted
inserted
replaced
6445:f1ad3923368c | 6446:011ca9b88179 |
---|---|
1 local st = require "util.stanza"; | 1 local st = require "util.stanza"; |
2 local uuid_generate = require "util.uuid".generate; | 2 local uuid_generate = require "util.uuid".generate; |
3 local dataform = require"util.dataforms".new; | |
3 | 4 |
4 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; | 5 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
5 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; | 6 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; |
6 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; | 7 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
7 | 8 |
28 end | 29 end |
29 return reply; | 30 return reply; |
30 end | 31 end |
31 _M.pubsub_error_reply = pubsub_error_reply; | 32 _M.pubsub_error_reply = pubsub_error_reply; |
32 | 33 |
34 local node_config_form = require"util.dataforms".new { | |
35 { | |
36 type = "hidden"; | |
37 name = "FORM_TYPE"; | |
38 value = "http://jabber.org/protocol/pubsub#node_config"; | |
39 }; | |
40 { | |
41 type = "text-single"; | |
42 name = "pubsub#max_items"; | |
43 label = "Max # of items to persist"; | |
44 }; | |
45 }; | |
46 | |
33 function handlers.get_items(origin, stanza, items, service) | 47 function handlers.get_items(origin, stanza, items, service) |
34 local node = items.attr.node; | 48 local node = items.attr.node; |
35 local item = items:get_child("item"); | 49 local item = items:get_child("item"); |
36 local id = item and item.attr.id; | 50 local id = item and item.attr.id; |
37 | 51 |
237 local node_obj = service.nodes[node]; | 251 local node_obj = service.nodes[node]; |
238 if not node_obj then | 252 if not node_obj then |
239 return origin.send(pubsub_error_reply(stanza, "item-not-found")); | 253 return origin.send(pubsub_error_reply(stanza, "item-not-found")); |
240 end | 254 end |
241 | 255 |
242 local form = self.config.node_config_form; | |
243 if not form then | |
244 return origin.send(pubsub_error_reply(stanza, "not-allowed")); | |
245 end | |
246 | |
247 local reply = st.reply(stanza) | 256 local reply = st.reply(stanza) |
248 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) | 257 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
249 :tag("configure", { node = node }) | 258 :tag("configure", { node = node }) |
250 :add_child(form:form(node_obj.config)); | 259 :add_child(node_config_form:form(node_obj.config)); |
251 return origin.send(reply); | 260 return origin.send(reply); |
252 end | 261 end |
253 | 262 |
254 function handlers.set_configure(origin, stanza, config, service) | 263 function handlers.set_configure(origin, stanza, config, service) |
255 local node = config.attr.node; | 264 local node = config.attr.node; |
256 if not node then | 265 if not node then |
257 return origin.send(pubsub_error_reply(stanza, "nodeid-required")); | 266 return origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
258 end | 267 end |
259 local form, node_obj = service:get_node_config_form(node, stanza.attr.from); | 268 if not service:may(node, stanza.attr.from, "configure") then |
260 if not form then | 269 return origin.send(pubsub_error_reply(stanza, "forbidden")); |
261 return origin.send(pubsub_error_reply(stanza, node_obj)); | 270 end |
262 end | 271 local new_config, err = node_config_form:data(config.tags[1]); |
263 local new_config, err = form:data(config.tags[1]); | |
264 if not new_config then | 272 if not new_config then |
265 return origin.send(st.error_reply(stanza, "modify", "bad-request", err)); | 273 return origin.send(st.error_reply(stanza, "modify", "bad-request", err)); |
266 end | 274 end |
267 local ok, err = service:set_node_config(node, stanza.attr.from, new_config); | 275 local ok, err = service:set_node_config(node, stanza.attr.from, new_config); |
268 if not ok then | 276 if not ok then |