From 346ca73cc20ec8f286be470b1f4f5910f5216b8c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jan 2012 23:55:48 +0000 Subject: portmanager: One manager to, in the darkness, bind them --- core/portmanager.lua | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 core/portmanager.lua (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua new file mode 100644 index 00000000..a460cd6a --- /dev/null +++ b/core/portmanager.lua @@ -0,0 +1,132 @@ + +local multitable = require "util.multitable"; +local fire_event = prosody.events.fire_event; + +--- Config + +local default_interfaces = { "*" }; +local default_local_interfaces = { "127.0.0.1" }; +if config.get("*", "use_ipv6") then + table.insert(default_interfaces, "::"); + table.insert(default_local_interfaces, "::1"); +end + +--- Private state + +-- service_name -> service_info +local services = {}; + +-- service_name, interface (string), port (number) +local active_services = multitable.new(); + +--- Private helpers + +local function error_to_friendly_message(service_name, err) + local friendly_message = err; + if err:match(" in use") then + -- FIXME: Use service_name here + 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 + return friendly_message; +end + +module("portmanager", package.seeall); + +--- Public API + +function activate_service(service_name) + local service_info = services[service_name]; + if not service_info then + return nil, "Unknown service: "..service_name; + end + + local bind_interfaces = set.new(config.get("*", service_name.."_interfaces") + or config.get("*", service_name.."_interface") -- COMPAT w/pre-0.9 + or config.get("*", "interfaces") + or config.get("*", "interface") -- COMPAT w/pre-0.9 + or (service_info.private and default_local_interfaces) + or service_info.default_interface -- COMPAT w/pre0.9 + or default_interfaces); + + local bind_ports = set.new(config.get("*", service_name.."_ports") + or (service_info.multiplex and config.get("*", "ports")) + or service_info.default_ports + or {service_info.default_port}); + + local listener = service_info.listener; + local mode = listener.default_mode or "*a"; + local ssl; + if service_info.encryption == "ssl" then + ssl = prosody.global_ssl_ctx; + if not ssl then + return nil, "global-ssl-context-required"; + end + end + + for interface in bind_interfaces do + for port in bind_ports do + if not service_info.multiplex and #active_services:search(nil, interface, port) > 0 then + log("error", "Multiple services configured to listen on the same port: %s, %s", table.concat(active_services:search(nil, interface, port), ", "), service_name); + else + local handler, err = server.addserver(interface, port, listener, mode, ssl); + if not handler then + log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, err)); + else + log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); + active_services:add(service_name, interface, port, { + server = handler; + service = service_info; + }); + end + end + end + end + log("info", "Activated service '%s'", service_name); +end + +function deactivate(service_name) + local active = active_services:search(service_name)[1]; + if not active then return; end + for interface, ports in pairs(active) do + for port, active_service in pairs(ports) do + active_service:close(); + active_services:remove(service_name, interface, port, active_service); + log("debug", "Removed listening service %s from [%s]:%d", service_name, interface, port); + end + end + log("info", "Deactivated service '%s'", service_name); +end + +function register_service(service_name, service_info) + services[service_name] = service_info; + + if not active_services[service_name] then + activate_service(service_name); + end + + fire_event("service-added", { name = service_name, service = service_info }); + return true; +end + + +return _M; -- cgit v1.2.3 From 335e19315e20464e6290c0d92f8d8b87bb485361 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jan 2012 00:07:15 +0000 Subject: portmanager: Pass port to friendly_error_message() --- core/portmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index a460cd6a..353c4a89 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -21,7 +21,7 @@ local active_services = multitable.new(); --- Private helpers -local function error_to_friendly_message(service_name, err) +local function error_to_friendly_message(service_name, port, err) local friendly_message = err; if err:match(" in use") then -- FIXME: Use service_name here @@ -90,7 +90,7 @@ function activate_service(service_name) else local handler, err = server.addserver(interface, port, listener, mode, ssl); if not handler then - log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, err)); + log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, port, err)); else log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); active_services:add(service_name, interface, port, { -- cgit v1.2.3 From f886be3d2c699f58a84b37c2ec51cdd14ebf6fe7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 3 Mar 2012 00:54:19 +0100 Subject: core.portmanager: Make sure the private flag takes precedence over global interfaces --- core/portmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 353c4a89..3d6dada4 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -62,9 +62,9 @@ function activate_service(service_name) local bind_interfaces = set.new(config.get("*", service_name.."_interfaces") or config.get("*", service_name.."_interface") -- COMPAT w/pre-0.9 + or (service_info.private and default_local_interfaces) or config.get("*", "interfaces") or config.get("*", "interface") -- COMPAT w/pre-0.9 - or (service_info.private and default_local_interfaces) or service_info.default_interface -- COMPAT w/pre0.9 or default_interfaces); -- cgit v1.2.3 From 91247839773b8514d2097e818271e4e84dfc4362 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 11 Mar 2012 12:40:32 +0000 Subject: portmanager: Add get_service() --- core/portmanager.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 3d6dada4..f655659d 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -128,5 +128,8 @@ function register_service(service_name, service_info) return true; end +function get_service(service_name) + return services[service_name]; +end return _M; -- cgit v1.2.3 From e7eecd81b727f653c5e3f7ecf3da956dc94cf5eb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 11 Mar 2012 18:35:27 +0000 Subject: portmanager: Add get_active_services() --- core/portmanager.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index f655659d..103c5d44 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -132,4 +132,8 @@ function get_service(service_name) return services[service_name]; end +function get_active_services(...) + return active_services; +end + return _M; -- cgit v1.2.3 From 88ea07a5ef72ee7d65d8e35a40186c7cd169cd41 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 14 Mar 2012 21:39:02 +0000 Subject: portmanager: Add unregister_service(), and allow multiple services with the same name (they get queued) --- core/portmanager.lua | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 103c5d44..30597628 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -13,8 +13,8 @@ end --- Private state --- service_name -> service_info -local services = {}; +-- service_name -> { service_info, ... } +local services = setmetatable({}, { __index = function (t, k) rawset(t, k, {}); return rawget(t, k); end }); -- service_name, interface (string), port (number) local active_services = multitable.new(); @@ -55,7 +55,7 @@ module("portmanager", package.seeall); --- Public API function activate_service(service_name) - local service_info = services[service_name]; + local service_info = services[service_name][1]; if not service_info then return nil, "Unknown service: "..service_name; end @@ -102,6 +102,7 @@ function activate_service(service_name) end end log("info", "Activated service '%s'", service_name); + return true; end function deactivate(service_name) @@ -118,16 +119,35 @@ function deactivate(service_name) end function register_service(service_name, service_info) - services[service_name] = service_info; + table.insert(services[service_name], service_info); - if not active_services[service_name] then - activate_service(service_name); + if not active_services:get(service_name) then + log("debug", "No active service for %s, activating...", service_name); + local ok, err = activate_service(service_name); + if not ok then + log("error", "Failed to activate service '%s': %s", service_name, err or "unknown error"); + end end fire_event("service-added", { name = service_name, service = service_info }); return true; end +function unregister_service(service_name, service_info) + local service_info_list = services[service_name]; + for i, service in ipairs(service_info_list) do + if service == service_info then + table.remove(service_info_list, i); + end + end + if active_services[service_name] == service_info then + deactivate(service_name); + if #service_info_list > 0 then -- Other services registered with this name + activate(service_name); -- Re-activate with the next available one + end + end +end + function get_service(service_name) return services[service_name]; end -- cgit v1.2.3 From 1ab1ddd3ee3f8a93b2d48d6a93840ea1ddaa6cb9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 14 Mar 2012 21:39:45 +0000 Subject: portmanager: Support item-added/net-provider (global and shared modules only!) --- core/portmanager.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 30597628..2870815c 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -52,6 +52,15 @@ end module("portmanager", package.seeall); +prosody.events.add_handler("item-added/net-provider", function (event) + local item = event.item; + register_service(item.name, item); +end); +prosody.events.add_handler("item-removed/net-provider", function (event) + local item = event.item; + unregister_service(item.name, item); +end); + --- Public API function activate_service(service_name) -- cgit v1.2.3 From a156128a90397ec050ca3c2296d6d23e7308f3e6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 14 Mar 2012 21:40:14 +0000 Subject: portmanager: Fix log message when multiple services are configured to use the same port --- core/portmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 2870815c..a7ba8a49 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -95,7 +95,7 @@ function activate_service(service_name) for interface in bind_interfaces do for port in bind_ports do if not service_info.multiplex and #active_services:search(nil, interface, port) > 0 then - log("error", "Multiple services configured to listen on the same port: %s, %s", table.concat(active_services:search(nil, interface, port), ", "), service_name); + 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 "", service_name or ""); else local handler, err = server.addserver(interface, port, listener, mode, ssl); if not handler then -- cgit v1.2.3 From 591bcc96e66cb00ac85d416899a61733d12cb6f0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 14 Mar 2012 23:44:24 +0000 Subject: portmanager: Fire service-removed on unregister --- core/portmanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index a7ba8a49..605e1e30 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -155,6 +155,7 @@ function unregister_service(service_name, service_info) activate(service_name); -- Re-activate with the next available one end end + fire_event("service-removed", { name = service_name, service = service_info }); end function get_service(service_name) -- cgit v1.2.3 From 0ae4e4464d090e98bd7daedae45320222a456599 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 15 Mar 2012 02:56:44 +0000 Subject: portmanager: Allow services to specify their config option prefix --- core/portmanager.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 605e1e30..a87e14eb 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -68,19 +68,23 @@ function activate_service(service_name) if not service_info then return nil, "Unknown service: "..service_name; end + + local config_prefix = (service_info.config_prefix or service_name).."_"; + if config_prefix == "_" then + config_prefix = ""; + end - local bind_interfaces = set.new(config.get("*", service_name.."_interfaces") - or config.get("*", service_name.."_interface") -- COMPAT w/pre-0.9 + local bind_interfaces = set.new(config.get("*", config_prefix.."interfaces") + or config.get("*", config_prefix.."interface") -- COMPAT w/pre-0.9 or (service_info.private and default_local_interfaces) or config.get("*", "interfaces") or config.get("*", "interface") -- COMPAT w/pre-0.9 or service_info.default_interface -- COMPAT w/pre0.9 or default_interfaces); - local bind_ports = set.new(config.get("*", service_name.."_ports") - or (service_info.multiplex and config.get("*", "ports")) or service_info.default_ports or {service_info.default_port}); + local bind_ports = set.new(config.get("*", config_prefix.."ports") local listener = service_info.listener; local mode = listener.default_mode or "*a"; -- cgit v1.2.3 From 917df51c8fd55aae373ddb7e6a6df40b7d336fe8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 15 Mar 2012 03:02:09 +0000 Subject: portmanager: Fix pre-0.9 compatibility by taking default_interface and default_port from the listener instead of service table --- core/portmanager.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index a87e14eb..a7c3c44e 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -69,6 +69,8 @@ function activate_service(service_name) return nil, "Unknown service: "..service_name; end + local listener = service_info.listener; + local config_prefix = (service_info.config_prefix or service_name).."_"; if config_prefix == "_" then config_prefix = ""; @@ -79,14 +81,13 @@ function activate_service(service_name) or (service_info.private and default_local_interfaces) or config.get("*", "interfaces") or config.get("*", "interface") -- COMPAT w/pre-0.9 - or service_info.default_interface -- COMPAT w/pre0.9 + or listener.default_interface -- COMPAT w/pre0.9 or default_interfaces); - or service_info.default_ports - or {service_info.default_port}); local bind_ports = set.new(config.get("*", config_prefix.."ports") + or service_info.default_ports + or {listener.default_port}); -- COMPAT w/pre-0.9 - local listener = service_info.listener; local mode = listener.default_mode or "*a"; local ssl; if service_info.encryption == "ssl" then -- cgit v1.2.3 From 477f505f4861870fff596c3751d249ecd1132164 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 15 Mar 2012 03:02:36 +0000 Subject: portmanager: Remove check for service_info.multiplex (now implemented in mod_net_multiplex) --- core/portmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index a7c3c44e..b4ceaef9 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -99,7 +99,7 @@ function activate_service(service_name) for interface in bind_interfaces do for port in bind_ports do - if not service_info.multiplex and #active_services:search(nil, interface, port) > 0 then + if #active_services:search(nil, interface, port) > 0 then 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 "", service_name or ""); else local handler, err = server.addserver(interface, port, listener, mode, ssl); -- cgit v1.2.3 From 9f7aa91f8f8bfa6c16a5d1e161fce292c190e103 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 15 Mar 2012 03:02:51 +0000 Subject: portmanager: Add get_registered_services() to the public API --- core/portmanager.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index b4ceaef9..914a8e2f 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -171,4 +171,8 @@ function get_active_services(...) return active_services; end +function get_registered_services() + return services; +end + return _M; -- cgit v1.2.3 From cd9f57bc12a5c99c86465c7ee209851081593161 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 15 Mar 2012 16:29:30 +0000 Subject: portmanager: Support 'default_port' in service options --- core/portmanager.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 914a8e2f..c5bb936a 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -86,7 +86,9 @@ function activate_service(service_name) local bind_ports = set.new(config.get("*", config_prefix.."ports") or service_info.default_ports - or {listener.default_port}); -- COMPAT w/pre-0.9 + or {service_info.default_port + or listener.default_port -- COMPAT w/pre-0.9 + }); local mode = listener.default_mode or "*a"; local ssl; -- cgit v1.2.3 From 1dea1062ea7a5a446bd72b82bab5ce373294e9d8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Apr 2012 16:00:20 +0100 Subject: portmanager: Add get_service_at(interface, port) and close(interface, port) --- core/portmanager.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index c5bb936a..da238dba 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -126,9 +126,7 @@ function deactivate(service_name) if not active then return; end for interface, ports in pairs(active) do for port, active_service in pairs(ports) do - active_service:close(); - active_services:remove(service_name, interface, port, active_service); - log("debug", "Removed listening service %s from [%s]:%d", service_name, interface, port); + close(interface, port); end end log("info", "Deactivated service '%s'", service_name); @@ -165,6 +163,22 @@ function unregister_service(service_name, service_info) fire_event("service-removed", { name = service_name, service = service_info }); end +function close(interface, port) + local service, server = get_service_at(interface, port); + if not service then + return false, "port-not-open"; + end + server:close(); + active_services:remove(service.name, interface, port); + log("debug", "Removed listening service %s from [%s]:%d", service.name, interface, port); + return true; +end + +function get_service_at(interface, port) + local data = active_services:search(nil, interface, port)[1][1]; + return data.service, data.server; +end + function get_service(service_name) return services[service_name]; end -- cgit v1.2.3 From 8d878575e6834a32a3170618c66655b6c5c1ab16 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 25 Apr 2012 14:53:54 +0200 Subject: portmanager: Fix selecting bind_interfaces from pre-0.9 config options. --- core/portmanager.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index da238dba..e2994308 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -76,13 +76,14 @@ function activate_service(service_name) config_prefix = ""; end - local bind_interfaces = set.new(config.get("*", config_prefix.."interfaces") + local bind_interfaces = config.get("*", config_prefix.."interfaces") or config.get("*", config_prefix.."interface") -- COMPAT w/pre-0.9 or (service_info.private and default_local_interfaces) or config.get("*", "interfaces") or config.get("*", "interface") -- COMPAT w/pre-0.9 or listener.default_interface -- COMPAT w/pre0.9 - or default_interfaces); + or default_interfaces + bind_interfaces = set.new(type(bind_interfaces)~="table" and {bind_interfaces} or bind_interfaces); local bind_ports = set.new(config.get("*", config_prefix.."ports") or service_info.default_ports -- cgit v1.2.3 From d5ba56353d042b7bb23162ce038a944085d47e08 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 01:27:02 +0100 Subject: portmanager: Explicitly import some libraries --- core/portmanager.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index e2994308..afcfb797 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -1,5 +1,11 @@ +local config = require "core.configmanager"; +local server = require "net.server"; +local log = require "util.logger".init("portmanager"); local multitable = require "util.multitable"; +local set = require "util.set"; + +local prosody = prosody; local fire_event = prosody.events.fire_event; --- Config -- cgit v1.2.3 From ed03e1adb93034e888558abebd257faf41cb3ad3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 01:27:15 +0100 Subject: portmanager: Add module() definition --- core/portmanager.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index afcfb797..8f26c57e 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -8,6 +8,8 @@ local set = require "util.set"; local prosody = prosody; local fire_event = prosody.events.fire_event; +module "portmanager"; + --- Config local default_interfaces = { "*" }; -- cgit v1.2.3 From 7a8047ba3e200045b078c8818b50869a3df9ba88 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 01:27:46 +0100 Subject: portmanager: Rename activate_service() to activate() (to match deactivate()) --- core/portmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 8f26c57e..337b8f4b 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -71,7 +71,7 @@ end); --- Public API -function activate_service(service_name) +function activate(service_name) local service_info = services[service_name][1]; if not service_info then return nil, "Unknown service: "..service_name; @@ -146,7 +146,7 @@ function register_service(service_name, service_info) if not active_services:get(service_name) then log("debug", "No active service for %s, activating...", service_name); - local ok, err = activate_service(service_name); + local ok, err = activate(service_name); if not ok then log("error", "Failed to activate service '%s': %s", service_name, err or "unknown error"); end -- cgit v1.2.3 From 7813edf719386c2c108d5415f8be2af11e6baa7c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 01:44:08 +0100 Subject: portmanager: Fix breakage (import ALL the functions) --- core/portmanager.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 337b8f4b..3bd143ef 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -5,6 +5,10 @@ local log = require "util.logger".init("portmanager"); local multitable = require "util.multitable"; local set = require "util.set"; +local table, package = table, package; +local setmetatable, rawset, rawget = setmetatable, rawset, rawget; +local type = type; + local prosody = prosody; local fire_event = prosody.events.fire_event; @@ -58,8 +62,6 @@ local function error_to_friendly_message(service_name, port, err) return friendly_message; end -module("portmanager", package.seeall); - prosody.events.add_handler("item-added/net-provider", function (event) local item = event.item; register_service(item.name, item); -- cgit v1.2.3 From 6521b0e6612036ceb4d4db1a8e6a99ac3d3a4ec2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 18:45:04 +0100 Subject: portmanager: Ensure port is always a number (thanks Zash) --- core/portmanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 3bd143ef..5f53b61c 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -112,6 +112,7 @@ function activate(service_name) for interface in bind_interfaces do for port in bind_ports do + port = tonumber(port); if #active_services:search(nil, interface, port) > 0 then 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 "", service_name or ""); else -- cgit v1.2.3 From 53ab26d52831cce03092a0c120cf95276c52ac28 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 19:38:51 +0100 Subject: portmanager: Import tonumber (thanks Zash) --- core/portmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/portmanager.lua') diff --git a/core/portmanager.lua b/core/portmanager.lua index 5f53b61c..fed35987 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -7,7 +7,7 @@ local set = require "util.set"; local table, package = table, package; local setmetatable, rawset, rawget = setmetatable, rawset, rawget; -local type = type; +local type, tonumber = type, tonumber; local prosody = prosody; local fire_event = prosody.events.fire_event; -- cgit v1.2.3