aboutsummaryrefslogtreecommitdiffstats
path: root/core/portmanager.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-08-20 13:05:22 +0200
committerKim Alvefur <zash@zash.se>2015-08-20 13:05:22 +0200
commit6ef7c4d80892f486d71e660b054bdfdb993c8528 (patch)
tree103fd7d9396b60b9f76071a009c54d3ca9d35744 /core/portmanager.lua
parenta9029bd099734436154fc4e794d3b958e54d1943 (diff)
parentd32f36b2817739d7f8d5f1208a3009b7be379562 (diff)
downloadprosody-6ef7c4d80892f486d71e660b054bdfdb993c8528.tar.gz
prosody-6ef7c4d80892f486d71e660b054bdfdb993c8528.zip
Merge 0.10->trunk
Diffstat (limited to 'core/portmanager.lua')
-rw-r--r--core/portmanager.lua52
1 files changed, 34 insertions, 18 deletions
diff --git a/core/portmanager.lua b/core/portmanager.lua
index e800cf36..9f95077a 100644
--- a/core/portmanager.lua
+++ b/core/portmanager.lua
@@ -14,7 +14,7 @@ local type, tonumber, tostring, ipairs = type, tonumber, tostring, ipairs;
local prosody = prosody;
local fire_event = prosody.events.fire_event;
-module "portmanager";
+local _ENV = nil;
--- Config
@@ -63,18 +63,9 @@ local function error_to_friendly_message(service_name, port, err) --luacheck: ig
return friendly_message;
end
-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_name)
+local function activate(service_name)
local service_info = services[service_name][1];
if not service_info then
return nil, "Unknown service: "..service_name;
@@ -151,7 +142,9 @@ function activate(service_name)
return true;
end
-function deactivate(service_name, service_info)
+local close; -- forward declaration
+
+local function deactivate(service_name, service_info)
for name, interface, port, n, active_service --luacheck: ignore 213/name 213/n
in active_services:iter(service_name or service_info and service_info.name, nil, nil, nil) do
if service_info == nil or active_service.service == service_info then
@@ -161,7 +154,7 @@ function deactivate(service_name, service_info)
log("info", "Deactivated service '%s'", service_name or service_info.name);
end
-function register_service(service_name, service_info)
+local function register_service(service_name, service_info)
table.insert(services[service_name], service_info);
if not active_services:get(service_name) then
@@ -176,7 +169,7 @@ function register_service(service_name, service_info)
return true;
end
-function unregister_service(service_name, service_info)
+local function unregister_service(service_name, service_info)
log("debug", "Unregistering service: %s", service_name);
local service_info_list = services[service_name];
for i, service in ipairs(service_info_list) do
@@ -191,6 +184,8 @@ function unregister_service(service_name, service_info)
fire_event("service-removed", { name = service_name, service = service_info });
end
+local get_service_at -- forward declaration
+
function close(interface, port)
local service, service_server = get_service_at(interface, port);
if not service then
@@ -207,16 +202,37 @@ function get_service_at(interface, port)
return data.service, data.server;
end
-function get_service(service_name)
+local function get_service(service_name)
return (services[service_name] or {})[1];
end
-function get_active_services()
+local function get_active_services()
return active_services;
end
-function get_registered_services()
+local function get_registered_services()
return services;
end
-return _M;
+-- Event handlers
+
+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);
+
+return {
+ activate = activate;
+ deactivate = deactivate;
+ register_service = register_service;
+ unregister_service = unregister_service;
+ close = close;
+ get_service_at = get_service_at;
+ get_service = get_service;
+ get_active_services = get_active_services;
+ get_registered_services = get_registered_services;
+};