core/sessionmanager.lua
changeset 9912 7d12af856238
parent 9073 21730a3642fe
child 9941 6245ee9494c6
equal deleted inserted replaced
9911:54e36a8677bc 9912:7d12af856238
    30 
    30 
    31 local function new_session(conn)
    31 local function new_session(conn)
    32 	local session = { conn = conn, type = "c2s_unauthed", conntime = gettime() };
    32 	local session = { conn = conn, type = "c2s_unauthed", conntime = gettime() };
    33 	local filter = initialize_filters(session);
    33 	local filter = initialize_filters(session);
    34 	local w = conn.write;
    34 	local w = conn.write;
       
    35 
       
    36 	function session.rawsend(t)
       
    37 		t = filter("bytes/out", tostring(t));
       
    38 		if t then
       
    39 			local ret, err = w(conn, t);
       
    40 			if not ret then
       
    41 				session.log("debug", "Error writing to connection: %s", tostring(err));
       
    42 				return false, err;
       
    43 			end
       
    44 		end
       
    45 		return true;
       
    46 	end
       
    47 
    35 	session.send = function (t)
    48 	session.send = function (t)
    36 		session.log("debug", "Sending[%s]: %s", session.type, t.top_tag and t:top_tag() or t:match("^[^>]*>?"));
    49 		session.log("debug", "Sending[%s]: %s", session.type, t.top_tag and t:top_tag() or t:match("^[^>]*>?"));
    37 		if t.name then
    50 		if t.name then
    38 			t = filter("stanzas/out", t);
    51 			t = filter("stanzas/out", t);
    39 		end
    52 		end
    40 		if t then
    53 		if t then
    41 			t = filter("bytes/out", tostring(t));
    54 			return session.rawsend(t);
    42 			if t then
       
    43 				local ret, err = w(conn, t);
       
    44 				if not ret then
       
    45 					session.log("debug", "Error writing to connection: %s", tostring(err));
       
    46 					return false, err;
       
    47 				end
       
    48 			end
       
    49 		end
    55 		end
    50 		return true;
    56 		return true;
    51 	end
    57 	end
    52 	session.ip = conn:ip();
    58 	session.ip = conn:ip();
    53 	local conn_name = "c2s"..tostring(session):match("[a-f0-9]+$");
    59 	local conn_name = "c2s"..tostring(session):match("[a-f0-9]+$");