main.lua
changeset 20 6885fd2cf51f
parent 18 ae161e907149
child 30 bcf539295f2d
equal deleted inserted replaced
19:65622bf34afc 20:6885fd2cf51f
     8 function log(type, area, message)
     8 function log(type, area, message)
     9 	print(type, area, message);
     9 	print(type, area, message);
    10 end
    10 end
    11  
    11  
    12 require "core.stanza_dispatch"
    12 require "core.stanza_dispatch"
    13 local init_xmlhandlers = require "core.xmlhandlers"
    13 require "core.xmlhandlers"
    14 require "core.rostermanager"
    14 require "core.rostermanager"
    15 require "core.offlinemessage"
    15 require "core.offlinemessage"
    16 require "core.usermanager"
    16 require "core.usermanager"
    17 require "util.stanza"
    17 require "util.stanza"
    18 require "util.jid"
    18 require "util.jid"
    22 local t_concat = table.concat;
    22 local t_concat = table.concat;
    23 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
    23 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
    24 local m_random = math.random;
    24 local m_random = math.random;
    25 local format = string.format;
    25 local format = string.format;
    26 local st = stanza;
    26 local st = stanza;
       
    27 local init_xmlhandlers = xmlhandlers.init_xmlhandlers;
    27 ------------------------------
    28 ------------------------------
    28 
    29 
    29 sessions = {};
    30 sessions = {};
    30 hosts = 	{ 
    31 hosts = 	{ 
    31 			["localhost"] = 	{
    32 			["localhost"] = 	{
   163 
   164 
   164 function disconnect(conn, err)
   165 function disconnect(conn, err)
   165 	sessions[conn].disconnect(err);
   166 	sessions[conn].disconnect(err);
   166 end
   167 end
   167 
   168 
   168 print("ssl_ctx:", type(ssl_ctx));
       
   169 
       
   170 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 }) --]][][[]][];
   169 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 }) --]][][[]][];
   171 
   170 
   172 
   171 
   173 local protected_handler = function (...) local success, ret = pcall(handler, ...); if not success then print("ERROR on "..tostring((select(1, ...)))..": "..ret); end end;
   172 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;
   174 local protected_disconnect = function (...) local success, ret = pcall(disconnect, ...); if not success then print("ERROR on "..tostring((select(1, ...))).." disconnect: "..ret); end end;
   173 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;
   175 
   174 
   176 print( server.add( { listener = protected_handler, disconnect = protected_disconnect }, 5222, "*", 1, nil ) )    -- server.add will send a status message
   175 server.add( { listener = protected_handler, disconnect = protected_disconnect }, 5222, "*", 1, nil ) -- server.add will send a status message
   177 print( server.add( { listener = protected_handler, disconnect = protected_disconnect }, 5223, "*", 1, ssl_ctx ) )    -- server.add will send a status message
   176 server.add( { listener = protected_handler, disconnect = protected_disconnect }, 5223, "*", 1, ssl_ctx ) -- server.add will send a status message
   178 
   177 
   179 server.loop();
   178 server.loop();