prosody: Added a comment, to match prosodyctl.
[prosody.git] / prosody
diff --git a/prosody b/prosody
index 4b016e504e3d9c60c60670704027c2ba8f6f974e..061f3781ee53904846b623a70999b0f76f18588f 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -1,12 +1,14 @@
 #!/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.
 --
 
+-- prosody - main executable for Prosody XMPP server
+
 -- Will be modified by configure script if run --
 
 CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR");
@@ -29,6 +31,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 +126,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 +167,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 +197,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,14 +287,17 @@ end
 function load_secondary_libraries()
        --- Load and initialise core modules
        require "util.import"
-       require "core.xmlhandlers"
+       require "util.xmppstream"
        require "core.rostermanager"
-       require "core.eventmanager"
        require "core.hostmanager"
        require "core.modulemanager"
        require "core.usermanager"
        require "core.sessionmanager"
        require "core.stanza_router"
+       package.loaded['core.componentmanager'] = setmetatable({},{__index=function()
+               log("warn", "componentmanager is deprecated: %s", debug.traceback():match("\n[^\n]*\n[\s\t]*([^\n]*)"));
+               return function() end
+       end});
 
        require "net.http"
        
@@ -302,12 +331,12 @@ function init_data_store()
                end
                return username, host, datastore, data;
        end);
+       require "core.storagemanager";
 end
 
 function prepare_to_start()
        log("info", "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 +444,7 @@ read_config();
 init_logging();
 check_dependencies();
 sandbox_require();
+set_function_metatable();
 load_libraries();
 init_global_state();
 read_version();
@@ -424,14 +454,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");