]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Argh, i give up
[user/henk/code/inspircd.git] / src / modules.cpp
index 7eb97873fad9dc0fb88635fe79f7a5e75b58459d..6fecc1f507d8cd8f16a577271a840fb25b74705e 100644 (file)
@@ -106,10 +106,12 @@ std::string Event::GetEventID()
 
                Module::Module(InspIRCd* Me) : ServerInstance(Me) { }
                Module::~Module() { }
+void           Module::OnReadConfig(ServerConfig*, ConfigReader*) { }
+int            Module::OnDownloadFile(const std::string&, std::istream*&) { return 0; }
 void           Module::OnUserConnect(User*) { }
 void           Module::OnUserQuit(User*, const std::string&, const std::string&) { }
 void           Module::OnUserDisconnect(User*) { }
-void           Module::OnUserJoin(User*, Channel*, bool&) { }
+void           Module::OnUserJoin(User*, Channel*, bool, bool&) { }
 void           Module::OnPostJoin(User*, Channel*) { }
 void           Module::OnUserPart(User*, Channel*, const std::string&, bool&) { }
 void           Module::OnRehash(User*, const std::string&) { }
@@ -191,8 +193,6 @@ void                Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
 
 ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
 {
-       for (int n = I_BEGIN; n != I_END; ++n)
-               EventHandlers.push_back(std::vector<Module*>());
 }
 
 ModuleManager::~ModuleManager()
@@ -406,13 +406,15 @@ bool ModuleManager::Load(const char* filename)
                newhandle = new ircd_module(Instance, modfile, "init_module");
                newmod = newhandle->CallInit();
 
-               if(newmod)
+               if (newmod)
                {
                        Version v = newmod->GetVersion();
 
                        if (v.API != API_VERSION)
                        {
+                               DetachAll(newmod);
                                delete newmod;
+                               delete newhandle;
                                LastModuleError = "Unable to load " + filename_str + ": Incorrect module API version: " + ConvToStr(v.API) + " (our version: " + ConvToStr(API_VERSION) + ")";
                                Instance->Log(DEFAULT, LastModuleError);
                                return false;
@@ -426,25 +428,42 @@ bool ModuleManager::Load(const char* filename)
                }
                else
                {
+                       delete newhandle;
                        LastModuleError = "Unable to load " + filename_str + ": Probably missing init_module() entrypoint, but dlsym() didn't notice a problem";
                        Instance->Log(DEFAULT, LastModuleError);
                        return false;
                }
        }
+       /** XXX: Is there anything we can do about this mess? -- Brain */
        catch (LoadModuleException& modexcept)
        {
+               DetachAll(newmod);
+               if (newmod)
+                       delete newmod;
+               if (newhandle)
+                       delete newhandle;
                LastModuleError = "Unable to load " + filename_str + ": Error when loading: " + modexcept.GetReason();
                Instance->Log(DEFAULT, LastModuleError);
                return false;
        }
        catch (FindSymbolException& modexcept)
        {
+               DetachAll(newmod);
+               if (newmod)
+                       delete newmod;
+               if (newhandle)
+                       delete newhandle;
                LastModuleError = "Unable to load " + filename_str + ": Error finding symbol: " + modexcept.GetReason();
                Instance->Log(DEFAULT, LastModuleError);
                return false;
        }
        catch (CoreException& modexcept)
        {
+               DetachAll(newmod);
+               if (newmod)
+                       delete newmod;
+               if (newhandle)
+                       delete newhandle;
                LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason();
                Instance->Log(DEFAULT, LastModuleError);
                return false;
@@ -538,8 +557,6 @@ void ModuleManager::LoadAll()
                        Instance->Exit(EXIT_STATUS_MODULE);
                }
        }
-       printf_c("\nA total of \033[1;32m%d\033[0m module%s been loaded.\n", (this->GetCount()), (this->GetCount()) == 1 ? " has" : "s have");
-       Instance->Log(DEFAULT,"Total loaded modules: %d", this->GetCount());
 }
 
 bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod)
@@ -808,7 +825,11 @@ ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : Se
        this->data = new ConfigDataHash;
        this->privatehash = true;
        this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
-       this->readerror = ServerInstance->Config->LoadConf(*this->data, filename, *this->errorlog);
+       for (int pass = 0; pass < 2; pass++)
+       {
+               /*** XXX: Can return a 'not ready yet!' code! */
+               this->readerror = ServerInstance->Config->LoadConf(*this->data, filename, *this->errorlog, pass);
+       }
        if (!this->readerror)
                this->error = CONF_FILE_NOT_FOUND;
 }