Changeset

658:1952fdcf1017

Fix specifying ports in config, and SSL support
author Matthew Wild <mwild1@gmail.com>
date Sat, 27 Dec 2008 21:20:09 +0000
parents 657:7f1946174d4b
children 659:c424bec771d9
files net/connlisteners.lua net/server.lua prosody
diffstat 3 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/net/connlisteners.lua	Sat Dec 27 21:18:12 2008 +0000
+++ b/net/connlisteners.lua	Sat Dec 27 21:20:09 2008 +0000
@@ -20,7 +20,7 @@
 
 
 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/";
-local server_add = require "net.server".add;
+local server = require "net.server";
 local log = require "util.logger".init("connlisteners");
 
 local dofile, pcall, error = 
@@ -54,14 +54,19 @@
 	return h;
 end
 
+local wrapper_functions = { tcp = server.wraptcpclient, ssl = server.wrapsslclient, tls = server.wraptlsclient }
+
 function start(name, udata)
 	local h = get(name);
 	if not h then
 		error("No such connection module: "..name, 0);
 	end
-	return server_add(h, 
+	
+	local wrapper_function = wrapper_functions[(udata and udata.type)] or wrapper_functions.tcp;
+	
+	return server.add(h, 
 			(udata and udata.port) or h.default_port or error("Can't start listener "..name.." because no port was specified, and it has no default port", 0), 
-				(udata and udata.interface) or "*", (udata and udata.mode) or h.default_mode or 1, (udata and udata.ssl) or nil );
+				(udata and udata.interface) or "*", (udata and udata.mode) or h.default_mode or 1, (udata and udata.ssl) or nil, wrapper_function);
 end
 
 return _M;
--- a/net/server.lua	Sat Dec 27 21:18:12 2008 +0000
+++ b/net/server.lua	Sat Dec 27 21:20:09 2008 +0000
@@ -94,14 +94,14 @@
 	return receivestat, sendstat
 end
 
-wrapserver = function( listener, socket, ip, serverport, mode, sslctx )    -- this function wraps a server
+wrapserver = function( listener, socket, ip, serverport, mode, sslctx, wrapper_function )    -- this function wraps a server
 
 	local dispatch, disconnect = listener.listener, listener.disconnect    -- dangerous
 
 	local wrapclient, err
 
 	out_put("Starting a new server on "..tostring(serverport).." with ssl: "..tostring(sslctx));
-	
+	out_put(traceback())
 	if sslctx then
 		if not ssl_newcontext then
 			return nil, "luasec not found"
@@ -116,12 +116,16 @@
 			out_error( "server.lua: ", err )
 			return nil, err
 		end
+	end
+	
+	if wrapper_function then
+		wrapclient = wrapper_function
+	elseif sslctx then
 		wrapclient = wrapsslclient
-		wrapclient = wraptlsclient
 	else
 		wrapclient = wraptcpclient
 	end
-
+	
 	local accept = socket.accept
 	local close = socket.close
 
@@ -768,7 +772,7 @@
 	end
 end
 
-addserver = function( listeners, port, addr, mode, sslctx )    -- this function provides a way for other scripts to reg a server
+addserver = function( listeners, port, addr, mode, sslctx, wrapper_function )    -- this function provides a way for other scripts to reg a server
 	local err
 	if type( listeners ) ~= "table" then
 		err = "invalid listener table"
@@ -797,7 +801,7 @@
 		out_error( "server.lua: ", err )
 		return nil, err
 	end
-	local handler, err = wrapserver( listeners, server, addr, port, mode, sslctx )    -- wrap new server socket
+	local handler, err = wrapserver( listeners, server, addr, port, mode, sslctx, wrapper_function )    -- wrap new server socket
 	if not handler then
 		server:close( )
 		return nil, err
@@ -877,5 +881,6 @@
 	closeall = closeall,
 	addtimer = addtimer,
 	wraptcpclient = wraptcpclient,
+	wrapsslclient = wrapsslclient,
 	wraptlsclient = wraptlsclient,
 }
--- a/prosody	Sat Dec 27 21:18:12 2008 +0000
+++ b/prosody	Sat Dec 27 21:20:09 2008 +0000
@@ -123,9 +123,10 @@
 end
 
 -- start listening on sockets
-local function do_ports(option, listener, default, key)
+local function do_ports(option, listener, default, conntype)
 	local ports = config.get("*", "core", option) or default;
 	--if type(ports) == "number" then ports = {ports} end;
+	
 	if type(ports) ~= "table" then
 		log("error", "core."..option.." is not a table");
 	else
@@ -133,15 +134,15 @@
 			if type(port) ~= "number" then
 				log("error", "Non-numeric "..option..": "..tostring(port));
 			else
-				cl.start(listener, { ssl = global_ssl_ctx, [key] = port });
+				cl.start(listener, { ssl = global_ssl_ctx, port = port, type = conntype });
 			end
 		end
 	end
 end
 
-do_ports("c2s_ports", "xmppclient", {5222}, "port");
-do_ports("s2s_ports", "xmppserver", {5269}, "port");
-do_ports("legacy_ssl_ports", "xmppclient", {}, "legacy_ssl_port");
+do_ports("c2s_ports", "xmppclient", {5222}, "tls");
+do_ports("s2s_ports", "xmppserver", {5269}, "tcp");
+do_ports("legacy_ssl_ports", "xmppclient", {}, "ssl");
 
 if config.get("*", "core", "console_enabled") then
 	if cl.get("console") then