# HG changeset patch # User Matthew Wild # Date 1247408619 -3600 # Node ID 30ebb38573b7c8e8e5f99195a97e570fbb21ca11 # Parent f2dd7ac894701d4d5aa424e5948398b02831809a# Parent dff620405503495783ef711f30bb2ce6d328f6fe Merge with 0.5 diff -r f2dd7ac89470 -r 30ebb38573b7 net/httpserver.lua --- a/net/httpserver.lua Sun Jul 12 14:34:02 2009 +0100 +++ b/net/httpserver.lua Sun Jul 12 15:23:39 2009 +0100 @@ -17,7 +17,7 @@ local t_insert, t_concat = table.insert, table.concat; local s_match, s_gmatch = string.match, string.gmatch; -local tonumber, tostring, pairs = tonumber, tostring, pairs; +local tonumber, tostring, pairs, ipairs, type = tonumber, tostring, pairs, ipairs, type; local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end @@ -250,6 +250,26 @@ end end +function new_from_config(ports, handle_request) + for _, options in ipairs(ports) do + local port, base, ssl, interface = 5280, "http-bind", false, nil; + if type(options) == "number" then + port = options; + elseif type(options) == "table" then + port, base, ssl, interface = options.port or 5280, options.path or "http-bind", options.ssl or false, options.interface; + elseif type(options) == "string" then + base = options; + end + + if ssl then + ssl.mode = "server"; + ssl.protocol = "sslv23"; + end + + new{ port = port, base = base, handler = handle_request, ssl = ssl, type = (ssl and "ssl") or "tcp" } + end +end + _M.request_reader = request_reader; _M.send_response = send_response; _M.urlencode = urlencode; diff -r f2dd7ac89470 -r 30ebb38573b7 net/server.lua --- a/net/server.lua Sun Jul 12 14:34:02 2009 +0100 +++ b/net/server.lua Sun Jul 12 15:23:39 2009 +0100 @@ -546,7 +546,9 @@ socket:settimeout( 0 ) handler.readbuffer = handshake handler.sendbuffer = handshake - handshake( socket ) -- do handshake + if not handshake( socket ) then -- do handshake + return nil, nil, "ssl handshake failed"; + end else -- We're not automatically doing SSL, so we're not secure (yet) ssl = false diff -r f2dd7ac89470 -r 30ebb38573b7 plugins/mod_bosh.lua --- a/plugins/mod_bosh.lua Sun Jul 12 14:34:02 2009 +0100 +++ b/plugins/mod_bosh.lua Sun Jul 12 15:23:39 2009 +0100 @@ -276,16 +276,6 @@ end local ports = config.get(module.host, "core", "bosh_ports") or { 5280 }; -for _, options in ipairs(ports) do - local port, base, ssl, interface = 5280, "http-bind", false, nil; - if type(options) == "number" then - port = options; - elseif type(options) == "table" then - port, base, ssl, interface = options.port or 5280, options.path or "http-bind", options.ssl or false, options.interface; - elseif type(options) == "string" then - base = options; - end - httpserver.new{ port = port, base = base, handler = handle_request, ssl = ssl } -end +httpserver.new_from_config(ports, handle_request); server.addtimer(on_timer); diff -r f2dd7ac89470 -r 30ebb38573b7 plugins/mod_httpserver.lua --- a/plugins/mod_httpserver.lua Sun Jul 12 14:34:02 2009 +0100 +++ b/plugins/mod_httpserver.lua Sun Jul 12 15:23:39 2009 +0100 @@ -28,14 +28,4 @@ end local ports = config.get(module.host, "core", "http_ports") or { 5280 }; -for _, options in ipairs(ports) do - local port, base, ssl, interface = 5280, "files", false, nil; - if type(options) == "number" then - port = options; - elseif type(options) == "table" then - port, base, ssl, interface = options.port or 5280, options.path or "files", options.ssl or false, options.interface; - elseif type(options) == "string" then - base = options; - end - httpserver.new{ port = port, base = base, handler = handle_request, ssl = ssl } -end +httpserver.new_from_config(ports, handle_request);