Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 10449:2e36a54906e4
MUC: Indicate that the room is the origin of various errors where 'from' is an occupant JID
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 25 Nov 2019 23:52:45 +0100 |
parent | 10434:8f709577fe8e |
child | 10451:347d16d70280 |
comparison
equal
deleted
inserted
replaced
10448:cbe524ed1a6a | 10449:2e36a54906e4 |
---|---|
420 -- check if user is banned | 420 -- check if user is banned |
421 module:hook("muc-occupant-pre-join", function(event) | 421 module:hook("muc-occupant-pre-join", function(event) |
422 local room, stanza = event.room, event.stanza; | 422 local room, stanza = event.room, event.stanza; |
423 local affiliation = room:get_affiliation(stanza.attr.from); | 423 local affiliation = room:get_affiliation(stanza.attr.from); |
424 if affiliation == "outcast" then | 424 if affiliation == "outcast" then |
425 local reply = st.error_reply(stanza, "auth", "forbidden"):up(); | 425 local reply = st.error_reply(stanza, "auth", "forbidden", nil, room.jid):up(); |
426 reply.tags[1].attr.code = "403"; | 426 reply.tags[1].attr.code = "403"; |
427 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); | 427 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
428 return true; | 428 return true; |
429 end | 429 end |
430 end, -10); | 430 end, -10); |
431 | 431 |
432 module:hook("muc-occupant-pre-join", function(event) | 432 module:hook("muc-occupant-pre-join", function(event) |
433 local room = event.room; | |
433 local nick = jid_resource(event.occupant.nick); | 434 local nick = jid_resource(event.occupant.nick); |
434 if not nick:find("%S") then | 435 if not nick:find("%S") then |
435 event.origin.send(st.error_reply(event.stanza, "modify", "not-allowed", "Invisible Nicknames are forbidden")); | 436 event.origin.send(st.error_reply(event.stanza, "modify", "not-allowed", "Invisible Nicknames are forbidden", room.jid)); |
436 return true; | 437 return true; |
437 end | 438 end |
438 end, 1); | 439 end, 1); |
439 | 440 |
440 module:hook("muc-occupant-pre-change", function(event) | 441 module:hook("muc-occupant-pre-change", function(event) |
442 local room = event.room; | |
441 if not jid_resource(event.dest_occupant.nick):find("%S") then | 443 if not jid_resource(event.dest_occupant.nick):find("%S") then |
442 event.origin.send(st.error_reply(event.stanza, "modify", "not-allowed", "Invisible Nicknames are forbidden")); | 444 event.origin.send(st.error_reply(event.stanza, "modify", "not-allowed", "Invisible Nicknames are forbidden", room.jid)); |
443 return true; | 445 return true; |
444 end | 446 end |
445 end, 1); | 447 end, 1); |
446 | 448 |
447 module:hook("muc-occupant-pre-join", function(event) | 449 module:hook("muc-occupant-pre-join", function(event) |
450 local room = event.room; | |
448 local nick = jid_resource(event.occupant.nick); | 451 local nick = jid_resource(event.occupant.nick); |
449 if not resourceprep(nick, true) then -- strict | 452 if not resourceprep(nick, true) then -- strict |
450 event.origin.send(st.error_reply(event.stanza, "modify", "jid-malformed", "Nickname must pass strict validation")); | 453 event.origin.send(st.error_reply(event.stanza, "modify", "jid-malformed", "Nickname must pass strict validation", room.jid)); |
451 return true; | 454 return true; |
452 end | 455 end |
453 end, 2); | 456 end, 2); |
454 | 457 |
455 module:hook("muc-occupant-pre-change", function(event) | 458 module:hook("muc-occupant-pre-change", function(event) |
456 local nick = jid_resource(event.dest_occupant.nick); | 459 local nick = jid_resource(event.dest_occupant.nick); |
457 if not resourceprep(nick, true) then -- strict | 460 if not resourceprep(nick, true) then -- strict |
458 event.origin.send(st.error_reply(event.stanza, "modify", "jid-malformed", "Nickname must pass strict validation")); | 461 event.origin.send(st.error_reply(event.stanza, "modify", "jid-malformed", "Nickname must pass strict validation", room.jid)); |
459 return true; | 462 return true; |
460 end | 463 end |
461 end, 2); | 464 end, 2); |
462 | 465 |
463 function room_mt:handle_first_presence(origin, stanza) | 466 function room_mt:handle_first_presence(origin, stanza) |
528 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc"); | 531 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
529 | 532 |
530 if orig_occupant == nil and not muc_x and stanza.attr.type == nil then | 533 if orig_occupant == nil and not muc_x and stanza.attr.type == nil then |
531 module:log("debug", "Attempted join without <x>, possibly desynced"); | 534 module:log("debug", "Attempted join without <x>, possibly desynced"); |
532 origin.send(st.error_reply(stanza, "cancel", "item-not-found", | 535 origin.send(st.error_reply(stanza, "cancel", "item-not-found", |
533 "You are not currently connected to this chat")); | 536 "You are not currently connected to this chat", self.jid)); |
534 return true; | 537 return true; |
535 end | 538 end |
536 | 539 |
537 local is_first_dest_session; | 540 local is_first_dest_session; |
538 local dest_occupant; | 541 local dest_occupant; |
590 -- Check for nick conflicts | 593 -- Check for nick conflicts |
591 if dest_occupant ~= nil and not is_first_dest_session | 594 if dest_occupant ~= nil and not is_first_dest_session |
592 and bare_jid ~= jid_bare(dest_occupant.bare_jid) then | 595 and bare_jid ~= jid_bare(dest_occupant.bare_jid) then |
593 -- new nick or has different bare real jid | 596 -- new nick or has different bare real jid |
594 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); | 597 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); |
595 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); | 598 local reply = st.error_reply(stanza, "cancel", "conflict", nil, self.jid):up(); |
596 reply.tags[1].attr.code = "409"; | 599 reply.tags[1].attr.code = "409"; |
597 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); | 600 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
598 return true; | 601 return true; |
599 end | 602 end |
600 | 603 |
719 return self:handle_kickable(origin, stanza) | 722 return self:handle_kickable(origin, stanza) |
720 elseif type == nil or type == "unavailable" then | 723 elseif type == nil or type == "unavailable" then |
721 return self:handle_normal_presence(origin, stanza); | 724 return self:handle_normal_presence(origin, stanza); |
722 elseif type ~= 'result' then -- bad type | 725 elseif type ~= 'result' then -- bad type |
723 if type ~= 'visible' and type ~= 'invisible' then -- COMPAT ejabberd can broadcast or forward XEP-0018 presences | 726 if type ~= 'visible' and type ~= 'invisible' then -- COMPAT ejabberd can broadcast or forward XEP-0018 presences |
724 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? | 727 origin.send(st.error_reply(stanza, "modify", "bad-request", nil, self.jid)); -- FIXME correct error? |
725 end | 728 end |
726 end | 729 end |
727 return true; | 730 return true; |
728 end | 731 end |
729 | 732 |
754 stanza.attr.from, stanza.attr.to, stanza.attr.id = from, to, id; | 757 stanza.attr.from, stanza.attr.to, stanza.attr.id = from, to, id; |
755 return true; | 758 return true; |
756 else -- Type is "get" or "set" | 759 else -- Type is "get" or "set" |
757 local current_nick = self:get_occupant_jid(from); | 760 local current_nick = self:get_occupant_jid(from); |
758 if not current_nick then | 761 if not current_nick then |
759 origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat")); | 762 origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat", self.jid)); |
760 return true; | 763 return true; |
761 end | 764 end |
762 if not occupant then -- recipient not in room | 765 if not occupant then -- recipient not in room |
763 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); | 766 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room", self.jid)); |
764 return true; | 767 return true; |
765 end | 768 end |
766 -- XEP-0410 MUC Self-Ping #1220 | 769 -- XEP-0410 MUC Self-Ping #1220 |
767 if to == current_nick and stanza.attr.type == "get" and stanza:get_child("ping", "urn:xmpp:ping") then | 770 if to == current_nick and stanza.attr.type == "get" and stanza:get_child("ping", "urn:xmpp:ping") then |
768 self:route_stanza(st.reply(stanza)); | 771 self:route_stanza(st.reply(stanza)); |
787 local from, to = stanza.attr.from, stanza.attr.to; | 790 local from, to = stanza.attr.from, stanza.attr.to; |
788 local current_nick = self:get_occupant_jid(from); | 791 local current_nick = self:get_occupant_jid(from); |
789 local type = stanza.attr.type; | 792 local type = stanza.attr.type; |
790 if not current_nick then -- not in room | 793 if not current_nick then -- not in room |
791 if type ~= "error" then | 794 if type ~= "error" then |
792 origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat")); | 795 origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat", self.jid)); |
793 end | 796 end |
794 return true; | 797 return true; |
795 end | 798 end |
796 if type == "groupchat" then -- groupchat messages not allowed in PM | 799 if type == "groupchat" then -- groupchat messages not allowed in PM |
797 origin.send(st.error_reply(stanza, "modify", "bad-request")); | 800 origin.send(st.error_reply(stanza, "modify", "bad-request", nil, self.jid)); |
798 return true; | 801 return true; |
799 elseif type == "error" and is_kickable_error(stanza) then | 802 elseif type == "error" and is_kickable_error(stanza) then |
800 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); | 803 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
801 return self:handle_kickable(origin, stanza); -- send unavailable | 804 return self:handle_kickable(origin, stanza); -- send unavailable |
802 end | 805 end |
803 | 806 |
804 local o_data = self:get_occupant_by_nick(to); | 807 local o_data = self:get_occupant_by_nick(to); |
805 if not o_data then | 808 if not o_data then |
806 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); | 809 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room", self.jid)); |
807 return true; | 810 return true; |
808 end | 811 end |
809 log("debug", "%s sent private message stanza to %s (%s)", from, to, o_data.jid); | 812 log("debug", "%s sent private message stanza to %s (%s)", from, to, o_data.jid); |
810 stanza = muc_util.filter_muc_x(st.clone(stanza)); | 813 stanza = muc_util.filter_muc_x(st.clone(stanza)); |
811 stanza:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }):up(); | 814 stanza:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }):up(); |