aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/adns.lua14
-rw-r--r--net/connlisteners.lua15
-rw-r--r--net/dns.lua4
-rw-r--r--net/http.lua34
-rw-r--r--net/httpserver.lua11
-rw-r--r--net/server_event.lua8
6 files changed, 48 insertions, 38 deletions
diff --git a/net/adns.lua b/net/adns.lua
index 87f2876b..d3da2065 100644
--- a/net/adns.lua
+++ b/net/adns.lua
@@ -16,9 +16,9 @@ local coroutine, tostring, pcall = coroutine, tostring, pcall;
local function dummy_send(sock, data, i, j) return (j-i)+1; end
-module "adns"
+local _ENV = nil;
-function lookup(handler, qname, qtype, qclass)
+local function lookup(handler, qname, qtype, qclass)
return coroutine.wrap(function (peek)
if peek then
log("debug", "Records for %s already cached, using those...", qname);
@@ -43,12 +43,12 @@ function lookup(handler, qname, qtype, qclass)
end)(dns.peek(qname, qtype, qclass));
end
-function cancel(handle, call_handler, reason)
+local function cancel(handle, call_handler, reason)
log("warn", "Cancelling DNS lookup for %s", tostring(handle[3]));
dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler);
end
-function new_async_socket(sock, resolver)
+local function new_async_socket(sock, resolver)
local peername = "<unknown>";
local listener = {};
local handler = {};
@@ -88,4 +88,8 @@ end
dns.socket_wrapper_set(new_async_socket);
-return _M;
+return {
+ lookup = lookup;
+ cancel = cancel;
+ new_async_socket = new_async_socket;
+};
diff --git a/net/connlisteners.lua b/net/connlisteners.lua
index 99ddc720..000bfa63 100644
--- a/net/connlisteners.lua
+++ b/net/connlisteners.lua
@@ -2,14 +2,17 @@
local log = require "util.logger".init("net.connlisteners");
local traceback = debug.traceback;
-module "httpserver"
+local _ENV = nil;
-function fail()
+local function fail()
log("error", "Attempt to use legacy connlisteners API. For more info see http://prosody.im/doc/developers/network");
log("error", "Legacy connlisteners API usage, %s", traceback("", 2));
end
-register, deregister = fail, fail;
-get, start = fail, fail, epic_fail;
-
-return _M;
+return {
+ register = fail;
+ register = fail;
+ get = fail;
+ start = fail;
+ -- epic fail
+};
diff --git a/net/dns.lua b/net/dns.lua
index 992f3986..acc1556c 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -71,8 +71,8 @@ local get, set = ztact.get, ztact.set;
local default_timeout = 15;
-------------------------------------------------- module dns
-module('dns')
-local dns = _M;
+local _ENV = nil;
+local dns = {};
-- dns type & class codes ------------------------------ dns type & class codes
diff --git a/net/http.lua b/net/http.lua
index 357b7452..b78f8438 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -23,7 +23,7 @@ local assert, error = assert, error
local log = require "util.logger".init("http");
-module "http"
+local _ENV = nil;
local requests = {}; -- Open requests
@@ -75,6 +75,13 @@ function listener.ondetach(conn)
requests[conn] = nil;
end
+local function destroy_request(request)
+ if request.conn then
+ request.conn = nil;
+ request.handler:close()
+ end
+end
+
local function request_reader(request, data, err)
if not request.parser then
local function error_cb(reason)
@@ -106,7 +113,7 @@ local function request_reader(request, data, err)
end
local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
-function request(u, ex, callback)
+local function request(u, ex, callback)
local req = url.parse(u);
if not (req and req.host) then
@@ -184,17 +191,12 @@ function request(u, ex, callback)
return req;
end
-function destroy_request(request)
- if request.conn then
- request.conn = nil;
- request.handler:close()
- end
-end
-
-local urlencode, urldecode = util_http.urlencode, util_http.urldecode;
-local formencode, formdecode = util_http.formencode, util_http.formdecode;
-
-_M.urlencode, _M.urldecode = urlencode, urldecode;
-_M.formencode, _M.formdecode = formencode, formdecode;
-
-return _M;
+return {
+ request = request;
+
+ -- COMPAT
+ urlencode = util_http.urlencode;
+ urldecode = util_http.urldecode;
+ formencode = util_http.formencode;
+ formdecode = util_http.formdecode;
+};
diff --git a/net/httpserver.lua b/net/httpserver.lua
index 7d574788..6e2e31b9 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -2,14 +2,15 @@
local log = require "util.logger".init("net.httpserver");
local traceback = debug.traceback;
-module "httpserver"
+local _ENV = nil;
function fail()
log("error", "Attempt to use legacy HTTP API. For more info see http://prosody.im/doc/developers/legacy_http");
log("error", "Legacy HTTP API usage, %s", traceback("", 2));
end
-new, new_from_config = fail, fail;
-set_default_handler = fail;
-
-return _M;
+return {
+ new = fail;
+ new_from_config = fail;
+ set_default_handler = fail;
+};
diff --git a/net/server_event.lua b/net/server_event.lua
index fa6dda19..a4cf1146 100644
--- a/net/server_event.lua
+++ b/net/server_event.lua
@@ -758,18 +758,18 @@ do
local create = socket[typ or "tcp"]
if type( create ) ~= "function" then
return nil, "invalid socket type"
- end
+ end
local client, err = create() -- creating new socket
if not client then
debug( "cannot create socket:", err )
- return nil, err
- end
+ return nil, err
+ end
client:settimeout( 0 ) -- set nonblocking
local res, err = client:connect( addr, serverport ) -- connect
if res or ( err == "timeout" or err == "Operation already in progress" ) then
if client.getsockname then
addr = client:getsockname( )
- end
+ end
local interface = wrapclient( client, addr, serverport, listener, pattern, sslctx )
debug( "new connection id:", interface.id )
return interface, err