aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-05-08 23:58:24 +0200
committerKim Alvefur <zash@zash.se>2020-05-08 23:58:24 +0200
commit0747cbea53bce8930724c4d7de735c07e36e6893 (patch)
treeb923536d6b8a23dc2ae5ff6db182b0abe4fcc44f /plugins
parenta7c0def27f214441fe4881e119194540d291fd75 (diff)
downloadprosody-0747cbea53bce8930724c4d7de735c07e36e6893.tar.gz
prosody-0747cbea53bce8930724c4d7de735c07e36e6893.zip
mod_c2s: Run stream open and close events in async thread, fixes #1103
Enables async processing during stream opening and closing.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_c2s.lua20
1 files changed, 18 insertions, 2 deletions
diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua
index 536b945e..91e37c4a 100644
--- a/plugins/mod_c2s.lua
+++ b/plugins/mod_c2s.lua
@@ -55,6 +55,11 @@ end);
local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
function stream_callbacks.streamopened(session, attr)
+ -- run _streamopened in async context
+ session.thread:run({ stream = "opened", attr = attr });
+end
+
+function stream_callbacks._streamopened(session, attr)
local send = session.send;
if not attr.to then
session:close{ condition = "improper-addressing",
@@ -121,7 +126,12 @@ function stream_callbacks.streamopened(session, attr)
end
end
-function stream_callbacks.streamclosed(session)
+function stream_callbacks.streamclosed(session, attr)
+ -- run _streamclosed in async context
+ session.thread:run({ stream = "closed", attr = attr });
+end
+
+function stream_callbacks._streamclosed(session)
session.log("debug", "Received </stream:stream>");
session:close(false);
end
@@ -280,7 +290,13 @@ function listener.onconnect(conn)
end
session.thread = runner(function (stanza)
- core_process_stanza(session, stanza);
+ if st.is_stanza(stanza) then
+ core_process_stanza(session, stanza);
+ elseif stanza.stream == "opened" then
+ stream_callbacks._streamopened(session, stanza.attr);
+ elseif stanza.stream == "closed" then
+ stream_callbacks._streamclosed(session, stanza.attr);
+ end
end, runner_callbacks, session);
local filter = session.filter;