Software /
code /
prosody
Comparison
util/stanza.lua @ 10446:5c2d1b13537c
util.stanza: Support the 'by' attribute on errors
This is to be used when the entity generating the error is not the same
as the one the stanza was directed to, e.g. an intermediate server.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 25 Nov 2019 20:59:36 +0100 |
parent | 10445:f53c03ab4357 |
child | 10503:e25a1a9a6e7e |
comparison
equal
deleted
inserted
replaced
10445:f53c03ab4357 | 10446:5c2d1b13537c |
---|---|
445 type = ((orig.name == "iq" and "result") or orig.attr.type) | 445 type = ((orig.name == "iq" and "result") or orig.attr.type) |
446 }); | 446 }); |
447 end | 447 end |
448 | 448 |
449 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; | 449 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; |
450 local function error_reply(orig, error_type, condition, error_message) | 450 local function error_reply(orig, error_type, condition, error_message, error_by) |
451 if not is_stanza(orig) then | 451 if not is_stanza(orig) then |
452 error("bad argument to error_reply: expected stanza, got "..type(orig)); | 452 error("bad argument to error_reply: expected stanza, got "..type(orig)); |
453 elseif orig.attr.type == "error" then | 453 elseif orig.attr.type == "error" then |
454 error("bad argument to error_reply: got stanza of type error which must not be replied to"); | 454 error("bad argument to error_reply: got stanza of type error which must not be replied to"); |
455 end | 455 end |
456 local t = reply(orig); | 456 local t = reply(orig); |
457 t.attr.type = "error"; | 457 t.attr.type = "error"; |
458 t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here | 458 if t.attr.from == error_by then |
459 error_by = nil; | |
460 end | |
461 t:tag("error", {type = error_type, by = error_by}) --COMPAT: Some day xmlns:stanzas goes here | |
459 :tag(condition, xmpp_stanzas_attr):up(); | 462 :tag(condition, xmpp_stanzas_attr):up(); |
460 if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end | 463 if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end |
461 return t; -- stanza ready for adding app-specific errors | 464 return t; -- stanza ready for adding app-specific errors |
462 end | 465 end |
463 | 466 |