Software /
code /
prosody
Comparison
core/portmanager.lua @ 5399:13454b2b86bf
portmanager: Log error and fail to bind when port is invalid (not a number)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 31 Mar 2013 12:27:28 +0100 |
parent | 5392:613959dbd0b2 |
child | 5426:1b20095eb230 |
comparison
equal
deleted
inserted
replaced
5397:ed55a48270be | 5399:13454b2b86bf |
---|---|
7 local multitable = require "util.multitable"; | 7 local multitable = require "util.multitable"; |
8 local set = require "util.set"; | 8 local set = require "util.set"; |
9 | 9 |
10 local table = table; | 10 local table = table; |
11 local setmetatable, rawset, rawget = setmetatable, rawset, rawget; | 11 local setmetatable, rawset, rawget = setmetatable, rawset, rawget; |
12 local type, tonumber, ipairs = type, tonumber, ipairs; | 12 local type, tonumber, tostring, ipairs = type, tonumber, tostring, ipairs; |
13 | 13 |
14 local prosody = prosody; | 14 local prosody = prosody; |
15 local fire_event = prosody.events.fire_event; | 15 local fire_event = prosody.events.fire_event; |
16 | 16 |
17 module "portmanager"; | 17 module "portmanager"; |
103 | 103 |
104 local mode, ssl = listener.default_mode or "*a"; | 104 local mode, ssl = listener.default_mode or "*a"; |
105 | 105 |
106 for interface in bind_interfaces do | 106 for interface in bind_interfaces do |
107 for port in bind_ports do | 107 for port in bind_ports do |
108 port = tonumber(port); | 108 local port_number = tonumber(port); |
109 if #active_services:search(nil, interface, port) > 0 then | 109 if not port_number then |
110 log("error", "Invalid port number specified for service '%s': %s", service_info.name, tostring(port)); | |
111 elseif #active_services:search(nil, interface, port_number) > 0 then | |
110 log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "<unnamed>", service_name or "<unnamed>"); | 112 log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "<unnamed>", service_name or "<unnamed>"); |
111 else | 113 else |
112 local err; | 114 local err; |
113 -- Create SSL context for this service/port | 115 -- Create SSL context for this service/port |
114 if service_info.encryption == "ssl" then | 116 if service_info.encryption == "ssl" then |
115 local ssl_config = config.get("*", config_prefix.."ssl"); | 117 local ssl_config = config.get("*", config_prefix.."ssl"); |
116 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port] | 118 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port_number] |
117 or (ssl_config.certificate and ssl_config))); | 119 or (ssl_config.certificate and ssl_config))); |
118 if not ssl then | 120 if not ssl then |
119 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port, err) or "unknown error"); | 121 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port_number, err) or "unknown error"); |
120 end | 122 end |
121 end | 123 end |
122 if not err then | 124 if not err then |
123 -- Start listening on interface+port | 125 -- Start listening on interface+port |
124 local handler, err = server.addserver(interface, port, listener, mode, ssl); | 126 local handler, err = server.addserver(interface, port_number, listener, mode, ssl); |
125 if not handler then | 127 if not handler then |
126 log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, port, err)); | 128 log("error", "Failed to open server port %d on %s, %s", port_number, interface, error_to_friendly_message(service_name, port_number, err)); |
127 else | 129 else |
128 log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); | 130 log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port_number); |
129 active_services:add(service_name, interface, port, { | 131 active_services:add(service_name, interface, port_number, { |
130 server = handler; | 132 server = handler; |
131 service = service_info; | 133 service = service_info; |
132 }); | 134 }); |
133 end | 135 end |
134 end | 136 end |