+ print("\n");
+ print("**************************");
+ if level == "parser" then
+ print("A problem occured while reading the config file "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
+ local err_line, err_message = tostring(err):match("%[string .-%]:(%d*): (.*)");
+ print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err)));
+ print("");
+ elseif level == "file" then
+ print("Prosody was unable to find the configuration file.");
+ print("We looked for: "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
+ print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
+ print("Copy or rename it to prosody.cfg.lua and edit as necessary.");
+ end
+ print("More help on configuring Prosody can be found at http://prosody.im/doc/configure");
+ print("Good luck!");
+ print("**************************");
+ print("");
+ os.exit(1);
+ end
+end
+
+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");