comparison main.lua @ 403:da92afa267cf

Merging with main branch.
author Tobias Markmann <tm@ayena.de>
date Sun, 23 Nov 2008 20:44:48 +0100
parents 32b586d9e915
children 11f176cae9da
comparison
equal deleted inserted replaced
402:50f1c09541cd 403:da92afa267cf
2 2
3 local server = require "net.server" 3 local server = require "net.server"
4 require "lxp" 4 require "lxp"
5 require "socket" 5 require "socket"
6 require "ssl" 6 require "ssl"
7 local config = require "core.configmanager"
7 8
8 function log(type, area, message) 9 log = require "util.logger".init("general");
9 print(type, area, message); 10
11 do
12 -- TODO: Check for other formats when we add support for them
13 -- Use lfs? Make a new conf/ dir?
14 local ok, err = config.load("lxmppd.cfg.lua");
15 if not ok then
16 log("error", "Couldn't load config file: %s", err);
17 log("info", "Falling back to old config file format...")
18 ok, err = pcall(dofile, "lxmppd.cfg");
19 if not ok then
20 log("error", "Old config format loading failed too: %s", err);
21 else
22 for _, host in ipairs(_G.config.hosts) do
23 config.set(host, "core", "defined", true);
24 end
25
26 config.set("*", "core", "modules_enabled", _G.config.modules);
27 config.set("*", "core", "ssl", _G.config.ssl_ctx);
28 end
29 end
10 end 30 end
11
12 dofile "lxmppd.cfg"
13 31
14 -- Maps connections to sessions -- 32 -- Maps connections to sessions --
15 sessions = {}; 33 sessions = {};
16 hosts = {}; 34 hosts = {};
17 35
18 if config.hosts and #config.hosts > 0 then 36 local defined_hosts = config.getconfig();
19 for _, host in pairs(config.hosts) do 37
38 for host, host_config in pairs(defined_hosts) do
39 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then
20 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} }; 40 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
21 end 41 end
22 else error("No hosts defined in the configuration file"); end 42 end
23 43
24 -- Load and initialise core modules -- 44 -- Load and initialise core modules --
25 45
26 require "util.import" 46 require "util.import"
27 require "core.xmlhandlers" 47 require "core.xmlhandlers"
30 require "core.modulemanager" 50 require "core.modulemanager"
31 require "core.usermanager" 51 require "core.usermanager"
32 require "core.sessionmanager" 52 require "core.sessionmanager"
33 require "core.stanza_router" 53 require "core.stanza_router"
34 54
55 --[[
35 pcall(require, "remdebug.engine"); 56 pcall(require, "remdebug.engine");
36 if remdebug then remdebug.engine.start() end 57 if remdebug then remdebug.engine.start() end
58 ]]
37 59
38 local start = require "net.connlisteners".start; 60 local start = require "net.connlisteners".start;
39 require "util.stanza" 61 require "util.stanza"
40 require "util.jid" 62 require "util.jid"
41 63
42 ------------------------------------------------------------------------ 64 ------------------------------------------------------------------------
43 65
44 -- Initialise modules 66 -- Initialise modules
45 if config.modules and #config.modules > 0 then 67 local modules_enabled = config.get("*", "core", "modules_enabled");
46 for _, module in pairs(config.modules) do 68 if modules_enabled then
69 for _, module in pairs(modules_enabled) do
47 modulemanager.load(module); 70 modulemanager.load(module);
48 end 71 end
49 else error("No modules enabled in the configuration file"); end 72 end
50 73
51 -- setup error handling 74 -- setup error handling
52 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 }) --]][][[]][]; 75 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 }) --]][][[]][];
53 76
54 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; 77 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;
55 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; 78 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;
56 79
80
81 local global_ssl_ctx = config.get("*", "core", "ssl");
82 if global_ssl_ctx then
83 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
84 setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
85 end
86
57 -- start listening on sockets 87 -- start listening on sockets
58 start("xmppclient", { ssl = config.ssl_ctx }) 88 start("xmppclient", { ssl = global_ssl_ctx })
59 start("xmppserver", { ssl = config.ssl_ctx }) 89 start("xmppserver", { ssl = global_ssl_ctx })
90
91 if config.get("*", "core", "console_enabled") then
92 start("console")
93 end
94
95 modulemanager.fire_event("server-started");
60 96
61 server.loop(); 97 server.loop();