12 if os.getenv("HOME") then
13 CFG_SOURCEDIR = CFG_SOURCEDIR:gsub("^~", os.getenv("HOME"));
15 package.path = CFG_SOURCEDIR.."/?.lua;"..package.path
16 package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath
20 if os.getenv("HOME") then
21 CFG_CONFIGDIR = CFG_CONFIGDIR:gsub("^~", os.getenv("HOME"));
26 if os.getenv("HOME") then
27 CFG_PLUGINDIR = CFG_PLUGINDIR:gsub("^~", os.getenv("HOME"));
31 -- Required to be able to find packages installed with luarocks
32 pcall(require, "luarocks.require")
35 config = require "core.configmanager"
36 log = require "util.logger".init("general");
39 -- TODO: Check for other formats when we add support for them
40 -- Use lfs? Make a new conf/ dir?
41 local ok, err = config.load((CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
43 log("error", "Couldn't load config file: %s", err);
44 log("info", "Falling back to old config file format...")
45 ok, err = pcall(dofile, "lxmppd.cfg");
47 log("error", "Old config format loading failed too: %s", err);
49 for _, host in ipairs(_G.config.hosts) do
50 config.set(host, "core", "defined", true);
53 config.set("*", "core", "modules_enabled", _G.config.modules);
54 config.set("*", "core", "ssl", _G.config.ssl_ctx);
59 require "util.datamanager".set_data_path(config.get("*", "core", "data_path") or "data");
61 local server = require "net.server"
63 require "util.dependencies"
65 -- Maps connections to sessions --
69 local defined_hosts = config.getconfig();
71 for host, host_config in pairs(defined_hosts) do
72 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then
73 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
77 -- Load and initialise core modules --
80 require "core.xmlhandlers"
81 require "core.rostermanager"
82 require "core.offlinemessage"
83 require "core.modulemanager"
84 require "core.usermanager"
85 require "core.sessionmanager"
86 require "core.stanza_router"
89 pcall(require, "remdebug.engine");
90 if remdebug then remdebug.engine.start() end
93 local start = require "net.connlisteners".start;
97 ------------------------------------------------------------------------
101 for host in pairs(hosts) do
103 local modules_enabled = config.get(host, "core", "modules_enabled");
104 if modules_enabled then
105 for _, module in pairs(modules_enabled) do
106 modulemanager.load(host, module);
112 -- setup error handling
113 setmetatable(_G, { __index = function (t, k) print("WARNING: ATTEMPT TO READ A NIL GLOBAL!!!", k); error("Attempt to read a non-existent global. Naughty boy.", 2); end, __newindex = function (t, k, v) print("ATTEMPT TO SET A GLOBAL!!!!", tostring(k).." = "..tostring(v)); error("Attempt to set a global. Naughty boy.", 2); end }) --]][][[]][];
115 local protected_handler = function (conn, data, err) local success, ret = pcall(handler, conn, data, err); if not success then print("ERROR on "..tostring(conn)..": "..ret); conn:close(); end end;
116 local protected_disconnect = function (conn, err) local success, ret = pcall(disconnect, conn, err); if not success then print("ERROR on "..tostring(conn).." disconnect: "..ret); conn:close(); end end;
119 local global_ssl_ctx = config.get("*", "core", "ssl");
120 if global_ssl_ctx then
121 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
122 setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
125 -- start listening on sockets
126 start("xmppclient", { ssl = global_ssl_ctx })
127 start("xmppserver", { ssl = global_ssl_ctx })
129 if config.get("*", "core", "console_enabled") then
133 modulemanager.fire_event("server-started");