diff options
author | Kim Alvefur <zash@zash.se> | 2019-11-25 20:59:36 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-11-25 20:59:36 +0100 |
commit | be23b274f685f5eac73b79231491f4f0141f1c1c (patch) | |
tree | ca8b34f24020ebd3c47343ec16153f79e727c036 | |
parent | 54da2ab6f7fec145d05ac8682c50a776bb993880 (diff) | |
download | prosody-be23b274f685f5eac73b79231491f4f0141f1c1c.tar.gz prosody-be23b274f685f5eac73b79231491f4f0141f1c1c.zip |
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.
-rw-r--r-- | spec/util_stanza_spec.lua | 3 | ||||
-rw-r--r-- | util/stanza.lua | 7 |
2 files changed, 7 insertions, 3 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 04458303..b754f59d 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -191,13 +191,14 @@ describe("util.stanza", function() local s = st.stanza("s", { to = "touser", from = "fromuser", id = "123" }) :tag("child1"); -- Make reply stanza - local r = st.error_reply(s, "cancel", "service-unavailable"); + local r = st.error_reply(s, "cancel", "service-unavailable", nil, "host"); assert.are.equal(r.name, s.name); assert.are.equal(r.id, s.id); assert.are.equal(r.attr.to, s.attr.from); assert.are.equal(r.attr.from, s.attr.to); assert.are.equal(#r.tags, 1); assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); + assert.are.equal(r.tags[1].attr.by, "host"); end); it("should work for <iq get>", function() diff --git a/util/stanza.lua b/util/stanza.lua index 8ff1aae3..8e46f90f 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -447,7 +447,7 @@ local function reply(orig) end local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; -local function error_reply(orig, error_type, condition, error_message) +local function error_reply(orig, error_type, condition, error_message, error_by) if not is_stanza(orig) then error("bad argument to error_reply: expected stanza, got "..type(orig)); elseif orig.attr.type == "error" then @@ -455,7 +455,10 @@ local function error_reply(orig, error_type, condition, error_message) end local t = reply(orig); t.attr.type = "error"; - t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here + if t.attr.from == error_by then + error_by = nil; + end + t:tag("error", {type = error_type, by = error_by}) --COMPAT: Some day xmlns:stanzas goes here :tag(condition, xmpp_stanzas_attr):up(); if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end return t; -- stanza ready for adding app-specific errors |