Comparison

mod_rest/mod_rest.lua @ 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
parent 4249:64aa1d9d70ac
child 4477:8df6cc648963
comparison
equal deleted inserted replaced
4249:64aa1d9d70ac 4250:8b489203e4d3
295 295
296 local code2err = require "net.http.errors".registry; 296 local code2err = require "net.http.errors".registry;
297 297
298 local function handle_stanza(event) 298 local function handle_stanza(event)
299 local stanza, origin = event.stanza, event.origin; 299 local stanza, origin = event.stanza, event.origin;
300 local reply_needed = stanza.name == "iq"; 300 local reply_allowed = stanza.attr.type ~= "error";
301 local reply_needed = reply_allowed and stanza.name == "iq";
301 local receipt; 302 local receipt;
302 303
303 if stanza.attr.type == "error" then 304 if reply_allowed and stanza.name == "message" and stanza.attr.id and stanza:get_child("urn:xmpp:receipts", "request") then
304 reply_needed = false;
305 end
306
307 if stanza.name == "message" and stanza.attr.id and stanza:get_child("urn:xmpp:receipts", "request") then
308 reply_needed = true; 305 reply_needed = true;
309 receipt = st.stanza("received", { xmlns = "urn:xmpp:receipts", id = stanza.id }); 306 receipt = st.stanza("received", { xmlns = "urn:xmpp:receipts", id = stanza.id });
310 end 307 end
311 308
312 local request_body = encode(send_type, stanza); 309 local request_body = encode(send_type, stanza);
325 }):next(function (response) 322 }):next(function (response)
326 module:set_status("info", "Connected"); 323 module:set_status("info", "Connected");
327 local reply; 324 local reply;
328 325
329 local code, body = response.code, response.body; 326 local code, body = response.code, response.body;
330 if code == 202 or code == 204 then 327 if not reply_allowed then
328 return;
329 elseif code == 202 or code == 204 then
331 if not reply_needed then 330 if not reply_needed then
332 -- Delivered, no reply 331 -- Delivered, no reply
333 return; 332 return;
334 end 333 end
335 else 334 else