X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=prosody;h=517762f3c438d4d7061739f7a8f3ec95e86d3175;hb=67972219b74e6315bcd23966e3570594e47456e3;hp=4b016e504e3d9c60c60670704027c2ba8f6f974e;hpb=8a0e5ce684e22190a6779e305db39db0a88a2e9c;p=prosody.git diff --git a/prosody b/prosody index 4b016e50..517762f3 100755 --- a/prosody +++ b/prosody @@ -1,7 +1,7 @@ #!/usr/bin/env lua -- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. @@ -29,6 +29,10 @@ if CFG_DATADIR then end end +-- Global 'prosody' object +prosody = { events = require "util.events".new(); }; +local prosody = prosody; + -- Load the config-parsing module config = require "core.configmanager" @@ -120,15 +124,38 @@ function sandbox_require() end end +function set_function_metatable() + local mt = {}; + function mt.__index(f, upvalue) + local i, name, value = 0; + repeat + i = i + 1; + name, value = debug.getupvalue(f, i); + until name == upvalue or name == nil; + return value; + end + function mt.__newindex(f, upvalue, value) + local i, name = 0; + repeat + i = i + 1; + name = debug.getupvalue(f, i); + until name == upvalue or name == nil; + if name then + debug.setupvalue(f, i, value); + end + end + function mt.__tostring(f) + local info = debug.getinfo(f); + return ("function(%s:%d)"):format(info.short_src:match("[^\\/]*$"), info.linedefined); + end + debug.setmetatable(function() end, mt); +end + function init_global_state() bare_sessions = {}; full_sessions = {}; hosts = {}; - -- Global 'prosody' object - prosody = {}; - local prosody = prosody; - prosody.bare_sessions = bare_sessions; prosody.full_sessions = full_sessions; prosody.hosts = hosts; @@ -138,8 +165,6 @@ function init_global_state() prosody.arg = _G.arg; - prosody.events = require "util.events".new(); - prosody.platform = "unknown"; if os.getenv("WINDIR") then prosody.platform = "windows"; @@ -170,7 +195,6 @@ function init_global_state() -- Function to reopen logfiles function prosody.reopen_logfiles() log("info", "Re-opening log files"); - eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks prosody.events.fire_event("reopen-log-files"); end @@ -261,9 +285,9 @@ end function load_secondary_libraries() --- Load and initialise core modules require "util.import" + require "util.xmppstream" require "core.xmlhandlers" require "core.rostermanager" - require "core.eventmanager" require "core.hostmanager" require "core.modulemanager" require "core.usermanager" @@ -305,9 +329,8 @@ function init_data_store() end function prepare_to_start() - log("info", "Prosody is using the %s backend for connection handling", server.get_backend()); + log("debug", "Prosody is using the %s backend for connection handling", server.get_backend()); -- Signal to modules that we are ready to start - eventmanager.fire_event("server-starting"); prosody.events.fire_event("server-starting"); -- start listening on sockets @@ -415,6 +438,7 @@ read_config(); init_logging(); check_dependencies(); sandbox_require(); +set_function_metatable(); load_libraries(); init_global_state(); read_version(); @@ -424,14 +448,12 @@ init_data_store(); init_global_protection(); prepare_to_start(); -eventmanager.fire_event("server-started"); prosody.events.fire_event("server-started"); loop(); log("info", "Shutting down..."); cleanup(); -eventmanager.fire_event("server-stopped"); prosody.events.fire_event("server-stopped"); log("info", "Shutdown complete");