Comparison

plugins/mod_websocket.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 11771:4c0802b52673
child 12263:168970ce8543
comparison
equal deleted inserted replaced
11867:bb20cfd4884f 11868:ae093c259da2
69 end 69 end
70 if reason then -- nil == no err, initiated by us, false == initiated by client 70 if reason then -- nil == no err, initiated by us, false == initiated by client
71 local stream_error = st.stanza("stream:error"); 71 local stream_error = st.stanza("stream:error");
72 if type(reason) == "string" then -- assume stream error 72 if type(reason) == "string" then -- assume stream error
73 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); 73 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' });
74 elseif st.is_stanza(reason) then
75 stream_error = reason;
74 elseif type(reason) == "table" then 76 elseif type(reason) == "table" then
75 if reason.condition then 77 if reason.condition then
76 stream_error:tag(reason.condition, stream_xmlns_attr):up(); 78 stream_error:tag(reason.condition, stream_xmlns_attr):up();
77 if reason.text then 79 if reason.text then
78 stream_error:tag("text", stream_xmlns_attr):text(reason.text):up(); 80 stream_error:tag("text", stream_xmlns_attr):text(reason.text):up();
79 end 81 end
80 if reason.extra then 82 if reason.extra then
81 stream_error:add_child(reason.extra); 83 stream_error:add_child(reason.extra);
82 end 84 end
83 elseif reason.name then -- a stanza
84 stream_error = reason;
85 end 85 end
86 end 86 end
87 log("debug", "Disconnecting client, <stream:error> is: %s", stream_error); 87 log("debug", "Disconnecting client, <stream:error> is: %s", stream_error);
88 session.send(stream_error); 88 session.send(stream_error);
89 end 89 end