prosody

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

mercurial