aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-09-26 17:30:47 +0200
committerKim Alvefur <zash@zash.se>2020-09-26 17:30:47 +0200
commit3f9988468d11d6e3b94fec0ec1ed4271712bed14 (patch)
tree8ce8d230407f3e6ea9bdb3896fba6e539779c643
parent2f0b85ce29a6b4eaa210a60a5d04610f0401379d (diff)
downloadprosody-3f9988468d11d6e3b94fec0ec1ed4271712bed14.tar.gz
prosody-3f9988468d11d6e3b94fec0ec1ed4271712bed14.zip
util.stanza: Support inclusion of <gone> URI from util.error object
-rw-r--r--spec/util_stanza_spec.lua5
-rw-r--r--util/stanza.lua10
2 files changed, 13 insertions, 2 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index ec392611..c4c1d174 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -247,6 +247,11 @@ describe("util.stanza", function()
assert.are.equal(r.tags[1].tags[1].name, e.condition);
assert.are.equal(r.tags[1].tags[2]:get_text(), e.text);
assert.are.equal("this.test", r.tags[1].attr.by);
+
+ local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } })
+ local gonner = st.error_reply(s, gone);
+ assert.are.equal("gone", gonner.tags[1].tags[1].name);
+ assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]);
end);
end);
diff --git a/util/stanza.lua b/util/stanza.lua
index 3c415f20..2c936a40 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -455,9 +455,11 @@ local function error_reply(orig, error_type, condition, error_message, error_by)
end
local t = reply(orig);
t.attr.type = "error";
+ local extra;
if type(error_type) == "table" then -- an util.error or similar object
if type(error_type.extra) == "table" then
- if type(error_type.extra.by) == "string" then error_by = error_type.extra.by; end
+ extra = error_type.extra;
+ if type(extra.by) == "string" then error_by = extra.by; end
end
error_type, condition, error_message = error_type.type, error_type.condition, error_type.text;
end
@@ -465,7 +467,11 @@ local function error_reply(orig, error_type, condition, error_message, error_by)
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();
+ :tag(condition, xmpp_stanzas_attr);
+ if extra and condition == "gone" and type(extra.uri) == "string" then
+ t:text(extra.uri);
+ end
+ t:up();
if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end
return t; -- stanza ready for adding app-specific errors
end