+ local cl = require "net.connlisteners";
+ -- start listening on sockets
+ function net_activate_ports(option, listener, default, conntype)
+ if not cl.get(listener) then return; end
+ local ports = config.get("*", "core", option.."_ports") or default;
+ if type(ports) == "number" then ports = {ports} end;
+
+ if type(ports) ~= "table" then
+ log("error", "core."..option.." is not a table");
+ else
+ for _, port in ipairs(ports) do
+ if type(port) ~= "number" then
+ log("error", "Non-numeric "..option.."_ports: "..tostring(port));
+ else
+ cl.start(listener, {
+ ssl = conntype ~= "tcp" and global_ssl_ctx,
+ port = port,
+ interface = config.get("*", "core", option.."_interface")
+ or cl.get(listener).default_interface
+ or config.get("*", "core", "interface"),
+ type = conntype
+ });
+ end
+ end
+ end
+ end
+
+ net_activate_ports("c2s", "xmppclient", {5222}, (global_ssl_ctx and "tls") or "tcp");
+ net_activate_ports("s2s", "xmppserver", {5269}, "tcp");
+ net_activate_ports("component", "xmppcomponent", {}, "tcp");
+ net_activate_ports("legacy_ssl", "xmppclient", {}, "ssl");
+ net_activate_ports("console", "console", {5582}, "tcp");
+
+ prosody.start_time = os.time();
+end
+
+function init_global_protection()
+ -- Catch global accesses --
+ local locked_globals_mt = { __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end, __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end }
+
+ function prosody.unlock_globals()
+ setmetatable(_G, nil);
+ end
+
+ function prosody.lock_globals()
+ setmetatable(_G, locked_globals_mt);
+ end