Comparison

main.lua @ 218:1263896ab2f1

Reworked the way lxmppd.cfg is used
author Waqas Hussain <waqas20@gmail.com>
date Thu, 06 Nov 2008 16:52:39 +0500
parent 207:90c387884234
child 224:4b1e30ddd2bb
comparison
equal deleted inserted replaced
217:d522f3a25dda 218:1263896ab2f1
11 11
12 dofile "lxmppd.cfg" 12 dofile "lxmppd.cfg"
13 13
14 -- Maps connections to sessions -- 14 -- Maps connections to sessions --
15 sessions = {}; 15 sessions = {};
16 hosts = {};
17
18 if config.hosts and #config.hosts > 0 then
19 for _, host in pairs(config.hosts) do
20 hosts[host] = {type = "local", connected = true, sessions = {}};
21 end
22 else error("No hosts defined in the configuration file"); end
16 23
17 -- Load and initialise core modules -- 24 -- Load and initialise core modules --
18 25
19 require "util.import" 26 require "util.import"
20 require "core.xmlhandlers" 27 require "core.xmlhandlers"
29 require "util.stanza" 36 require "util.stanza"
30 require "util.jid" 37 require "util.jid"
31 38
32 ------------------------------------------------------------------------ 39 ------------------------------------------------------------------------
33 40
34 -- Locals for faster access -- 41 -- Initialise modules
35 local t_insert = table.insert; 42 if config.modules and #config.modules > 0 then
36 local t_concat = table.concat; 43 for _, module in pairs(config.modules) do
37 local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end 44 modulemanager.load(module);
38 local m_random = math.random; 45 end
39 local format = string.format; 46 else error("No modules enabled in the configuration file"); end
40 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; --import("core.sessionmanager", "new_session", "destroy_session");
41 local st = stanza;
42 ------------------------------
43 47
44 local hosts, sessions = hosts, sessions; 48 -- setup error handling
45
46 -- Initialise modules
47 modulemanager.loadall();
48
49 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 }) --]][][[]][]; 49 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 }) --]][][[]][];
50
51 50
52 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; 51 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;
53 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; 52 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;
54 53
55 start("xmppclient", { ssl = ssl_ctx }) 54 -- start listening on sockets
56 start("xmppserver", { ssl = ssl_ctx }) 55 start("xmppclient", { ssl = config.ssl_ctx })
56 start("xmppserver", { ssl = config.ssl_ctx })
57 57
58 server.loop(); 58 server.loop();