main.lua

changeset 459
6ac173c88834
parent 458
ac17926c3282
parent 455
2eeae9c314b0
child 460
95d2001d0aab
equal deleted inserted replaced
458:ac17926c3282 459:6ac173c88834
1 pcall(require, "luarocks.require")
2
3 config = require "core.configmanager"
4 log = require "util.logger".init("general");
5
6 do
7 -- TODO: Check for other formats when we add support for them
8 -- Use lfs? Make a new conf/ dir?
9 local ok, err = config.load("lxmppd.cfg.lua");
10 if not ok then
11 log("error", "Couldn't load config file: %s", err);
12 log("info", "Falling back to old config file format...")
13 ok, err = pcall(dofile, "lxmppd.cfg");
14 if not ok then
15 log("error", "Old config format loading failed too: %s", err);
16 else
17 for _, host in ipairs(_G.config.hosts) do
18 config.set(host, "core", "defined", true);
19 end
20
21 config.set("*", "core", "modules_enabled", _G.config.modules);
22 config.set("*", "core", "ssl", _G.config.ssl_ctx);
23 end
24 end
25 end
26
27 require "util.datamanager".set_data_path(config.get("*", "core", "data_path") or "data");
28
29 local server = require "net.server"
30
31 require "util.dependencies"
32
33 -- Maps connections to sessions --
34 sessions = {};
35 hosts = {};
36
37 local defined_hosts = config.getconfig();
38
39 for host, host_config in pairs(defined_hosts) do
40 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then
41 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
42 end
43 end
44
45 -- Load and initialise core modules --
46
47 require "util.import"
48 require "core.xmlhandlers"
49 require "core.rostermanager"
50 require "core.offlinemessage"
51 require "core.modulemanager"
52 require "core.usermanager"
53 require "core.sessionmanager"
54 require "core.stanza_router"
55
56 --[[
57 pcall(require, "remdebug.engine");
58 if remdebug then remdebug.engine.start() end
59 ]]
60
61 local start = require "net.connlisteners".start;
62 require "util.stanza"
63 require "util.jid"
64
65 ------------------------------------------------------------------------
66
67 -- Initialise modules
68
69 for host in pairs(hosts) do
70 if host ~= "*" then
71 local modules_enabled = config.get(host, "core", "modules_enabled");
72 if modules_enabled then
73 for _, module in pairs(modules_enabled) do
74 modulemanager.load(host, module);
75 end
76 end
77 end
78 end
79
80 -- setup error handling
81 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 }) --]][][[]][];
82
83 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;
84 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;
85
86
87 local global_ssl_ctx = config.get("*", "core", "ssl");
88 if global_ssl_ctx then
89 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
90 setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
91 end
92
93 -- start listening on sockets
94 start("xmppclient", { ssl = global_ssl_ctx })
95 start("xmppserver", { ssl = global_ssl_ctx })
96
97 if config.get("*", "core", "console_enabled") then
98 start("console")
99 end
100
101 modulemanager.fire_event("server-started");
102
103 server.loop();

mercurial