Software /
code /
prosody
Annotate
plugins/mod_pubsub.lua @ 3913:e748d29b18d6
mod_pubsub: Fix capabilities table from some debugging
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 21 Dec 2010 03:30:18 +0000 |
parent | 3912:dfc9789f9016 |
child | 3914:f10282c2e410 |
rev | line source |
---|---|
3619 | 1 local pubsub = require "util.pubsub"; |
2 local st = require "util.stanza"; | |
3 local jid_bare = require "util.jid".bare; | |
4 local uuid_generate = require "util.uuid".generate; | |
5 | |
6 require "core.modulemanager".load(module.host, "iq"); | |
7 | |
8 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; | |
9 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; | |
10 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; | |
11 | |
12 local service; | |
13 | |
14 local handlers = {}; | |
15 | |
16 function handle_pubsub_iq(event) | |
17 local origin, stanza = event.origin, event.stanza; | |
18 local pubsub = stanza.tags[1]; | |
19 local action = pubsub.tags[1]; | |
20 local handler = handlers[stanza.attr.type.."_"..action.name]; | |
21 if handler then | |
22 handler(origin, stanza, action); | |
23 return true; | |
24 end | |
25 end | |
26 | |
27 local pubsub_errors = { | |
3697
67c01f75af97
mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
28 ["conflict"] = { "cancel", "conflict" }; |
3619 | 29 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; |
30 ["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
|
31 ["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
|
32 ["forbidden"] = { "cancel", "forbidden" }; |
3619 | 33 }; |
34 function pubsub_error_reply(stanza, error) | |
35 local e = pubsub_errors[error]; | |
36 local reply = st.error_reply(stanza, unpack(e, 1, 3)); | |
37 if e[4] then | |
38 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up(); | |
39 end | |
40 return reply; | |
41 end | |
42 | |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
43 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
|
44 local node = items.attr.node; |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
45 local item = items:get_child("item"); |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
46 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
|
47 |
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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
53 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
|
54 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
|
55 data:add_child(entry); |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
56 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
57 if data then |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
58 reply = st.reply(stanza) |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
59 :tag("pubsub", { xmlns = xmlns_pubsub }) |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
60 :add_child(data); |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
61 else |
3697
67c01f75af97
mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
62 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
|
63 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
64 return origin.send(reply); |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
65 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3622
diff
changeset
|
66 |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
67 function handlers.set_create(origin, stanza, create) |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
68 local node = create.attr.node; |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
69 local ok, ret, reply; |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
70 if node then |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
71 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
|
72 if ok then |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
73 reply = st.reply(stanza); |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
74 else |
3697
67c01f75af97
mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
75 reply = pubsub_error_reply(stanza, ret); |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
76 end |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
77 else |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
78 repeat |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
79 node = uuid_generate(); |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 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
|
84 :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
|
85 :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
|
86 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
|
87 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
|
88 end |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
89 end |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
90 return origin.send(reply); |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
91 end |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
92 |
3619 | 93 function handlers.set_subscribe(origin, stanza, subscribe) |
94 local node, jid = subscribe.attr.node, subscribe.attr.jid; | |
95 if jid_bare(jid) ~= jid_bare(stanza.attr.from) then | |
96 return origin.send(pubsub_error_reply(stanza, "invalid-jid")); | |
97 end | |
98 local ok, ret = service:add_subscription(node, stanza.attr.from, jid); | |
99 local reply; | |
100 if ok then | |
101 reply = st.reply(stanza) | |
102 :tag("pubsub", { xmlns = xmlns_pubsub }) | |
103 :tag("subscription", { | |
104 node = node, | |
105 jid = jid, | |
106 subscription = "subscribed" | |
107 }); | |
108 else | |
109 reply = pubsub_error_reply(stanza, ret); | |
110 end | |
111 return origin.send(reply); | |
112 end | |
113 | |
3698
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
114 function handlers.set_unsubscribe(origin, stanza, unsubscribe) |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
119 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
|
120 local reply; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
121 if ok then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
122 reply = st.reply(stanza); |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
123 else |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
124 reply = pubsub_error_reply(stanza, ret); |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
125 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
126 return origin.send(reply); |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
127 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3697
diff
changeset
|
128 |
3619 | 129 function handlers.set_publish(origin, stanza, publish) |
130 local node = publish.attr.node; | |
131 local item = publish:get_child("item"); | |
132 local id = (item and item.attr.id) or uuid_generate(); | |
133 local ok, ret = service:publish(node, stanza.attr.from, id, item); | |
134 local reply; | |
135 if ok then | |
136 reply = st.reply(stanza) | |
137 :tag("pubsub", { xmlns = xmlns_pubsub }) | |
138 :tag("publish", { node = node }) | |
139 :tag("item", { id = id }); | |
140 else | |
141 reply = pubsub_error_reply(stanza, ret); | |
142 end | |
143 return origin.send(reply); | |
144 end | |
145 | |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
146 function handlers.set_retract(origin, stanza, retract) |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
147 local node, notify = retract.attr.node, retract.attr.notify; |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
148 notify = (notify == "1") or (notify == "true"); |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
149 local item = retract:get_child("item"); |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
150 local id = item and item.attr.id |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
151 local reply, notifier; |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
152 if notify then |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
153 notifier = st.stanza("retract", { id = id }); |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
154 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
155 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
|
156 if ok then |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
157 reply = st.reply(stanza); |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
158 else |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
159 reply = pubsub_error_reply(stanza, ret); |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
160 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
161 return origin.send(reply); |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
162 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
163 |
3619 | 164 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
|
165 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
|
166 item.attr.xmlns = nil; -- Clear the pubsub namespace |
3619 | 167 local message = st.message({ from = module.host, type = "headline" }) |
168 :tag("event", { xmlns = xmlns_pubsub_event }) | |
169 :tag("items", { node = node }) | |
170 :add_child(item); | |
171 for jid in pairs(jids) do | |
172 module:log("debug", "Sending notification to %s", jid); | |
173 message.attr.to = jid; | |
174 core_post_stanza(hosts[module.host], message); | |
175 end | |
176 end | |
177 | |
3621
7e1a1dd42088
mod_pubsub: Expose 'service'
Matthew Wild <mwild1@gmail.com>
parents:
3619
diff
changeset
|
178 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
|
179 |
3760
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
180 local disco_info = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" }) |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
181 :tag("identity", { category = "pubsub", type = "service" }):up() |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
182 :tag("feature", { var = "http://jabber.org/protocol/pubsub" }):up(); |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
183 |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
184 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
|
185 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
|
186 return true; |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
187 end); |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
188 |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
189 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
|
190 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
|
191 if not ok then |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
192 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
|
193 else |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
194 local reply = st.reply(event.stanza) |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
195 :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
|
196 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
|
197 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
|
198 end |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
199 event.origin.send(reply); |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
200 end |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
201 return true; |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
202 end); |
3bfb65496773
mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents:
3700
diff
changeset
|
203 |
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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 |
3619 | 211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
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
|
219 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
|
220 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
|
221 get_subscription = true; |
3913
e748d29b18d6
mod_pubsub: Fix capabilities table from some debugging
Matthew Wild <mwild1@gmail.com>
parents:
3912
diff
changeset
|
222 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
|
223 |
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
|
224 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
|
225 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
|
226 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
|
227 |
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
|
228 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
|
229 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
|
230 |
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
|
231 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
|
232 }; |
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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 |
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 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
|
240 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
|
241 get_subscription = true; |
3913
e748d29b18d6
mod_pubsub: Fix capabilities table from some debugging
Matthew Wild <mwild1@gmail.com>
parents:
3912
diff
changeset
|
242 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
|
243 |
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
|
244 |
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
|
245 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
|
246 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
|
247 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
|
248 |
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
|
249 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
|
250 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
|
251 |
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
|
252 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
|
253 }; |
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
|
254 }; |
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
|
255 |
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 autocreate_on_publish = module:get_option_boolean("autocreate_on_publish"); |
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 autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe"); |
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 |
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 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
|
260 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
|
261 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
|
262 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
|
263 end; |
3619 | 264 }); |
3622
418354197a02
mod_pubsub: Use module.environment to reference the module's environment
Matthew Wild <mwild1@gmail.com>
parents:
3621
diff
changeset
|
265 module.environment.service = service; |
3619 | 266 |
3761
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
267 function module.save() |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
268 return { service = service }; |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
269 end |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
270 |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
271 function module.restore(data) |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
272 service = data.service; |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
273 module.environment.service = service; |
e5fb26e8faeb
mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents:
3760
diff
changeset
|
274 end |