Mercurial > prosody-modules
comparison mod_blocking/mod_blocking.lua @ 262:4986ffe35704
mod_blocking: Updated to use the new events API.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 16 Oct 2010 06:23:16 +0500 |
parents | bcd7dc51a5e3 |
children | 000f1d1c6ca5 |
comparison
equal
deleted
inserted
replaced
261:0f46fb2dbc79 | 262:4986ffe35704 |
---|---|
98 end | 98 end |
99 end | 99 end |
100 return jid_list; | 100 return jid_list; |
101 end | 101 end |
102 | 102 |
103 function handle_blocking_command(session, stanza) | 103 function handle_blocking_command(event) |
104 local session, stanza = event.origin, event.stanza; | |
105 | |
104 local username, host = jid_split(stanza.attr.from); | 106 local username, host = jid_split(stanza.attr.from); |
105 if stanza.attr.type == "set" then | 107 if stanza.attr.type == "set" then |
106 if stanza.tags[1].name == "block" then | 108 if stanza.tags[1].name == "block" then |
107 local block = stanza.tags[1]; | 109 local block = stanza.tags[1]; |
108 local block_jid_list = {}; | 110 local block_jid_list = {}; |
109 for item in block:childtags() do | 111 for item in block:childtags() do |
110 block_jid_list[#block_jid_list+1] = item.attr.jid; | 112 block_jid_list[#block_jid_list+1] = item.attr.jid; |
111 end | 113 end |
112 if #block_jid_list == 0 then | 114 if #block_jid_list == 0 then |
113 --FIXME: Reply bad-request | 115 session.send(st.error_reply(stanza, "modify", "bad-request")); |
114 else | 116 else |
115 for _, jid in ipairs(block_jid_list) do | 117 for _, jid in ipairs(block_jid_list) do |
116 add_blocked_jid(username, host, jid); | 118 add_blocked_jid(username, host, jid); |
117 end | 119 end |
118 session.send(st.reply(stanza)); | 120 session.send(st.reply(stanza)); |
119 end | 121 end |
122 return true; | |
120 elseif stanza.tags[1].name == "unblock" then | 123 elseif stanza.tags[1].name == "unblock" then |
121 remove_all_blocked_jids(username, host); | 124 remove_all_blocked_jids(username, host); |
122 session.send(st.reply(stanza)); | 125 session.send(st.reply(stanza)); |
126 return true; | |
123 end | 127 end |
124 elseif stanza.attr.type == "get" and stanza.tags[1].name == "blocklist" then | 128 elseif stanza.attr.type == "get" and stanza.tags[1].name == "blocklist" then |
125 local reply = st.reply(stanza):tag("blocklist", { xmlns = xmlns_blocking }); | 129 local reply = st.reply(stanza):tag("blocklist", { xmlns = xmlns_blocking }); |
126 local blocked_jids = get_blocked_jids(username, host); | 130 local blocked_jids = get_blocked_jids(username, host); |
127 for _, jid in ipairs(blocked_jids) do | 131 for _, jid in ipairs(blocked_jids) do |
128 reply:tag("item", { jid = jid }):up(); | 132 reply:tag("item", { jid = jid }):up(); |
129 end | 133 end |
130 session.send(reply); | 134 session.send(reply); |
131 else | 135 return true; |
132 --FIXME: Need to respond with service-unavailable | |
133 end | 136 end |
134 end | 137 end |
135 | 138 |
136 module:add_iq_handler("c2s", xmlns_blocking, handle_blocking_command); | 139 module:hook("iq/self/urn:xmpp:blocking:blocklist", handle_blocking_command); |
140 module:hook("iq/self/urn:xmpp:blocking:block", handle_blocking_command); | |
141 module:hook("iq/self/urn:xmpp:blocking:unblock", handle_blocking_command); |