Comparison

plugins/mod_component.lua @ 11868:ae093c259da2

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.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Oct 2021 15:17:01 +0200
parent 11560:3bbb1af92514
child 12686:5f182bccf33f
comparison
equal deleted inserted replaced
11867:bb20cfd4884f 11868:ae093c259da2
263 end 263 end
264 if reason then 264 if reason then
265 if type(reason) == "string" then -- assume stream error 265 if type(reason) == "string" then -- assume stream error
266 module:log("info", "Disconnecting component, <stream:error> is: %s", reason); 266 module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
267 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); 267 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
268 elseif st.is_stanza(reason) then
269 module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
270 session.send(reason);
268 elseif type(reason) == "table" then 271 elseif type(reason) == "table" then
269 if reason.condition then 272 if reason.condition then
270 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up(); 273 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
271 if reason.text then 274 if reason.text then
272 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); 275 stanza:tag("text", stream_xmlns_attr):text(reason.text):up();
274 if reason.extra then 277 if reason.extra then
275 stanza:add_child(reason.extra); 278 stanza:add_child(reason.extra);
276 end 279 end
277 module:log("info", "Disconnecting component, <stream:error> is: %s", stanza); 280 module:log("info", "Disconnecting component, <stream:error> is: %s", stanza);
278 session.send(stanza); 281 session.send(stanza);
279 elseif reason.name then -- a stanza
280 module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
281 session.send(reason);
282 end 282 end
283 end 283 end
284 end 284 end
285 session.send("</stream:stream>"); 285 session.send("</stream:stream>");
286 session.conn:close(); 286 session.conn:close();