Annotate

plugins/mod_pubsub.lua @ 3935:2733b56f23b0

mod_pubsub: Set normalize_jid instead of jids_equal
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Dec 2010 03:04:44 +0000
parent 3933:24f0a7544a7a
child 3939:b66e9a7593b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local pubsub = require "util.pubsub";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local st = require "util.stanza";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local uuid_generate = require "util.uuid".generate;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 require "core.modulemanager".load(module.host, "iq");
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
12 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false);
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
13 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false);
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
14
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local service;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local handlers = {};
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 function handle_pubsub_iq(event)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local origin, stanza = event.origin, event.stanza;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local pubsub = stanza.tags[1];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local action = pubsub.tags[1];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local handler = handlers[stanza.attr.type.."_"..action.name];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 if handler then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 handler(origin, stanza, action);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 return true;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 local pubsub_errors = {
3697
67c01f75af97 mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents: 3672
diff changeset
31 ["conflict"] = { "cancel", "conflict" };
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" };
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 ["item-not-found"] = { "cancel", "item-not-found" };
3698
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
34 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
3908
4d8081c35f01 mod_pubsub: Add 'forbidden' error support
Matthew Wild <mwild1@gmail.com>
parents: 3761
diff changeset
35 ["forbidden"] = { "cancel", "forbidden" };
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 };
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 function pubsub_error_reply(stanza, error)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 local e = pubsub_errors[error];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local reply = st.error_reply(stanza, unpack(e, 1, 3));
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 if e[4] then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up();
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 return reply;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
46 function handlers.get_items(origin, stanza, items)
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
47 local node = items.attr.node;
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
48 local item = items:get_child("item");
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
49 local id = item and item.attr.id;
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
50
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
51 local ok, results = service:get_items(node, stanza.attr.from, id);
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
52 if not ok then
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
53 return origin.send(pubsub_error_reply(stanza, results));
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
54 end
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
55
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
56 local data = st.stanza("items", { node = node });
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
57 for _, entry in pairs(results) do
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
58 data:add_child(entry);
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
59 end
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
60 if data then
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
61 reply = st.reply(stanza)
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
62 :tag("pubsub", { xmlns = xmlns_pubsub })
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
63 :add_child(data);
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
64 else
3697
67c01f75af97 mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents: 3672
diff changeset
65 reply = pubsub_error_reply(stanza, "item-not-found");
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
66 end
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
67 return origin.send(reply);
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
68 end
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
69
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
70 function handlers.set_create(origin, stanza, create)
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
71 local node = create.attr.node;
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
72 local ok, ret, reply;
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
73 if node then
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
74 ok, ret = service:create(node, stanza.attr.from);
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
75 if ok then
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
76 reply = st.reply(stanza);
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
77 else
3697
67c01f75af97 mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents: 3672
diff changeset
78 reply = pubsub_error_reply(stanza, ret);
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
79 end
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
80 else
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
81 repeat
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
82 node = uuid_generate();
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
83 ok, ret = service:create(node, stanza.attr.from);
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
84 until ok or ret ~= "conflict";
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
85 if ok then
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
86 reply = st.reply(stanza)
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
87 :tag("pubsub", { xmlns = xmlns_pubsub })
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
88 :tag("create", { node = node });
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
89 else
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
90 reply = pubsub_error_reply(stanza, ret);
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
91 end
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
92 end
3699
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
93 return origin.send(reply);
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
94 end
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
95
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 function handlers.set_subscribe(origin, stanza, subscribe)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 local node, jid = subscribe.attr.node, subscribe.attr.jid;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 if jid_bare(jid) ~= jid_bare(stanza.attr.from) then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 return origin.send(pubsub_error_reply(stanza, "invalid-jid"));
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 local ok, ret = service:add_subscription(node, stanza.attr.from, jid);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 local reply;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 if ok then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 reply = st.reply(stanza)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 :tag("pubsub", { xmlns = xmlns_pubsub })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 :tag("subscription", {
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 node = node,
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 jid = jid,
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 subscription = "subscribed"
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 });
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 else
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 reply = pubsub_error_reply(stanza, ret);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 return origin.send(reply);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116
3698
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
117 function handlers.set_unsubscribe(origin, stanza, unsubscribe)
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
118 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid;
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
119 if jid_bare(jid) ~= jid_bare(stanza.attr.from) then
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
120 return origin.send(pubsub_error_reply(stanza, "invalid-jid"));
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
121 end
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
122 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
123 local reply;
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
124 if ok then
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
125 reply = st.reply(stanza);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
126 else
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
127 reply = pubsub_error_reply(stanza, ret);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
128 end
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
129 return origin.send(reply);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
130 end
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
131
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 function handlers.set_publish(origin, stanza, publish)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 local node = publish.attr.node;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 local item = publish:get_child("item");
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 local id = (item and item.attr.id) or uuid_generate();
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 local ok, ret = service:publish(node, stanza.attr.from, id, item);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 local reply;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 if ok then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 reply = st.reply(stanza)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 :tag("pubsub", { xmlns = xmlns_pubsub })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 :tag("publish", { node = node })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 :tag("item", { id = id });
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 else
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 reply = pubsub_error_reply(stanza, ret);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 return origin.send(reply);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
3699
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
149 function handlers.set_retract(origin, stanza, retract)
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
150 local node, notify = retract.attr.node, retract.attr.notify;
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
151 notify = (notify == "1") or (notify == "true");
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
152 local item = retract:get_child("item");
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
153 local id = item and item.attr.id
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
154 local reply, notifier;
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
155 if notify then
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
156 notifier = st.stanza("retract", { id = id });
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
157 end
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
158 local ok, ret = service:retract(node, stanza.attr.from, id, notifier);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
159 if ok then
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
160 reply = st.reply(stanza);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
161 else
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
162 reply = pubsub_error_reply(stanza, ret);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
163 end
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
164 return origin.send(reply);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
165 end
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
166
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 function simple_broadcast(node, jids, item)
3700
c8fcd63e9526 mod_pubsub: Ensure <item> is in correct scope when broadcasting an event
Matthew Wild <mwild1@gmail.com>
parents: 3699
diff changeset
168 item = st.clone(item);
c8fcd63e9526 mod_pubsub: Ensure <item> is in correct scope when broadcasting an event
Matthew Wild <mwild1@gmail.com>
parents: 3699
diff changeset
169 item.attr.xmlns = nil; -- Clear the pubsub namespace
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 local message = st.message({ from = module.host, type = "headline" })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 :tag("event", { xmlns = xmlns_pubsub_event })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 :tag("items", { node = node })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 :add_child(item);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 for jid in pairs(jids) do
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 module:log("debug", "Sending notification to %s", jid);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 message.attr.to = jid;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 core_post_stanza(hosts[module.host], message);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180
3621
7e1a1dd42088 mod_pubsub: Expose 'service'
Matthew Wild <mwild1@gmail.com>
parents: 3619
diff changeset
181 module:hook("iq/host/http://jabber.org/protocol/pubsub:pubsub", handle_pubsub_iq);
7e1a1dd42088 mod_pubsub: Expose 'service'
Matthew Wild <mwild1@gmail.com>
parents: 3619
diff changeset
182
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
183 local disco_info;
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
184
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
185 local feature_map = {
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
186 create = { "create-nodes", autocreate_on_publish and "instant-nodes", "item-ids" };
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
187 retract = { "delete-items", "retract-items" };
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
188 publish = { "publish" };
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
189 get_items = { "retrieve-items" };
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
190 };
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
191
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
192 local function add_disco_features_from_service(disco, service)
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
193 for method, features in pairs(feature_map) do
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
194 if service[method] then
3915
e24fcbb01fb6 mod_pubsub: Iterate over disco features in correct table
Matthew Wild <mwild1@gmail.com>
parents: 3914
diff changeset
195 for _, feature in ipairs(features) do
3918
f30c5bad29b8 mod_pubsub: Skip false features in feature_map
Matthew Wild <mwild1@gmail.com>
parents: 3916
diff changeset
196 if feature then
f30c5bad29b8 mod_pubsub: Skip false features in feature_map
Matthew Wild <mwild1@gmail.com>
parents: 3916
diff changeset
197 disco:tag("feature", { var = xmlns_pubsub.."#"..feature }):up();
f30c5bad29b8 mod_pubsub: Skip false features in feature_map
Matthew Wild <mwild1@gmail.com>
parents: 3916
diff changeset
198 end
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
199 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
200 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
201 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
202 for affiliation in pairs(service.config.capabilities) do
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
203 if affiliation ~= "none" and affiliation ~= "owner" then
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
204 disco:tag("feature", { var = xmlns_pubsub.."#"..affiliation.."-affiliation" }):up();
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
205 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
206 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
207 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
208
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
209 local function build_disco_info(service)
3916
ffe5a0d36f57 mod_pubsub: Return disco#info stanza from build_disco_info()
Matthew Wild <mwild1@gmail.com>
parents: 3915
diff changeset
210 local disco_info = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" })
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
211 :tag("identity", { category = "pubsub", type = "service" }):up()
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
212 :tag("feature", { var = "http://jabber.org/protocol/pubsub" }):up();
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
213 add_disco_features_from_service(disco_info, service);
3916
ffe5a0d36f57 mod_pubsub: Return disco#info stanza from build_disco_info()
Matthew Wild <mwild1@gmail.com>
parents: 3915
diff changeset
214 return disco_info;
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
215 end
3760
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
216
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
217 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function (event)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
218 event.origin.send(st.reply(event.stanza):add_child(disco_info));
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
219 return true;
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
220 end);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
221
3932
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
222 local function handle_disco_items_on_node(event)
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
223 local stanza, origin = event.stanza, event.origin;
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
224 local query = stanza.tags[1];
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
225 local node = query.attr.node;
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
226 local ok, ret = service:get_items(node, stanza.attr.from);
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
227 if not ok then
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
228 return origin.send(pubsub_error_reply(stanza, ret));
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
229 end
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
230
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
231 local reply = st.reply(stanza)
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
232 :tag("query", { xmlns = xmlns_disco_items });
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
233
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
234 for id, item in pairs(ret) do
3933
24f0a7544a7a mod_pubsub: Fix a missing :up() from the last commit
Matthew Wild <mwild1@gmail.com>
parents: 3932
diff changeset
235 reply:tag("item", { jid = module.host, name = id }):up();
3932
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
236 end
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
237
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
238 return origin.send(reply);
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
239 end
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
240
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
241
3760
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
242 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function (event)
3932
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
243 if event.stanza.tags[1].attr.node then
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
244 return handle_disco_items_on_node(event);
aa245e43b21e mod_pubsub: Handle disco#items on nodes
Matthew Wild <mwild1@gmail.com>
parents: 3919
diff changeset
245 end
3760
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
246 local ok, ret = service:get_nodes(event.stanza.attr.from);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
247 if not ok then
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
248 event.origin.send(pubsub_error_reply(stanza, ret));
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
249 else
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
250 local reply = st.reply(event.stanza)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
251 :tag("query", { xmlns = "http://jabber.org/protocol/disco#items" });
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
252 for node, node_obj in pairs(ret) do
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
253 reply:tag("item", { jid = module.host, node = node, name = node_obj.config.name }):up();
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
254 end
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
255 event.origin.send(reply);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
256 end
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
257 return true;
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
258 end);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
259
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
260 local admin_aff = module:get_option_string("default_admin_affiliation", "owner");
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
261 local function get_affiliation(jid)
3919
e288372dd19f mod_pubsub: Use bare JID in get_affiliation
Matthew Wild <mwild1@gmail.com>
parents: 3918
diff changeset
262 local bare_jid = jid_bare(jid);
e288372dd19f mod_pubsub: Use bare JID in get_affiliation
Matthew Wild <mwild1@gmail.com>
parents: 3918
diff changeset
263 if bare_jid == module.host or usermanager.is_admin(bare_jid, module.host) then
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
264 return admin_aff;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
265 end
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
266 end
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
267
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
268 function set_service(new_service)
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
269 service = new_service;
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
270 module.environment.service = service;
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
271 disco_info = build_disco_info(service);
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
272 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
273
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
274 function module.save()
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
275 return { service = service };
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
276 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
277
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
278 function module.restore(data)
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
279 set_service(data.service);
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
280 end
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
281
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
282 set_service(pubsub.new({
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
283 capabilities = {
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
284 none = {
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
285 create = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
286 publish = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
287 retract = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
288 get_nodes = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
289
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
290 subscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
291 unsubscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
292 get_subscription = true;
3913
e748d29b18d6 mod_pubsub: Fix capabilities table from some debugging
Matthew Wild <mwild1@gmail.com>
parents: 3912
diff changeset
293 get_items = true;
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
294
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
295 subscribe_other = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
296 unsubscribe_other = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
297 get_subscription_other = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
298
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
299 be_subscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
300 be_unsubscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
301
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
302 set_affiliation = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
303 };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
304 owner = {
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
305 create = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
306 publish = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
307 retract = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
308 get_nodes = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
309
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
310 subscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
311 unsubscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
312 get_subscription = true;
3913
e748d29b18d6 mod_pubsub: Fix capabilities table from some debugging
Matthew Wild <mwild1@gmail.com>
parents: 3912
diff changeset
313 get_items = true;
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
314
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
315
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
316 subscribe_other = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
317 unsubscribe_other = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
318 get_subscription_other = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
319
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
320 be_subscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
321 be_unsubscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
322
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
323 set_affiliation = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
324 };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
325 };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
326
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
327 autocreate_on_publish = autocreate_on_publish;
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
328 autocreate_on_subscribe = autocreate_on_subscribe;
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
329
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
330 broadcaster = simple_broadcast;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
331 get_affiliation = get_affiliation;
3935
2733b56f23b0 mod_pubsub: Set normalize_jid instead of jids_equal
Matthew Wild <mwild1@gmail.com>
parents: 3933
diff changeset
332
2733b56f23b0 mod_pubsub: Set normalize_jid instead of jids_equal
Matthew Wild <mwild1@gmail.com>
parents: 3933
diff changeset
333 normalize_jid = jid_bare;
3914
f10282c2e410 mod_pubsub: Build disco#info based on the methods provided by the pubsub service object. Add public set_service() method to change the service object used by the module.
Matthew Wild <mwild1@gmail.com>
parents: 3913
diff changeset
334 }));