aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2013-12-18 18:11:17 -0500
committerdaurnimator <quae@daurnimator.com>2013-12-18 18:11:17 -0500
commitae044f21b05363570a8e8ee96c716e9b4f42f2b9 (patch)
treeb91286bc53f1432f1025e782feddb39ce47ab70d /net
parent62ce3bb70888010588030c679fb778c22ab023fb (diff)
downloadprosody-ae044f21b05363570a8e8ee96c716e9b4f42f2b9.tar.gz
prosody-ae044f21b05363570a8e8ee96c716e9b4f42f2b9.zip
net/server_event: pcall require ssl rather than relying on globals
Diffstat (limited to 'net')
-rw-r--r--net/server_event.lua30
1 files changed, 11 insertions, 19 deletions
diff --git a/net/server_event.lua b/net/server_event.lua
index 82accc99..502cc80a 100644
--- a/net/server_event.lua
+++ b/net/server_event.lua
@@ -44,7 +44,7 @@ local setmetatable = use "setmetatable"
local t_insert = table.insert
local t_concat = table.concat
-local ssl = use "ssl"
+local has_luasec, ssl = pcall ( require , "ssl" )
local socket = use "socket" or require "socket"
local log = require ("util.logger").init("socket")
@@ -136,7 +136,7 @@ do
self:_close()
debug( "new connection failed. id:", self.id, "error:", self.fatalerror )
else
- if plainssl and ssl then -- start ssl session
+ if plainssl and has_luasec then -- start ssl session
self:starttls(self._sslctx, true)
else -- normal connection
self:_start_session(true)
@@ -506,7 +506,7 @@ do
_sslctx = sslctx; -- parameters
_usingssl = false; -- client is using ssl;
}
- if not ssl then interface.starttls = false; end
+ if not has_luasec then interface.starttls = false; end
interface.id = tostring(interface):match("%x+$");
interface.writecallback = function( event ) -- called on write events
--vdebug( "new client write event, id/ip/port:", interface, ip, port )
@@ -689,7 +689,7 @@ do
interface._connections = interface._connections + 1 -- increase connection count
local clientinterface = handleclient( client, client_ip, client_port, interface, pattern, listener, sslctx )
--vdebug( "client id:", clientinterface, "startssl:", startssl )
- if ssl and sslctx then
+ if has_luasec and sslctx then
clientinterface:starttls(sslctx, true)
else
clientinterface:_start_session( true )
@@ -710,25 +710,17 @@ do
end
local addserver = ( function( )
- return function( addr, port, listener, pattern, sslcfg, startssl ) -- TODO: check arguments
- --vdebug( "creating new tcp server with following parameters:", addr or "nil", port or "nil", sslcfg or "nil", startssl or "nil")
+ return function( addr, port, listener, pattern, sslctx, startssl ) -- TODO: check arguments
+ --vdebug( "creating new tcp server with following parameters:", addr or "nil", port or "nil", sslctx or "nil", startssl or "nil")
+ if sslctx and not has_luasec then
+ debug "fatal error: luasec not found"
+ return nil, "luasec not found"
+ end
local server, err = socket.bind( addr, port, cfg.ACCEPT_QUEUE ) -- create server socket
if not server then
debug( "creating server socket on "..addr.." port "..port.." failed:", err )
return nil, err
end
- local sslctx
- if sslcfg then
- if not ssl then
- debug "fatal error: luasec not found"
- return nil, "luasec not found"
- end
- sslctx, err = sslcfg
- if err then
- debug( "error while creating new ssl context for server socket:", err )
- return nil, err
- end
- end
local interface = handleserver( server, addr, port, pattern, listener, sslctx, startssl ) -- new server handler
debug( "new server created with id:", tostring(interface))
return interface
@@ -745,7 +737,7 @@ do
end
function addclient( addr, serverport, listener, pattern, sslctx )
- if sslctx and not ssl then
+ if sslctx and not has_luasec then
debug "need luasec, but not available"
return nil, "luasec not found"
end