Software /
code /
prosody
Changeset
6005:98b768a41c9d
mod_c2s: Break out stream opening into a separate function
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 31 Jan 2014 12:01:12 +0100 |
parents | 6004:09151d26560a |
children | 6007:ff24bc2d41a6 |
files | plugins/mod_c2s.lua |
diffstat | 1 files changed, 16 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_c2s.lua Tue Jan 28 19:21:21 2014 +0100 +++ b/plugins/mod_c2s.lua Fri Jan 31 12:01:12 2014 +0100 @@ -38,7 +38,6 @@ --- 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 @@ 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 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 @@ 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 @@ conn:setoption("keepalive", opt_keepalives); end + session.open_stream = session_open_stream; session.close = session_close; local stream = new_xmpp_stream(session, stream_callbacks);