Annotate

plugins/mod_pubsub/pubsub.lib.lua @ 6448:f799b45cf735

pubsub.lib: Fix variable renaming issue
author Kim Alvefur <zash@zash.se>
date Sun, 28 Sep 2014 03:06:29 +0200
parent 6447:8c2dc2ac5a40
child 6473:7c8f58d2b331
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 local st = require "util.stanza";
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 local uuid_generate = require "util.uuid".generate;
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
3 local dataform = require"util.dataforms".new;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
7 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
9 local _M = {};
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
10
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11 local handlers = {};
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 _M.handlers = handlers;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local pubsub_errors = {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15 ["conflict"] = { "cancel", "conflict" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17 ["jid-required"] = { "modify", "bad-request", nil, "jid-required" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 ["nodeid-required"] = { "modify", "bad-request", nil, "nodeid-required" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 ["item-not-found"] = { "cancel", "item-not-found" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 ["forbidden"] = { "cancel", "forbidden" };
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
22 ["not-allowed"] = { "cancel", "not-allowed" };
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 local function pubsub_error_reply(stanza, error)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25 local e = pubsub_errors[error];
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 local reply = st.error_reply(stanza, unpack(e, 1, 3));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 if e[4] then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30 return reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
32 _M.pubsub_error_reply = pubsub_error_reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
33
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
34 local node_config_form = require"util.dataforms".new {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
35 {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
36 type = "hidden";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
37 name = "FORM_TYPE";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
38 value = "http://jabber.org/protocol/pubsub#node_config";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
39 };
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
40 {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
41 type = "text-single";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
42 name = "pubsub#max_items";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
43 label = "Max # of items to persist";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
44 };
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
45 };
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
46
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 function handlers.get_items(origin, stanza, items, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 local node = items.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 local item = items:get_child("item");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50 local id = item and item.attr.id;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52 if not node then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
54 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
55 local ok, results = service:get_items(node, stanza.attr.from, id);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
56 if not ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 return origin.send(pubsub_error_reply(stanza, results));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
59
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
60 local data = st.stanza("items", { node = node });
6434
382e03a40dd2 mod_pubsub: Transplant pieces of cdcfd93e2f43 from trunk
Kim Alvefur <zash@zash.se>
parents: 5626
diff changeset
61 for _, id in ipairs(results) do
382e03a40dd2 mod_pubsub: Transplant pieces of cdcfd93e2f43 from trunk
Kim Alvefur <zash@zash.se>
parents: 5626
diff changeset
62 data:add_child(results[id]);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
64 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
65 if data then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
67 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
68 :add_child(data);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 reply = pubsub_error_reply(stanza, "item-not-found");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
72 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75 function handlers.get_subscriptions(origin, stanza, subscriptions, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
76 local node = subscriptions.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
77 local ok, ret = service:get_subscriptions(node, stanza.attr.from, stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 if not ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
79 return origin.send(pubsub_error_reply(stanza, ret));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81 local reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
82 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
83 :tag("subscriptions");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 for _, sub in ipairs(ret) do
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 reply:tag("subscription", { node = sub.node, jid = sub.jid, subscription = 'subscribed' }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
89
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 function handlers.set_create(origin, stanza, create, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91 local node = create.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 local ok, ret, reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
93 if node then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 ok, ret = service:create(node, stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
100 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101 repeat
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 node = uuid_generate();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 ok, ret = service:create(node, stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 until ok or ret ~= "conflict";
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
105 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 :tag("create", { node = node });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 function handlers.set_delete(origin, stanza, delete, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 local node = delete.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 local reply, notifier;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 if not node then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121 return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 local ok, ret = service:delete(node, stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 function handlers.set_subscribe(origin, stanza, subscribe, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 local node, jid = subscribe.attr.node, subscribe.attr.jid;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 if not (node and jid) then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135 return origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 --[[
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138 local options_tag, options = stanza.tags[1]:get_child("options"), nil;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
139 if options_tag then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
140 options = options_form:data(options_tag.tags[1]);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 --]]
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
143 local options_tag, options; -- FIXME
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
144 local ok, ret = service:add_subscription(node, stanza.attr.from, jid, options);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
145 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
147 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
148 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
149 :tag("subscription", {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150 node = node,
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
151 jid = jid,
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
152 subscription = "subscribed"
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
153 }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
154 if options_tag then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
155 reply:add_child(options_tag);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
156 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
157 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
158 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
159 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
160 origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
161 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
162
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
163 function handlers.set_unsubscribe(origin, stanza, unsubscribe, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
164 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
165 if not (node and jid) then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
166 return origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
167 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
168 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
169 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
170 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
171 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
172 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
173 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
174 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
175 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
176 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
177
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
178 function handlers.set_publish(origin, stanza, publish, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179 local node = publish.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
180 if not node then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
181 return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
182 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
183 local item = publish:get_child("item");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
184 local id = (item and item.attr.id);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
185 if not id then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
186 id = uuid_generate();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
187 if item then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
188 item.attr.id = id;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
189 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
190 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
191 local ok, ret = service:publish(node, stanza.attr.from, id, item);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
192 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
193 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
194 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
195 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
196 :tag("publish", { node = node })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
197 :tag("item", { id = id });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
198 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
199 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
200 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
201 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
202 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
203
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
204 function handlers.set_retract(origin, stanza, retract, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
205 local node, notify = retract.attr.node, retract.attr.notify;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
206 notify = (notify == "1") or (notify == "true");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
207 local item = retract:get_child("item");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
208 local id = item and item.attr.id
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
209 if not (node and id) then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
210 return origin.send(pubsub_error_reply(stanza, node and "item-not-found" or "nodeid-required"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
211 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
212 local reply, notifier;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
213 if notify then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
214 notifier = st.stanza("retract", { id = id });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
215 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
216 local ok, ret = service:retract(node, stanza.attr.from, id, notifier);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
217 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
218 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
219 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
220 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
221 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
222 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
223 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
224
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
225 function handlers.set_purge(origin, stanza, purge, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
226 local node, notify = purge.attr.node, purge.attr.notify;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
227 notify = (notify == "1") or (notify == "true");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
228 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
229 if not node then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
230 return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
231 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
232 local ok, ret = service:purge(node, stanza.attr.from, notify);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
233 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
234 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
235 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
236 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
237 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
238 return origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
239 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
240
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
241 function handlers.get_configure(origin, stanza, config, service)
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
242 local node = config.attr.node;
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
243 if not node then
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
244 return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
245 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
246
6445
f1ad3923368c pubsub.lib: Fix actor in configure
Kim Alvefur <zash@zash.se>
parents: 6441
diff changeset
247 if not service:may(node, stanza.attr.from, "configure") then
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
248 return origin.send(pubsub_error_reply(stanza, "forbidden"));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
249 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
250
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
251 local node_obj = service.nodes[node];
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
252 if not node_obj then
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
253 return origin.send(pubsub_error_reply(stanza, "item-not-found"));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
254 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
255
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
256 local reply = st.reply(stanza)
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
257 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
258 :tag("configure", { node = node })
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
259 :add_child(node_config_form:form(node_obj.config));
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
260 return origin.send(reply);
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
261 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
262
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
263 function handlers.set_configure(origin, stanza, config, service)
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
264 local node = config.attr.node;
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
265 if not node then
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
266 return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
267 end
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
268 if not service:may(node, stanza.attr.from, "configure") then
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
269 return origin.send(pubsub_error_reply(stanza, "forbidden"));
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
270 end
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
271 local new_config, err = node_config_form:data(config.tags[1]);
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
272 if not new_config then
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
273 return origin.send(st.error_reply(stanza, "modify", "bad-request", err));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
274 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
275 local ok, err = service:set_node_config(node, stanza.attr.from, new_config);
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
276 if not ok then
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
277 return origin.send(pubsub_error_reply(stanza, err));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
278 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
279 return origin.send(st.reply(stanza));
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
280 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
281
6441
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
282 function handlers.get_default(origin, stanza, default, service)
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
283 local reply = st.reply(stanza)
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
284 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
6447
8c2dc2ac5a40 mod_pubsub: Fix retreival of node config defaults
Kim Alvefur <zash@zash.se>
parents: 6446
diff changeset
285 :tag("default")
6448
f799b45cf735 pubsub.lib: Fix variable renaming issue
Kim Alvefur <zash@zash.se>
parents: 6447
diff changeset
286 :add_child(node_config_form:form(service.node_defaults));
6441
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
287 return origin.send(reply);
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
288 end
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
289
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
290 return _M;