# HG changeset patch # User Waqas Hussain # Date 1292365980 -18000 # Node ID c34a58c3ea4388ae27800b471735e4bb295d3175 # Parent 46edbc8339b10fde90708f8f1737d1498234c7a5 net.xmppcomponent_listener: Move session creation from listener.onincoming to listener.onconnect. diff -r 46edbc8339b1 -r c34a58c3ea43 net/xmppcomponent_listener.lua --- a/net/xmppcomponent_listener.lua Wed Dec 15 03:14:15 2010 +0500 +++ b/net/xmppcomponent_listener.lua Wed Dec 15 03:33:00 2010 +0500 @@ -165,46 +165,42 @@ end --- Component connlistener +function component_listener.onconnect(conn) + local _send = conn.write; + local session = { type = "component", conn = conn, send = function (data) return _send(conn, tostring(data)); end }; + + -- Logging functions -- + local conn_name = "jcp"..tostring(conn):match("[a-f0-9]+$"); + session.log = logger.init(conn_name); + session.close = session_close; + + session.log("info", "Incoming Jabber component connection"); + + local stream = new_xmpp_stream(session, stream_callbacks); + session.stream = stream; + + session.notopen = true; + + function session.reset_stream() + session.notopen = true; + session.stream:reset(); + end + + function session.data(conn, data) + local ok, err = stream:feed(data); + if ok then return; end + log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); + session:close("not-well-formed"); + end + + session.dispatch_stanza = stream_callbacks.handlestanza; + + sessions[conn] = session; +end function component_listener.onincoming(conn, data) local session = sessions[conn]; - if not session then - local _send = conn.write; - session = { type = "component", conn = conn, send = function (data) return _send(conn, tostring(data)); end }; - sessions[conn] = session; - - -- Logging functions -- - - local conn_name = "jcp"..tostring(conn):match("[a-f0-9]+$"); - session.log = logger.init(conn_name); - session.close = session_close; - - session.log("info", "Incoming Jabber component connection"); - - local stream = new_xmpp_stream(session, stream_callbacks); - session.stream = stream; - - session.notopen = true; - - function session.reset_stream() - session.notopen = true; - session.stream:reset(); - end - - function session.data(conn, data) - local ok, err = stream:feed(data); - if ok then return; end - log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); - session:close("not-well-formed"); - end - - session.dispatch_stanza = stream_callbacks.handlestanza; - - end - if data then - session.data(conn, data); - end + session.data(conn, data); end - function component_listener.ondisconnect(conn, err) local session = sessions[conn]; if session then