comparison plugins/mod_pubsub/pubsub.lib.lua @ 10411:db2a06b9ff98

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 16 Nov 2019 16:52:31 +0100
parents 0a2d7efca039
children e1de29c41259
comparison
equal deleted inserted replaced
10410:659b577f280c 10411:db2a06b9ff98
5 local set = require "util.set"; 5 local set = require "util.set";
6 local st = require "util.stanza"; 6 local st = require "util.stanza";
7 local it = require "util.iterators"; 7 local it = require "util.iterators";
8 local uuid_generate = require "util.uuid".generate; 8 local uuid_generate = require "util.uuid".generate;
9 local dataform = require"util.dataforms".new; 9 local dataform = require"util.dataforms".new;
10 local errors = require "util.error";
10 11
11 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; 12 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
12 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; 13 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
13 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; 14 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
14 15
32 ["precondition-not-met"] = { "cancel", "conflict", nil, "precondition-not-met" }; 33 ["precondition-not-met"] = { "cancel", "conflict", nil, "precondition-not-met" };
33 ["invalid-item"] = { "modify", "bad-request", "invalid item" }; 34 ["invalid-item"] = { "modify", "bad-request", "invalid item" };
34 }; 35 };
35 local function pubsub_error_reply(stanza, error) 36 local function pubsub_error_reply(stanza, error)
36 local e = pubsub_errors[error]; 37 local e = pubsub_errors[error];
38 if not e and errors.is_err(error) then
39 e = { error.type, error.condition, error.text, error.pubsub_condition };
40 end
37 local reply = st.error_reply(stanza, t_unpack(e, 1, 3)); 41 local reply = st.error_reply(stanza, t_unpack(e, 1, 3));
38 if e[4] then 42 if e[4] then
39 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up(); 43 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up();
40 end 44 end
41 return reply; 45 return reply;
182 name = "pubsub#description"; 186 name = "pubsub#description";
183 }; 187 };
184 { 188 {
185 type = "text-single"; 189 type = "text-single";
186 name = "pubsub#type"; 190 name = "pubsub#type";
191 };
192 {
193 type = "text-single";
194 name = "pubsub#access_model";
195 };
196 {
197 type = "text-single";
198 name = "pubsub#publish_model";
187 }; 199 };
188 }; 200 };
189 201
190 local service_method_feature_map = { 202 local service_method_feature_map = {
191 add_subscription = { "subscribe", "subscription-options" }; 203 add_subscription = { "subscribe", "subscription-options" };
256 if node_obj.config then 268 if node_obj.config then
257 reply:add_child(node_metadata_form:form({ 269 reply:add_child(node_metadata_form:form({
258 ["pubsub#title"] = node_obj.config.title; 270 ["pubsub#title"] = node_obj.config.title;
259 ["pubsub#description"] = node_obj.config.description; 271 ["pubsub#description"] = node_obj.config.description;
260 ["pubsub#type"] = node_obj.config.payload_type; 272 ["pubsub#type"] = node_obj.config.payload_type;
273 ["pubsub#access_model"] = node_obj.config.access_model;
274 ["pubsub#publish_model"] = node_obj.config.publish_model;
261 }, "result")); 275 }, "result"));
262 end 276 end
263 end 277 end
264 278
265 function _M.handle_disco_items_node(event, service) 279 function _M.handle_disco_items_node(event, service)
316 330
317 local data = st.stanza("items", { node = node }); 331 local data = st.stanza("items", { node = node });
318 for _, id in ipairs(results) do 332 for _, id in ipairs(results) do
319 data:add_child(results[id]); 333 data:add_child(results[id]);
320 end 334 end
321 local reply; 335 local reply = st.reply(stanza)
322 if data then 336 :tag("pubsub", { xmlns = xmlns_pubsub })
323 reply = st.reply(stanza) 337 :add_child(data);
324 :tag("pubsub", { xmlns = xmlns_pubsub })
325 :add_child(data);
326 else
327 reply = pubsub_error_reply(stanza, "item-not-found");
328 end
329 origin.send(reply); 338 origin.send(reply);
330 return true; 339 return true;
331 end 340 end
332 341
333 function handlers.get_subscriptions(origin, stanza, subscriptions, service) 342 function handlers.get_subscriptions(origin, stanza, subscriptions, service)
631 origin.send(reply); 640 origin.send(reply);
632 return true; 641 return true;
633 end 642 end
634 643
635 function handlers.owner_set_purge(origin, stanza, purge, service) 644 function handlers.owner_set_purge(origin, stanza, purge, service)
636 local node, notify = purge.attr.node, purge.attr.notify; 645 local node = purge.attr.node;
637 notify = (notify == "1") or (notify == "true");
638 local reply; 646 local reply;
639 if not node then 647 if not node then
640 origin.send(pubsub_error_reply(stanza, "nodeid-required")); 648 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
641 return true; 649 return true;
642 end 650 end
643 local ok, ret = service:purge(node, stanza.attr.from, notify); 651 local ok, ret = service:purge(node, stanza.attr.from, true);
644 if ok then 652 if ok then
645 reply = st.reply(stanza); 653 reply = st.reply(stanza);
646 else 654 else
647 reply = pubsub_error_reply(stanza, ret); 655 reply = pubsub_error_reply(stanza, ret);
648 end 656 end