Software /
code /
prosody
Comparison
plugins/mod_c2s.lua @ 12071:85c8fcb4192e
mod_c2s: Fire pre-closing event regardless of connected state
With mod_smacks, a session can outlive the connection, so whether the
event is fired should not hinge on whether the session is connected or
not.
Helps mod_smacks remove some state.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 18 Dec 2021 13:43:57 +0100 |
parent | 11974:a7c183bb4e64 |
child | 12298:cb459f8fa740 |
comparison
equal
deleted
inserted
replaced
12070:e662c172ea0f | 12071:85c8fcb4192e |
---|---|
184 end | 184 end |
185 | 185 |
186 --- Session methods | 186 --- Session methods |
187 local function session_close(session, reason) | 187 local function session_close(session, reason) |
188 local log = session.log or log; | 188 local log = session.log or log; |
189 local close_event_payload = { session = session, reason = reason }; | |
190 module:context(session.host):fire_event("pre-session-close", close_event_payload); | |
191 reason = close_event_payload.reason; | |
189 if session.conn then | 192 if session.conn then |
190 if session.notopen then | 193 if session.notopen then |
191 session:open_stream(); | 194 session:open_stream(); |
192 end | 195 end |
193 local close_event_payload = { session = session, reason = reason }; | |
194 module:context(session.host):fire_event("pre-session-close", close_event_payload); | |
195 reason = close_event_payload.reason; | |
196 if reason then -- nil == no err, initiated by us, false == initiated by client | 196 if reason then -- nil == no err, initiated by us, false == initiated by client |
197 local stream_error = st.stanza("stream:error"); | 197 local stream_error = st.stanza("stream:error"); |
198 if type(reason) == "string" then -- assume stream error | 198 if type(reason) == "string" then -- assume stream error |
199 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); | 199 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
200 elseif st.is_stanza(reason) then | 200 elseif st.is_stanza(reason) then |