Software / code / prosody
Comparison
plugins/mod_muc.lua @ 879:2189baddedb8
MUC: Kick participants for error replies only on a selected list of error conditions
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Wed, 04 Mar 2009 22:45:06 +0500 |
| parent | 856:946d0f91bd38 |
| child | 896:2c0b9e3c11c3 |
comparison
equal
deleted
inserted
replaced
| 878:72a7eeaa9e58 | 879:2189baddedb8 |
|---|---|
| 68 return stanza, 0; | 68 return stanza, 0; |
| 69 end | 69 end |
| 70 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; | 70 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; |
| 71 function get_filtered_presence(stanza) | 71 function get_filtered_presence(stanza) |
| 72 return filter_xmlns_from_stanza(st.clone(stanza), presence_filters); | 72 return filter_xmlns_from_stanza(st.clone(stanza), presence_filters); |
| 73 end | |
| 74 local kickable_error_conditions = { | |
| 75 ["gone"] = true; | |
| 76 ["internal-server-error"] = true; | |
| 77 ["item-not-found"] = true; | |
| 78 ["jid-malformed"] = true; | |
| 79 ["recipient-unavailable"] = true; | |
| 80 ["redirect"] = true; | |
| 81 ["remote-server-not-found"] = true; | |
| 82 ["remote-server-timeout"] = true; | |
| 83 ["service-unavailable"] = true; | |
| 84 }; | |
| 85 function get_kickable_error(stanza) | |
| 86 for _, tag in ipairs(stanza.tags) do | |
| 87 if tag.name == "error" and tag.attr.xmlns == "jabber:client" then | |
| 88 for _, cond in ipairs(tag.tags) do | |
| 89 if cond.attr.xmlns == "urn:ietf:params:xml:ns:xmpp-stanzas" then | |
| 90 return kickable_error_conditions[cond.name] and cond.name; | |
| 91 end | |
| 92 end | |
| 93 return true; -- malformed error message | |
| 94 end | |
| 95 end | |
| 96 return true; -- malformed error message | |
| 73 end | 97 end |
| 74 function getUsingPath(stanza, path, getText) | 98 function getUsingPath(stanza, path, getText) |
| 75 local tag = stanza; | 99 local tag = stanza; |
| 76 for _, name in ipairs(path) do | 100 for _, name in ipairs(path) do |
| 77 if type(tag) ~= 'table' then return; end | 101 if type(tag) ~= 'table' then return; end |
| 289 end | 313 end |
| 290 elseif not current_nick and type ~= "error" then -- not in room | 314 elseif not current_nick and type ~= "error" then -- not in room |
| 291 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); | 315 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
| 292 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM | 316 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM |
| 293 origin.send(st.error_reply(stanza, "modify", "bad-request")); | 317 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
| 294 elseif stanza.name == "message" and type == "error" then | 318 elseif stanza.name == "message" and type == "error" and get_kickable_error(stanza) then |
| 295 log("debug", "%s kicked from %s for sending an error message", current_nick, room); | 319 log("debug", "%s kicked from %s for sending an error message", current_nick, room); |
| 296 handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}):tag('status'):text('This participant is kicked from the room because he sent an error message to another occupant')); -- send unavailable | 320 handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}):tag('status'):text('This participant is kicked from the room because he sent an error message to another occupant')); -- send unavailable |
| 297 else -- private stanza | 321 else -- private stanza |
| 298 local o_data = rooms:get(room, to); | 322 local o_data = rooms:get(room, to); |
| 299 if o_data then | 323 if o_data then |
| 300 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); | 324 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); |
| 301 local jid = o_data.jid; | 325 local jid = o_data.jid; |
| 302 if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' then jid = jid_bare(jid); end | 326 if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' then jid = jid_bare(jid); end |
| 303 stanza.attr.to, stanza.attr.from = jid, current_nick; | 327 stanza.attr.to, stanza.attr.from = jid, current_nick; |
| 304 core_route_stanza(component, stanza); | 328 core_route_stanza(component, stanza); |
| 305 else -- recipient not in room | 329 elseif type ~= "error" and type ~= "result" then -- recipient not in room |
| 306 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); | 330 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); |
| 307 end | 331 end |
| 308 end | 332 end |
| 309 end | 333 end |
| 310 | 334 |
| 340 local current_nick = jid_nick:get(stanza.attr.from, to); | 364 local current_nick = jid_nick:get(stanza.attr.from, to); |
| 341 if current_nick then | 365 if current_nick then |
| 342 stanza.attr.to = current_nick; | 366 stanza.attr.to = current_nick; |
| 343 handle_to_occupant(origin, stanza); | 367 handle_to_occupant(origin, stanza); |
| 344 stanza.attr.to = to; | 368 stanza.attr.to = to; |
| 345 else | 369 elseif type ~= "error" and type ~= "result" then |
| 346 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 370 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
| 347 end | 371 end |
| 348 else | 372 else |
| 349 if type == "error" or type == "result" then return; end | 373 if type == "error" or type == "result" then return; end |
| 350 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 374 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |