main.lua

changeset 475
fe861de7a4fc
parent 474
666e22848890
parent 463
a2452d3bd828
child 476
4744735a0a5e
equal deleted inserted replaced
474:666e22848890 475:fe861de7a4fc
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 local server = require "net.server"
28
29 require "util.dependencies"
30
31 -- Maps connections to sessions --
32 sessions = {};
33 hosts = {};
34
35 local defined_hosts = config.getconfig();
36
37 for host, host_config in pairs(defined_hosts) do
38 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then
39 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
40 end
41 end
42
43 -- Load and initialise core modules --
44
45 require "util.import"
46 require "core.xmlhandlers"
47 require "core.rostermanager"
48 require "core.offlinemessage"
49 require "core.modulemanager"
50 require "core.usermanager"
51 require "core.sessionmanager"
52 require "core.stanza_router"
53
54 --[[
55 pcall(require, "remdebug.engine");
56 if remdebug then remdebug.engine.start() end
57 ]]
58
59 local start = require "net.connlisteners".start;
60 require "util.stanza"
61 require "util.jid"
62
63 ------------------------------------------------------------------------
64
65 -- Initialise modules
66
67 for host in pairs(hosts) do
68 if host ~= "*" then
69 local modules_enabled = config.get(host, "core", "modules_enabled");
70 if modules_enabled then
71 for _, module in pairs(modules_enabled) do
72 modulemanager.load(host, module);
73 end
74 end
75 end
76 end
77
78 -- setup error handling
79 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 }) --]][][[]][];
80
81 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;
82 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;
83
84
85 local global_ssl_ctx = config.get("*", "core", "ssl");
86 if global_ssl_ctx then
87 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
88 setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
89 end
90
91 -- start listening on sockets
92 start("xmppclient", { ssl = global_ssl_ctx })
93 start("xmppserver", { ssl = global_ssl_ctx })
94
95 if config.get("*", "core", "console_enabled") then
96 start("console")
97 end
98
99 modulemanager.fire_event("server-started");
100
101 server.loop();

mercurial