diff options
-rw-r--r-- | net/connlisteners.lua | 16 | ||||
-rw-r--r-- | net/server_select.lua | 24 | ||||
-rwxr-xr-x | prosody | 50 |
3 files changed, 51 insertions, 39 deletions
diff --git a/net/connlisteners.lua b/net/connlisteners.lua index 7da25c62..6a227c9d 100644 --- a/net/connlisteners.lua +++ b/net/connlisteners.lua @@ -12,6 +12,8 @@ local listeners_dir = (CFG_SOURCEDIR or ".").."/net/"; local server = require "net.server"; local log = require "util.logger".init("connlisteners"); local tostring = tostring; +local type = type +local ipairs = ipairs local dofile, xpcall, error = dofile, xpcall, error @@ -55,7 +57,8 @@ function start(name, udata) error("No such connection module: "..name.. (err and (" ("..err..")") or ""), 0); end - local interface = (udata and udata.interface) or h.default_interface or "*"; + local interfaces = (udata and udata.interface) or h.default_interface or "*"; + if type(interfaces) == "string" then interfaces = {interfaces}; end local port = (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); local mode = (udata and udata.mode) or h.default_mode or 1; local ssl = (udata and udata.ssl) or nil; @@ -64,8 +67,15 @@ function start(name, udata) if autossl and not ssl then return nil, "no ssl context"; end - - return server.addserver(interface, port, h, mode, autossl and ssl or nil); + + ok, err = true, {}; + for _, interface in ipairs(interfaces) do + local handler + handler, err[interface] = server.addserver(interface, port, h, mode, autossl and ssl or nil); + ok = ok and handler; + end + + return ok, err; end return _M; diff --git a/net/server_select.lua b/net/server_select.lua index 13a910f8..4a22d2ed 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -701,19 +701,19 @@ addserver = function( addr, port, listeners, pattern, sslctx ) -- this function end if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then err = "invalid port" - elseif _server[ port ] then - err = "listeners on port '" .. port .. "' already exist" + elseif _server[ addr..":"..port ] then + err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" elseif sslctx and not luasec then err = "luasec not found" end if err then - out_error( "server.lua, port ", port, ": ", err ) + out_error( "server.lua, [", addr, "]:", port, ": ", err ) return nil, err end addr = addr or "*" local server, err = socket_bind( addr, port ) if err then - out_error( "server.lua, port ", port, ": ", err ) + out_error( "server.lua, [", addr, "]:", port, ": ", err ) return nil, err end local handler, err = wrapserver( listeners, server, addr, port, pattern, sslctx, _maxclientsperserver ) -- wrap new server socket @@ -723,23 +723,23 @@ addserver = function( addr, port, listeners, pattern, sslctx ) -- this function end server:settimeout( 0 ) _readlistlen = addsocket(_readlist, server, _readlistlen) - _server[ port ] = handler + _server[ addr..":"..port ] = handler _socketlist[ server ] = handler - out_put( "server.lua: new "..(sslctx and "ssl " or "").."server listener on '", addr, ":", port, "'" ) + out_put( "server.lua: new "..(sslctx and "ssl " or "").."server listener on '[", addr, "]:", port, "'" ) return handler end -getserver = function ( port ) - return _server[ port ]; +getserver = function ( addr, port ) + return _server[ addr..":"..port ]; end -removeserver = function( port ) - local handler = _server[ port ] +removeserver = function( addr, port ) + local handler = _server[ addr..":"..port ] if not handler then - return nil, "no server found on port '" .. tostring( port ) .. "'" + return nil, "no server found on '[" .. addr .. "]:" .. tostring( port ) .. "'" end handler:close( ) - _server[ port ] = nil + _server[ addr..":"..port ] = nil return true end @@ -270,7 +270,7 @@ function init_global_state() if type(port) ~= "number" then log("error", "Non-numeric "..ports_option..": "..tostring(port)); else - local ok, err = cl.start(listener, { + local ok, errors = cl.start(listener, { ssl = conntype == "ssl" and global_ssl_ctx, port = port, interface = (option and config.get("*", "core", option.."_interface")) @@ -279,31 +279,33 @@ function init_global_state() type = conntype }); if not ok then - local friendly_message = err; - if err:match(" in use") then - if port == 5222 or port == 5223 or port == 5269 then - friendly_message = "check that Prosody or another XMPP server is " - .."not already running and using this port"; - elseif port == 80 or port == 81 then - friendly_message = "check that a HTTP server is not already using " - .."this port"; - elseif port == 5280 then - friendly_message = "check that Prosody or a BOSH connection manager " - .."is not already running"; - else - friendly_message = "this port is in use by another application"; - end - elseif err:match("permission") then - friendly_message = "Prosody does not have sufficient privileges to use this port"; - elseif err == "no ssl context" then - if not config.get("*", "core", "ssl") then - friendly_message = "there is no 'ssl' config under Host \"*\" which is " - .."require for legacy SSL ports"; - else - friendly_message = "initializing SSL support failed, see previous log entries"; + for addr, err in pairs(errors) do + local friendly_message = err; + if err:match(" in use") then + if port == 5222 or port == 5223 or port == 5269 then + friendly_message = "check that Prosody or another XMPP server is " + .."not already running and using this port"; + elseif port == 80 or port == 81 then + friendly_message = "check that a HTTP server is not already using " + .."this port"; + elseif port == 5280 then + friendly_message = "check that Prosody or a BOSH connection manager " + .."is not already running"; + else + friendly_message = "this port is in use by another application"; + end + elseif err:match("permission") then + friendly_message = "Prosody does not have sufficient privileges to use this port"; + elseif err == "no ssl context" then + if not config.get("*", "core", "ssl") then + friendly_message = "there is no 'ssl' config under Host \"*\" which is " + .."require for legacy SSL ports"; + else + friendly_message = "initializing SSL support failed, see previous log entries"; + end end + log("error", "Failed to open server port %d on %s, %s", port, addr, friendly_message); end - log("error", "Failed to open server port %d, %s", port, friendly_message); end end end |