aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-12-15 03:33:00 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-12-15 03:33:00 +0500
commit812627cb6091797db365dc0459109cf7f8c45057 (patch)
tree21362cd705d6bfb510c796ec6aa5eab8cd7113fa
parent72d46a321bb9fa08e736fca71a1065985687d08d (diff)
downloadprosody-812627cb6091797db365dc0459109cf7f8c45057.tar.gz
prosody-812627cb6091797db365dc0459109cf7f8c45057.zip
net.xmppcomponent_listener: Move session creation from listener.onincoming to listener.onconnect.
-rw-r--r--net/xmppcomponent_listener.lua68
1 files changed, 32 insertions, 36 deletions
diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua
index 94716037..90293559 100644
--- a/net/xmppcomponent_listener.lua
+++ b/net/xmppcomponent_listener.lua
@@ -165,46 +165,42 @@ local function session_close(session, reason)
end
--- Component connlistener
-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 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;
- 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;
-
+ 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
- if data then
- session.data(conn, data);
+
+ 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
-end
+ session.dispatch_stanza = stream_callbacks.handlestanza;
+
+ sessions[conn] = session;
+end
+function component_listener.onincoming(conn, data)
+ local session = sessions[conn];
+ session.data(conn, data);
+end
function component_listener.ondisconnect(conn, err)
local session = sessions[conn];
if session then