mod_c2s,etc: Identify stanza object with appropriate function
Better than duck typing, in case anyone ever passes a non-stanza table
with a 'name' field.
--- a/plugins/mod_bosh.lua Sun Oct 24 15:11:01 2021 +0200
+++ b/plugins/mod_bosh.lua Sun Oct 24 15:17:01 2021 +0200
@@ -236,6 +236,8 @@
if type(reason) == "string" then -- assume stream error
close_reply:tag("stream:error")
:tag(reason, {xmlns = xmlns_xmpp_streams});
+ elseif st.is_stanza(reason) then
+ close_reply = reason;
elseif type(reason) == "table" then
if reason.condition then
close_reply:tag("stream:error")
@@ -246,8 +248,6 @@
if reason.extra then
close_reply:add_child(reason.extra);
end
- elseif reason.name then -- a stanza
- close_reply = reason;
end
end
log("info", "Disconnecting client, <stream:error> is: %s", close_reply);
--- a/plugins/mod_c2s.lua Sun Oct 24 15:11:01 2021 +0200
+++ b/plugins/mod_c2s.lua Sun Oct 24 15:17:01 2021 +0200
@@ -194,6 +194,8 @@
local stream_error = st.stanza("stream:error");
if type(reason) == "string" then -- assume stream error
stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' });
+ elseif st.is_stanza(reason) then
+ stream_error = reason;
elseif type(reason) == "table" then
if reason.condition then
stream_error:tag(reason.condition, stream_xmlns_attr):up();
@@ -203,8 +205,6 @@
if reason.extra then
stream_error:add_child(reason.extra);
end
- elseif reason.name then -- a stanza
- stream_error = reason;
end
end
stream_error = tostring(stream_error);
--- a/plugins/mod_component.lua Sun Oct 24 15:11:01 2021 +0200
+++ b/plugins/mod_component.lua Sun Oct 24 15:17:01 2021 +0200
@@ -265,6 +265,9 @@
if type(reason) == "string" then -- assume stream error
module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
+ elseif st.is_stanza(reason) then
+ module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
+ session.send(reason);
elseif type(reason) == "table" then
if reason.condition then
local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
@@ -276,9 +279,6 @@
end
module:log("info", "Disconnecting component, <stream:error> is: %s", stanza);
session.send(stanza);
- elseif reason.name then -- a stanza
- module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
- session.send(reason);
end
end
end
--- a/plugins/mod_websocket.lua Sun Oct 24 15:11:01 2021 +0200
+++ b/plugins/mod_websocket.lua Sun Oct 24 15:17:01 2021 +0200
@@ -71,6 +71,8 @@
local stream_error = st.stanza("stream:error");
if type(reason) == "string" then -- assume stream error
stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' });
+ elseif st.is_stanza(reason) then
+ stream_error = reason;
elseif type(reason) == "table" then
if reason.condition then
stream_error:tag(reason.condition, stream_xmlns_attr):up();
@@ -80,8 +82,6 @@
if reason.extra then
stream_error:add_child(reason.extra);
end
- elseif reason.name then -- a stanza
- stream_error = reason;
end
end
log("debug", "Disconnecting client, <stream:error> is: %s", stream_error);