X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules.cpp;h=71363ae9dd0ee7817062778aea74b7e99d079b16;hb=37fd031da06761c8a050105b55d73a8ab499fb74;hp=169a3a352746794ab3203fa58f0bb0929fcd9d3b;hpb=4ab15e865571f78cd8ea22c47a1a3b7d3372a786;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules.cpp b/src/modules.cpp index 169a3a352..71363ae9d 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -56,7 +56,7 @@ void Event::Send() Module::Module() { } bool Module::cull() { - ServerInstance->GlobalCulls.AddItem(ModuleDLLFactory); + ServerInstance->GlobalCulls.AddItem(ModuleDLLManager); return true; } Module::~Module() { } @@ -372,67 +372,36 @@ bool ModuleManager::Load(const char* filename) } Module* newmod = NULL; - DLLFactory* newhandle = NULL; + DLLManager* newhandle = new DLLManager(modfile); try { - /* This will throw a CoreException if there's a problem loading - * the module file or getting a pointer to the init_module symbol. - */ - newhandle = new DLLFactory(modfile, "init_module"); - if (newhandle->init_func) - newmod = newhandle->init_func(); + newmod = newhandle->callInit(); if (newmod) { newmod->ModuleSourceFile = filename_str; - newmod->ModuleDLLFactory = newhandle; + newmod->ModuleDLLManager = newhandle; Version v = newmod->GetVersion(); - ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s", filename, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); + ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s", + filename, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); Modules[filename_str] = newmod; } else { - delete newhandle; - LastModuleError = "Unable to load " + filename_str + ": Probably missing init_module() entrypoint, but dlsym() didn't notice a problem"; + LastModuleError = "Unable to load " + filename_str + ": " + newhandle->LastError(); ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); + delete newhandle; return false; } } - /** XXX: Is there anything we can do about this mess? -- Brain - * Yeah, don't use exceptions without RAII. -- Daniel - */ - catch (LoadModuleException& modexcept) - { - DetachAll(newmod); - if (newmod) - delete newmod; - if (newhandle) - delete newhandle; - LastModuleError = "Unable to load " + filename_str + ": Error when loading: " + modexcept.GetReason(); - ServerInstance->Logs->Log("MODULE", 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(); - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } catch (CoreException& modexcept) { - DetachAll(newmod); - if (newmod) - delete newmod; - if (newhandle) - delete newhandle; + // failure in module constructor + delete newmod; + delete newhandle; LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason(); ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); return false; @@ -505,9 +474,6 @@ bool ModuleManager::Unload(const char* filename) this->DetachAll(modfind->second); - ServerInstance->Parser->RemoveCommands(modfind->second); - ServerInstance->Modes->RemoveModes(modfind->second); - ServerInstance->GlobalCulls.AddItem(modfind->second); Modules.erase(modfind); @@ -526,7 +492,7 @@ bool ModuleManager::Unload(const char* filename) void ModuleManager::LoadAll() { char configToken[MAXBUF]; - ModCount = -1; + ModCount = 0; printf("\nLoading core commands"); fflush(stdout); @@ -701,24 +667,6 @@ const std::string& ModuleManager::GetModuleName(Module* m) return nothing; } -/* This is ugly, yes, but hash_map's arent designed to be - * addressed in this manner, and this is a bit of a kludge. - * Luckily its a specialist function and rarely used by - * many modules (in fact, it was specially created to make - * m_safelist possible, initially). - */ - -Channel* InspIRCd::GetChannelIndex(long index) -{ - int target = 0; - for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++) - { - if (index == target) - return n->second; - } - return NULL; -} - CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector& parameters, User* user) { return this->Parser->CallHandler(commandname, parameters, user); @@ -731,10 +679,9 @@ bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, Us void InspIRCd::AddCommand(Command *f) { - if (!this->Parser->CreateCommand(f)) + if (!this->Parser->AddCommand(f)) { - ModuleException err("Command "+std::string(f->command)+" already exists."); - throw (err); + throw ModuleException("Command "+std::string(f->command)+" already exists."); } }