-local server = require "net.server"
-
-require "util.dependencies"
-
--- Maps connections to sessions --
-sessions = {};
-hosts = {};
-
--- Load and initialise core modules --
-
-require "util.import"
-require "core.xmlhandlers"
-require "core.rostermanager"
-require "core.offlinemessage"
-require "core.eventmanager"
-require "core.hostmanager"
-require "core.modulemanager"
-require "core.usermanager"
-require "core.sessionmanager"
-require "core.stanza_router"
-
---[[
-pcall(require, "remdebug.engine");
-if remdebug then remdebug.engine.start() end
-]]
-
-local cl = require "net.connlisteners";
-
-require "util.stanza"
-require "util.jid"
-
-------------------------------------------------------------------------
-
+function load_libraries()
+ -- Initialize logging
+ require "core.loggingmanager"
+
+ -- Check runtime dependencies
+ require "util.dependencies"
+
+ -- Load socket framework
+ server = require "net.server"
+end
+
+function init_global_state()
+ bare_sessions = {};
+ full_sessions = {};
+ hosts = {};
+
+ -- Global 'prosody' object
+ prosody = {};
+ local prosody = prosody;
+
+ prosody.bare_sessions = bare_sessions;
+ prosody.full_sessions = full_sessions;
+ prosody.hosts = hosts;
+
+ prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR,
+ plugins = CFG_PLUGINDIR, data = CFG_DATADIR };
+
+ prosody.arg = _G.arg;
+
+ prosody.events = require "util.events".new();
+
+ prosody.platform = "unknown";
+ if os.getenv("WINDIR") then
+ prosody.platform = "windows";
+ elseif package.config:sub(1,1) == "/" then
+ prosody.platform = "posix";
+ end
+
+ prosody.installed = nil;
+ if CFG_SOURCEDIR and (prosody.platform == "windows" or CFG_SOURCEDIR:match("^/")) then
+ prosody.installed = true;
+ end
+
+ -- Function to reload the config file
+ function prosody.reload_config()
+ log("info", "Reloading configuration file");
+ prosody.events.fire_event("reloading-config");
+ local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua");
+ if not ok then
+ if level == "parser" then
+ log("error", "There was an error parsing the configuration file: %s", tostring(err));
+ elseif level == "file" then
+ log("error", "Couldn't read the config file when trying to reload: %s", tostring(err));
+ end
+ end
+ return ok, (err and tostring(level)..": "..tostring(err)) or nil;
+ end