Software / code / prosody
Comparison
plugins/mod_pubsub.lua @ 5312:fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 25 Jan 2013 01:32:14 +0100 |
| parent | 5308:fd3219d64414 |
| child | 5313:3d63f5236464 |
comparison
equal
deleted
inserted
replaced
| 5311:86fe6e2fa5ae | 5312:fdcd2ac7c22d |
|---|---|
| 4 local uuid_generate = require "util.uuid".generate; | 4 local uuid_generate = require "util.uuid".generate; |
| 5 | 5 |
| 6 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; | 6 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
| 7 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; | 7 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; |
| 8 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; | 8 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; |
| 9 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; | |
| 9 | 10 |
| 10 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false); | 11 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false); |
| 11 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false); | 12 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false); |
| 12 local pubsub_disco_name = module:get_option("name"); | 13 local pubsub_disco_name = module:get_option("name"); |
| 13 if type(pubsub_disco_name) ~= "string" then pubsub_disco_name = "Prosody PubSub Service"; end | 14 if type(pubsub_disco_name) ~= "string" then pubsub_disco_name = "Prosody PubSub Service"; end |
| 199 end | 200 end |
| 200 | 201 |
| 201 function handlers.set_purge(origin, stanza, purge) | 202 function handlers.set_purge(origin, stanza, purge) |
| 202 local node, notify = purge.attr.node, purge.attr.notify; | 203 local node, notify = purge.attr.node, purge.attr.notify; |
| 203 notify = (notify == "1") or (notify == "true"); | 204 notify = (notify == "1") or (notify == "true"); |
| 204 local reply, notifier; | 205 local reply; |
| 205 if not node then | 206 if not node then |
| 206 origin.send(st.error_reply(stanza, "modify", "bad-request")); | 207 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
| 207 return true; | 208 return true; |
| 208 end | 209 end |
| 209 if notify then | 210 local ok, ret = service:purge(node, stanza.attr.from, notify); |
| 210 notifier = st.stanza("purge"); | |
| 211 end | |
| 212 local ok, ret = service:purge(node, stanza.attr.from, notifier); | |
| 213 if ok then | 211 if ok then |
| 214 reply = st.reply(stanza); | 212 reply = st.reply(stanza); |
| 215 else | 213 else |
| 216 reply = pubsub_error_reply(stanza, ret); | 214 reply = pubsub_error_reply(stanza, ret); |
| 217 end | 215 end |
| 218 return origin.send(reply); | 216 return origin.send(reply); |
| 219 end | 217 end |
| 220 | 218 |
| 221 function simple_broadcast(node, jids, item) | 219 function simple_broadcast(kind, node, jids, item) |
| 222 item = st.clone(item); | 220 if item then |
| 223 item.attr.xmlns = nil; -- Clear the pubsub namespace | 221 item = st.clone(item); |
| 222 item.attr.xmlns = nil; -- Clear the pubsub namespace | |
| 223 end | |
| 224 local message = st.message({ from = module.host, type = "headline" }) | 224 local message = st.message({ from = module.host, type = "headline" }) |
| 225 :tag("event", { xmlns = xmlns_pubsub_event }) | 225 :tag("event", { xmlns = xmlns_pubsub_event }) |
| 226 :tag("items", { node = node }) | 226 :tag(kind, { node = node }) |
| 227 :add_child(item); | 227 :add_child(item); |
| 228 for jid in pairs(jids) do | 228 for jid in pairs(jids) do |
| 229 module:log("debug", "Sending notification to %s", jid); | 229 module:log("debug", "Sending notification to %s", jid); |
| 230 message.attr.to = jid; | 230 message.attr.to = jid; |
| 231 module:send(message); | 231 module:send(message); |
| 232 end | 232 end |
| 233 end | 233 end |
| 234 | 234 |
| 235 module:hook("iq/host/http://jabber.org/protocol/pubsub:pubsub", handle_pubsub_iq); | 235 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); |
| 236 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); | |
| 236 | 237 |
| 237 local disco_info; | 238 local disco_info; |
| 238 | 239 |
| 239 local feature_map = { | 240 local feature_map = { |
| 240 create = { "create-nodes", "instant-nodes", "item-ids" }; | 241 create = { "create-nodes", "instant-nodes", "item-ids" }; |