changeset 4250:8b489203e4d3

mod_rest: Ensure no attempt is made to reply to an error stanza Previously it was possible to return an error reply from a callback.
author Kim Alvefur <zash@zash.se>
date Sun, 15 Nov 2020 16:29:48 +0100
parents 64aa1d9d70ac
children d33b480befcb
files mod_rest/mod_rest.lua
diffstat 1 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Sun Nov 15 16:25:49 2020 +0100
+++ b/mod_rest/mod_rest.lua	Sun Nov 15 16:29:48 2020 +0100
@@ -297,14 +297,11 @@
 
 	local function handle_stanza(event)
 		local stanza, origin = event.stanza, event.origin;
-		local reply_needed = stanza.name == "iq";
+		local reply_allowed = stanza.attr.type ~= "error";
+		local reply_needed = reply_allowed and stanza.name == "iq";
 		local receipt;
 
-		if stanza.attr.type == "error" then
-			reply_needed = false;
-		end
-
-		if stanza.name == "message" and stanza.attr.id and stanza:get_child("urn:xmpp:receipts", "request") then
+		if reply_allowed and stanza.name == "message" and stanza.attr.id and stanza:get_child("urn:xmpp:receipts", "request") then
 			reply_needed = true;
 			receipt = st.stanza("received", { xmlns = "urn:xmpp:receipts", id = stanza.id });
 		end
@@ -327,7 +324,9 @@
 				local reply;
 
 				local code, body = response.code, response.body;
-				if code == 202 or code == 204 then
+				if not reply_allowed then
+					return;
+				elseif code == 202 or code == 204 then
 					if not reply_needed then
 						-- Delivered, no reply
 						return;