aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/adns.lua6
-rw-r--r--net/dns.lua10
-rw-r--r--net/httpserver.lua9
-rw-r--r--net/server.lua30
-rw-r--r--net/xmppclient_listener.lua8
-rw-r--r--net/xmppserver_listener.lua7
6 files changed, 39 insertions, 31 deletions
diff --git a/net/adns.lua b/net/adns.lua
index 34ef5d77..7ee54da3 100644
--- a/net/adns.lua
+++ b/net/adns.lua
@@ -50,6 +50,12 @@ function new_async_socket(sock)
function listener.disconnect()
end
newconn.handler, newconn._socket = server.wrapclient(sock, "dns", 53, listener);
+ if not newconn.handler then
+ log("warn", "handler is nil");
+ end
+ if not newconn._socket then
+ log("warn", "socket is nil");
+ end
newconn.handler.settimeout = function () end
newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end
newconn.handler.setpeername = function (_, ...) local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end
diff --git a/net/dns.lua b/net/dns.lua
index 48c08218..592471bb 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -17,6 +17,7 @@
require 'socket'
local ztact = require 'util.ztact'
local require = require
+local os = os;
local coroutine, io, math, socket, string, table =
coroutine, io, math, socket, string, table
@@ -509,9 +510,12 @@ function resolver:adddefaultnameservers () -- - - - - adddefaultnameservers
local address = string.match (line, 'nameserver%s+(%d+%.%d+%.%d+%.%d+)')
if address then self:addnameserver (address) end
end
- else -- FIXME correct for windows, using opendns nameservers for now
- self:addnameserver ("208.67.222.222")
- self:addnameserver ("208.67.220.220")
+ elseif os.getenv("WINDIR") then
+ self:addnameserver ("208.67.222.222")
+ self:addnameserver ("208.67.220.220")
+ end
+ if not self.server or #self.server == 0 then
+ self:addnameserver("127.0.0.1");
end
end
diff --git a/net/httpserver.lua b/net/httpserver.lua
index 57c8eede..56dfe04e 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -61,7 +61,7 @@ local function send_response(request, response)
end
else
-- Response we have is just a string (the body)
- log("debug", "Sending response to %s: %s", request.id or "<none>", response or "<none>");
+ log("debug", "Sending 200 response to %s", request.id or "<none>");
resp = { "HTTP/1.0 200 OK\r\n" };
t_insert(resp, "Connection: close\r\n");
@@ -89,9 +89,6 @@ local function call_callback(request, err)
end
callback = (request.server and request.server.handlers[base]) or default_handler;
- if callback == default_handler then
- log("debug", "Default callback for this request (base: "..tostring(base)..")")
- end
end
if callback then
if err then
@@ -251,6 +248,10 @@ function new(params)
end
end
+function set_default_handler(handler)
+ default_handler = handler;
+end
+
function new_from_config(ports, default_base, handle_request)
for _, options in ipairs(ports) do
local port, base, ssl, interface = 5280, default_base, false, nil;
diff --git a/net/server.lua b/net/server.lua
index 966006c1..65567d15 100644
--- a/net/server.lua
+++ b/net/server.lua
@@ -246,7 +246,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco
_socketlist[ socket ] = nil
handler = nil
socket = nil
- mem_free( )
+ --mem_free( )
out_put "server.lua: closed server handler and removed sockets from list"
end
handler.ip = function( )
@@ -373,7 +373,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
handler = nil
end
socket = nil
- mem_free( )
+ --mem_free( )
if server then
server.remove( )
end
@@ -483,13 +483,19 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
end
end
local _sendbuffer = function( ) -- this function sends data
- local buffer = table_concat( bufferqueue, "", 1, bufferqueuelen )
- local succ, err, byte = send( socket, buffer, 1, bufferlen )
- local count = ( succ or byte or 0 ) * STAT_UNIT
- sendtraffic = sendtraffic + count
- _sendtraffic = _sendtraffic + count
- _ = _cleanqueue and clean( bufferqueue )
- --out_put( "server.lua: sended '", buffer, "', bytes: ", tostring(succ), ", error: ", tostring(err), ", part: ", tostring(byte), ", to: ", tostring(ip), ":", tostring(clientport) )
+ local succ, err, byte, buffer, count;
+ local count;
+ if socket then
+ buffer = table_concat( bufferqueue, "", 1, bufferqueuelen )
+ succ, err, byte = send( socket, buffer, 1, bufferlen )
+ count = ( succ or byte or 0 ) * STAT_UNIT
+ sendtraffic = sendtraffic + count
+ _sendtraffic = _sendtraffic + count
+ _ = _cleanqueue and clean( bufferqueue )
+ --out_put( "server.lua: sended '", buffer, "', bytes: ", tostring(succ), ", error: ", tostring(err), ", part: ", tostring(byte), ", to: ", tostring(ip), ":", tostring(clientport) )
+ else
+ succ, err, count = false, "closed", 0;
+ end
if succ then -- sending succesful
bufferqueuelen = 0
bufferlen = 0
@@ -559,7 +565,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
socket, err = ssl_wrap( socket, sslctx ) -- wrap socket
if err then
out_put( "server.lua: ssl error: ", tostring(err) )
- mem_free( )
+ --mem_free( )
return nil, nil, err -- fatal error
end
socket:settimeout( 0 )
@@ -664,7 +670,7 @@ closesocket = function( socket )
_readlistlen = removesocket( _readlist, socket, _readlistlen )
_socketlist[ socket ] = nil
socket:close( )
- mem_free( )
+ --mem_free( )
end
----------------------------------// PUBLIC //--
@@ -733,7 +739,7 @@ closeall = function( )
_sendlist = { }
_timerlist = { }
_socketlist = { }
- mem_free( )
+ --mem_free( )
end
getsettings = function( )
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua
index ce7788c7..6cea43f2 100644
--- a/net/xmppclient_listener.lua
+++ b/net/xmppclient_listener.lua
@@ -61,6 +61,7 @@ local function session_reset_stream(session)
function session.data(conn, data)
local ok, err = parser:parse(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]+", " "));
session:close("xml-not-well-formed");
end
@@ -100,7 +101,7 @@ local function session_close(session, reason)
end
session.send("</stream:stream>");
session.conn.close();
- xmppclient.disconnect(session.conn, (reason and reason.condition) or reason or "session closed");
+ xmppclient.disconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed");
end
end
@@ -113,11 +114,6 @@ function xmppclient.listener(conn, data)
session = sm_new_session(conn);
sessions[conn] = session;
- -- Logging functions --
-
- local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$");
- session.log = logger.init(conn_name);
-
session.log("info", "Client connected");
-- Client is using legacy SSL (otherwise mod_tls sets this flag)
diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua
index 81d26526..6a196446 100644
--- a/net/xmppserver_listener.lua
+++ b/net/xmppserver_listener.lua
@@ -61,6 +61,7 @@ local function session_reset_stream(session)
function session.data(conn, data)
local ok, err = parser:parse(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]+", " "));
session:close("xml-not-well-formed");
end
@@ -113,12 +114,6 @@ function xmppserver.listener(conn, data)
session = s2s_new_incoming(conn);
sessions[conn] = session;
- -- Logging functions --
-
-
- local conn_name = "s2sin"..tostring(conn):match("[a-f0-9]+$");
- session.log = logger.init(conn_name);
-
session.log("info", "Incoming s2s connection");
session.reset_stream = session_reset_stream;