Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 10450:c1edeb9fe337
MUC: Indicate the component as origin of various errors where there's no room
A room that doesn't exist can't return an error, can it?
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Nov 2019 00:02:13 +0100 |
parent | 10449:2e36a54906e4 |
child | 10647:d1bfda983ffe |
comparison
equal
deleted
inserted
replaced
10449:2e36a54906e4 | 10450:c1edeb9fe337 |
---|---|
353 end, 1); | 353 end, 1); |
354 | 354 |
355 module:hook("muc-room-pre-create", function(event) | 355 module:hook("muc-room-pre-create", function(event) |
356 local origin, stanza = event.origin, event.stanza; | 356 local origin, stanza = event.origin, event.stanza; |
357 if not track_room(event.room) then | 357 if not track_room(event.room) then |
358 origin.send(st.error_reply(stanza, "wait", "resource-constraint")); | 358 origin.send(st.error_reply(stanza, "wait", "resource-constraint", nil, module.host)); |
359 return true; | 359 return true; |
360 end | 360 end |
361 end, -1000); | 361 end, -1000); |
362 | 362 |
363 module:hook("muc-room-destroyed",function(event) | 363 module:hook("muc-room-destroyed",function(event) |
404 local user_jid = stanza.attr.from; | 404 local user_jid = stanza.attr.from; |
405 if not is_admin(user_jid) and not ( | 405 if not is_admin(user_jid) and not ( |
406 restrict_room_creation == "local" and | 406 restrict_room_creation == "local" and |
407 select(2, jid_split(user_jid)) == host_suffix | 407 select(2, jid_split(user_jid)) == host_suffix |
408 ) then | 408 ) then |
409 origin.send(st.error_reply(stanza, "cancel", "not-allowed", "Room creation is restricted")); | 409 origin.send(st.error_reply(stanza, "cancel", "not-allowed", "Room creation is restricted", module.host)); |
410 return true; | 410 return true; |
411 end | 411 end |
412 end); | 412 end); |
413 end | 413 end |
414 end | 414 end |
449 -- Allow the room to be recreated by admin or after time has passed | 449 -- Allow the room to be recreated by admin or after time has passed |
450 delete_room(room); | 450 delete_room(room); |
451 room = nil; | 451 room = nil; |
452 else | 452 else |
453 if stanza.attr.type ~= "error" then | 453 if stanza.attr.type ~= "error" then |
454 local reply = st.error_reply(stanza, "cancel", "gone", room._data.reason) | 454 local reply = st.error_reply(stanza, "cancel", "gone", room._data.reason, module.host) |
455 if room._data.newjid then | 455 if room._data.newjid then |
456 local uri = "xmpp:"..room._data.newjid.."?join"; | 456 local uri = "xmpp:"..room._data.newjid.."?join"; |
457 reply:get_child("error"):child_with_name("gone"):text(uri); | 457 reply:get_child("error"):child_with_name("gone"):text(uri); |
458 end | 458 end |
459 event.origin.send(reply); | 459 event.origin.send(reply); |
463 end | 463 end |
464 | 464 |
465 if room == nil then | 465 if room == nil then |
466 -- Watch presence to create rooms | 466 -- Watch presence to create rooms |
467 if not jid_prep(room_jid, true) then | 467 if not jid_prep(room_jid, true) then |
468 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); | 468 origin.send(st.error_reply(stanza, "modify", "jid-malformed", nil, module.host)); |
469 return true; | 469 return true; |
470 end | 470 end |
471 if stanza.attr.type == nil and stanza.name == "presence" and stanza:get_child("x", "http://jabber.org/protocol/muc") then | 471 if stanza.attr.type == nil and stanza.name == "presence" and stanza:get_child("x", "http://jabber.org/protocol/muc") then |
472 room = muclib.new_room(room_jid); | 472 room = muclib.new_room(room_jid); |
473 return room:handle_first_presence(origin, stanza); | 473 return room:handle_first_presence(origin, stanza); |
474 elseif stanza.attr.type ~= "error" then | 474 elseif stanza.attr.type ~= "error" then |
475 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); | 475 origin.send(st.error_reply(stanza, "cancel", "item-not-found", nil, module.host)); |
476 return true; | 476 return true; |
477 else | 477 else |
478 return; | 478 return; |
479 end | 479 end |
480 elseif room == false then -- Error loading room | 480 elseif room == false then -- Error loading room |
481 origin.send(st.error_reply(stanza, "wait", "resource-constraint")); | 481 origin.send(st.error_reply(stanza, "wait", "resource-constraint", nil, module.host)); |
482 return true; | 482 return true; |
483 end | 483 end |
484 return room[method](room, origin, stanza); | 484 return room[method](room, origin, stanza); |
485 end, -2) | 485 end, -2) |
486 end | 486 end |