Software /
code /
prosody
Comparison
plugins/mod_pubsub.lua @ 3698:77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Sun, 05 Dec 2010 02:46:08 +0100 |
parent | 3697:67c01f75af97 |
child | 3699:150e58d69e60 |
comparison
equal
deleted
inserted
replaced
3697:67c01f75af97 | 3698:77171fd1dc3c |
---|---|
26 | 26 |
27 local pubsub_errors = { | 27 local pubsub_errors = { |
28 ["conflict"] = { "cancel", "conflict" }; | 28 ["conflict"] = { "cancel", "conflict" }; |
29 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; | 29 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; |
30 ["item-not-found"] = { "cancel", "item-not-found" }; | 30 ["item-not-found"] = { "cancel", "item-not-found" }; |
31 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; | |
31 }; | 32 }; |
32 function pubsub_error_reply(stanza, error) | 33 function pubsub_error_reply(stanza, error) |
33 local e = pubsub_errors[error]; | 34 local e = pubsub_errors[error]; |
34 local reply = st.error_reply(stanza, unpack(e, 1, 3)); | 35 local reply = st.error_reply(stanza, unpack(e, 1, 3)); |
35 if e[4] then | 36 if e[4] then |
97 reply = pubsub_error_reply(stanza, ret); | 98 reply = pubsub_error_reply(stanza, ret); |
98 end | 99 end |
99 return origin.send(reply); | 100 return origin.send(reply); |
100 end | 101 end |
101 | 102 |
103 function handlers.set_unsubscribe(origin, stanza, unsubscribe) | |
104 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid; | |
105 if jid_bare(jid) ~= jid_bare(stanza.attr.from) then | |
106 return origin.send(pubsub_error_reply(stanza, "invalid-jid")); | |
107 end | |
108 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid); | |
109 local reply; | |
110 if ok then | |
111 reply = st.reply(stanza); | |
112 else | |
113 reply = pubsub_error_reply(stanza, ret); | |
114 end | |
115 return origin.send(reply); | |
116 end | |
117 | |
102 function handlers.set_publish(origin, stanza, publish) | 118 function handlers.set_publish(origin, stanza, publish) |
103 local node = publish.attr.node; | 119 local node = publish.attr.node; |
104 local item = publish:get_child("item"); | 120 local item = publish:get_child("item"); |
105 local id = (item and item.attr.id) or uuid_generate(); | 121 local id = (item and item.attr.id) or uuid_generate(); |
106 local ok, ret = service:publish(node, stanza.attr.from, id, item); | 122 local ok, ret = service:publish(node, stanza.attr.from, id, item); |