Fix error handling for non-existent MUCs

This commit is contained in:
Bohdan Horbeshko 2025-06-24 11:18:44 -04:00
parent 32b00c244c
commit 93dcc32480

View file

@ -591,7 +591,7 @@ func handleMUCPresence(s xmpp.Sender, p stanza.Presence, mucExt stanza.MucPresen
chat, _, err := session.GetContactByID(chatId, nil) chat, _, err := session.GetContactByID(chatId, nil)
if err != nil || !session.IsGroup(chat) { if err != nil || !session.IsGroup(chat) {
presenceReplySetError(reply, 405) presenceReplySetError(reply, 404)
return return
} }
@ -913,6 +913,7 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ, di *stanza.DiscoInfo) {
defer gateway.ResumableSend(component, answer) defer gateway.ResumableSend(component, answer)
disco := answer.DiscoInfo() disco := answer.DiscoInfo()
answer.Payload = disco
toID, toOk, toIsGroup := toToID(iq.To) toID, toOk, toIsGroup := toToID(iq.To)
if di.Node == "" { if di.Node == "" {
@ -969,7 +970,12 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ, di *stanza.DiscoInfo) {
} }
if toOk { if toOk {
if toIsGroup {
if !isMuc { if !isMuc {
iqAnswerSetError(answer, 404)
return
}
} else {
disco.AddIdentity("", "account", "registered") disco.AddIdentity("", "account", "registered")
} }
disco.AddFeatures(stanza.NSMsgChatMarkers) disco.AddFeatures(stanza.NSMsgChatMarkers)
@ -1014,7 +1020,6 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ, di *stanza.DiscoInfo) {
} }
} }
} }
answer.Payload = disco
} }
func handleGetDiscoItems(s xmpp.Sender, iq *stanza.IQ, di *stanza.DiscoItems) { func handleGetDiscoItems(s xmpp.Sender, iq *stanza.IQ, di *stanza.DiscoItems) {
@ -2045,12 +2050,15 @@ func presenceReplySetError(reply *stanza.Presence, code int) {
case 400: case 400:
reply.Error.Type = stanza.ErrorTypeModify reply.Error.Type = stanza.ErrorTypeModify
reply.Error.Reason = "jid-malformed" reply.Error.Reason = "jid-malformed"
case 407: case 404:
reply.Error.Type = stanza.ErrorTypeAuth reply.Error.Type = stanza.ErrorTypeCancel
reply.Error.Reason = "registration-required" reply.Error.Reason = "item-not-found"
case 405: case 405:
reply.Error.Type = stanza.ErrorTypeCancel reply.Error.Type = stanza.ErrorTypeCancel
reply.Error.Reason = "not-allowed" reply.Error.Reason = "not-allowed"
case 407:
reply.Error.Type = stanza.ErrorTypeAuth
reply.Error.Reason = "registration-required"
default: default:
log.Error("Unknown error code, falling back with empty reason") log.Error("Unknown error code, falling back with empty reason")
reply.Error.Type = stanza.ErrorTypeCancel reply.Error.Type = stanza.ErrorTypeCancel