plugins/mod_pubsub.lua

Tue, 21 Dec 2010 04:15:29 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 21 Dec 2010 04:15:29 +0000
changeset 3915
e24fcbb01fb6
parent 3914
f10282c2e410
child 3916
ffe5a0d36f57
permissions
-rw-r--r--

mod_pubsub: Iterate over disco features in correct table

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
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
196 disco:tag("feature", { var = xmlns_pubsub.."#"..feature }):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
197 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
198 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
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 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
201 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
202 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
203 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
204 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
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
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 local function 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
208 disco_info = st.stanza("query", { xmlns = "http://jabber.org/protocol/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
209 :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
210 :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
211 add_disco_features_from_service(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
212 end
3760
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
213
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
214 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
215 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
216 return true;
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
217 end);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
218
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
219 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function (event)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
220 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
221 if not ok then
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
222 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
223 else
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
224 local reply = st.reply(event.stanza)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
225 :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
226 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
227 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
228 end
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
229 event.origin.send(reply);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
230 end
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
231 return true;
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
232 end);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
233
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
234 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
235 local function get_affiliation(jid)
3912
dfc9789f9016 mod_pubsub: Make the pubsub host an admin too
Matthew Wild <mwild1@gmail.com>
parents: 3911
diff changeset
236 if jid == module.host or usermanager.is_admin(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
237 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
238 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
239 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
240
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
241 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
242 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
243 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
244 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
245 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
246
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
247 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
248 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
249 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
250
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
251 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
252 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
253 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
254
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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262
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
263 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
264 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
265 get_subscription = true;
3913
e748d29b18d6 mod_pubsub: Fix capabilities table from some debugging
Matthew Wild <mwild1@gmail.com>
parents: 3912
diff changeset
266 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
267
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
268 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
269 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
270 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
271
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
272 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
273 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
274
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
275 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
276 };
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
277 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
278 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
279 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
280 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
281 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
282
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 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
284 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
285 get_subscription = true;
3913
e748d29b18d6 mod_pubsub: Fix capabilities table from some debugging
Matthew Wild <mwild1@gmail.com>
parents: 3912
diff changeset
286 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
287
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
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 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
290 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
291 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
292
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
293 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
294 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
295
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 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
297 };
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
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
300 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
301 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
302
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 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
304 get_affiliation = get_affiliation;
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 jids_equal = function (jid1, jid2)
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 return jid_bare(jid1) == jid_bare(jid2);
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 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
308 }));

mercurial