aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_c2s.lua
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2014-01-31 12:01:12 +0100
committerFlorian Zeitz <florob@babelmonkeys.de>2014-01-31 12:01:12 +0100
commitc5c7ef5b0f47d1e51117f756420176f1f0a2466d (patch)
tree1caf89f1cb2eafce0b32f95d08c6119d256b2fa9 /plugins/mod_c2s.lua
parente5faa1bfa21a99addfa92f637af6d8cf32144b34 (diff)
downloadprosody-c5c7ef5b0f47d1e51117f756420176f1f0a2466d.tar.gz
prosody-c5c7ef5b0f47d1e51117f756420176f1f0a2466d.zip
mod_c2s: Break out stream opening into a separate function
Diffstat (limited to 'plugins/mod_c2s.lua')
-rw-r--r--plugins/mod_c2s.lua22
1 files changed, 16 insertions, 6 deletions
diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua
index 3bdffc7d..7a8af406 100644
--- a/plugins/mod_c2s.lua
+++ b/plugins/mod_c2s.lua
@@ -38,7 +38,6 @@ local runner_callbacks = {};
--- Stream events handlers
local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
-local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
function stream_callbacks.streamopened(session, attr)
local send = session.send;
@@ -58,9 +57,7 @@ function stream_callbacks.streamopened(session, attr)
return;
end
- send("<?xml version='1.0'?>"..st.stanza("stream:stream", {
- xmlns = 'jabber:client', ["xmlns:stream"] = 'http://etherx.jabber.org/streams';
- id = session.streamid, from = session.host, version = '1.0', ["xml:lang"] = 'en' }):top_tag());
+ session:open_stream();
(session.log or log)("debug", "Sent reply <stream:stream> to client");
session.notopen = nil;
@@ -129,8 +126,7 @@ local function session_close(session, reason)
local log = session.log or log;
if session.conn then
if session.notopen then
- session.send("<?xml version='1.0'?>");
- session.send(st.stanza("stream:stream", default_stream_attr):top_tag());
+ session:open_stream();
end
if reason then -- nil == no err, initiated by us, false == initiated by client
local stream_error = st.stanza("stream:error");
@@ -178,6 +174,19 @@ local function session_close(session, reason)
end
end
+local function session_open_stream(session)
+ local attr = {
+ ["xmlns:stream"] = 'http://etherx.jabber.org/streams',
+ xmlns = stream_callbacks.default_ns,
+ version = "1.0",
+ ["xml:lang"] = 'en',
+ id = session.streamid or "",
+ from = session.host
+ };
+ session.send("<?xml version='1.0'?>");
+ session.send(st.stanza("stream:stream", attr):top_tag());
+end
+
module:hook_global("user-deleted", function(event)
local username, host = event.username, event.host;
local user = hosts[host].sessions[username];
@@ -225,6 +234,7 @@ function listener.onconnect(conn)
conn:setoption("keepalive", opt_keepalives);
end
+ session.open_stream = session_open_stream;
session.close = session_close;
local stream = new_xmpp_stream(session, stream_callbacks);