X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules.cpp;h=71363ae9dd0ee7817062778aea74b7e99d079b16;hb=37fd031da06761c8a050105b55d73a8ab499fb74;hp=d38496444160842ed986a3b01c071e5ccb719827;hpb=7d93921aabd9c608821baec8a871aff844dfae49;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules.cpp b/src/modules.cpp index d38496444..71363ae9d 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -27,84 +27,38 @@ // version is a simple class for holding a modules version number -Version::Version(const std::string &modv, int flags, int api_ver, const std::string& rev) -: description(modv), version(rev), Flags(flags), API(api_ver) +template<> +VersionBase::VersionBase(const std::string &modv, int flags, int, const std::string& rev) +: description(modv), version(rev), Flags(flags) { } -Request::Request(char* anydata, Module* src, Module* dst) -: data(anydata), source(src), dest(dst) -{ - /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do - * by passing them uninitialized pointers (could happen) - */ - id = '\0'; -} - Request::Request(Module* src, Module* dst, const char* idstr) : id(idstr), source(src), dest(dst) { } -char* Request::GetData() -{ - return this->data; -} - -const char* Request::GetId() -{ - return this->id; -} - -Module* Request::GetSource() -{ - return this->source; -} - -Module* Request::GetDest() -{ - return this->dest; -} - -const char* Request::Send() +void Request::Send() { - if (this->dest) - { - return dest->OnRequest(this); - } - else - { - return NULL; - } + if (dest) + dest->OnRequest(*this); } -Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { } - -char* Event::GetData() -{ - return this->data; -} +Event::Event(Module* src, const std::string &eventid) : source(src), id(eventid) { } -Module* Event::GetSource() +void Event::Send() { - return this->source; + FOREACH_MOD(I_OnEvent,OnEvent(*this)); } -char* Event::Send(InspIRCd* SI) -{ - FOREACH_MOD(I_OnEvent,OnEvent(this)); - return NULL; -} +// These declarations define the behavours of the base class Module (which does nothing at all) -std::string Event::GetEventID() +Module::Module() { } +bool Module::cull() { - return this->id; + ServerInstance->GlobalCulls.AddItem(ModuleDLLManager); + return true; } - - -// These declarations define the behavours of the base class Module (which does nothing at all) - -Module::Module(InspIRCd*) { } Module::~Module() { } ModResult Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return MOD_RES_PASSTHRU; } @@ -151,8 +105,8 @@ ModResult Module::OnStats(char, User*, string_list&) { return MOD_RES_PASSTHRU; ModResult Module::OnChangeLocalUserHost(User*, const std::string&) { return MOD_RES_PASSTHRU; } ModResult Module::OnChangeLocalUserGECOS(User*, const std::string&) { return MOD_RES_PASSTHRU; } ModResult Module::OnPreTopicChange(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; } -void Module::OnEvent(Event*) { return; } -const char* Module::OnRequest(Request*) { return NULL; } +void Module::OnEvent(Event&) { } +void Module::OnRequest(Request&) { } ModResult Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return MOD_RES_PASSTHRU; } void Module::OnGlobalOper(User*) { } void Module::OnPostConnect(User*) { } @@ -188,16 +142,15 @@ void Module::OnChannelDelete(Channel*) { } ModResult Module::OnSetAway(User*, const std::string &) { return MOD_RES_PASSTHRU; } ModResult Module::OnUserList(User*, Channel*) { return MOD_RES_PASSTHRU; } ModResult Module::OnWhoisLine(User*, User*, int&, std::string&) { return MOD_RES_PASSTHRU; } -void Module::OnBuildExemptList(MessageType, Channel*, User*, char, CUList&, const std::string&) { } +void Module::OnBuildNeighborList(User*, UserChanList&, std::map&) { } void Module::OnGarbageCollect() { } -void Module::OnBufferFlushed(User*) { } void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { } void Module::OnRunTestSuite() { } void Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { } ModResult Module::OnNumeric(User*, unsigned int, const std::string&) { return MOD_RES_PASSTHRU; } void Module::OnHookIO(StreamSocket*, ListenSocketBase*) { } -ModResult Module::OnHostCycle(User*) { return MOD_RES_PASSTHRU; } void Module::OnSendWhoLine(User*, User*, Channel*, std::string&) { } +ModResult Module::OnChannelRestrictionApply(User*, Channel*, const char*) { return MOD_RES_PASSTHRU; } ModuleManager::ModuleManager() : ModCount(0) { @@ -419,82 +372,43 @@ bool ModuleManager::Load(const char* filename) } Module* newmod = NULL; - ircd_module* 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 ircd_module(ServerInstance, modfile, "init_module"); - newmod = newhandle->CallInit(); + newmod = newhandle->callInit(); if (newmod) { newmod->ModuleSourceFile = filename_str; + newmod->ModuleDLLManager = newhandle; 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) + ")"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } - else - { - ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (API version %d, Module version %s)%s", filename, v.API, 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] = std::make_pair(newhandle, newmod); + 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 */ - 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; } this->ModCount++; - FOREACH_MOD_I(ServerInstance,I_OnLoadModule,OnLoadModule(newmod, filename_str)); + FOREACH_MOD(I_OnLoadModule,OnLoadModule(newmod, filename_str)); /* We give every module a chance to re-prioritize when we introduce a new one, * not just the one thats loading, as the new module could affect the preference @@ -503,8 +417,8 @@ bool ModuleManager::Load(const char* filename) for(int tries = 0; tries < 20; tries++) { prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST; - for (std::map >::iterator n = Modules.begin(); n != Modules.end(); ++n) - n->second.second->Prioritize(); + for (std::map::iterator n = Modules.begin(); n != Modules.end(); ++n) + n->second->Prioritize(); if (prioritizationState == PRIO_STATE_LAST) break; @@ -519,17 +433,17 @@ bool ModuleManager::Load(const char* filename) bool ModuleManager::Unload(const char* filename) { std::string filename_str(filename); - std::map >::iterator modfind = Modules.find(filename); + std::map::iterator modfind = Modules.find(filename); if (modfind != Modules.end()) { - if (modfind->second.second->GetVersion().Flags & VF_STATIC) + if (modfind->second->GetVersion().Flags & VF_STATIC) { LastModuleError = "Module " + filename_str + " not unloadable (marked static)"; ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); return false; } - std::pair intercount = GetInterfaceInstanceCount(modfind->second.second); + std::pair intercount = GetInterfaceInstanceCount(modfind->second); if (intercount.first > 0) { LastModuleError = "Failed to unload module " + filename_str + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'"; @@ -537,11 +451,11 @@ bool ModuleManager::Unload(const char* filename) return false; } - std::vector items = Extensible::BeginUnregister(modfind->second.second); + std::vector items = Extensible::BeginUnregister(modfind->second); /* Give the module a chance to tidy out all its metadata */ for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++) { - modfind->second.second->OnCleanup(TYPE_CHANNEL,c->second); + modfind->second->OnCleanup(TYPE_CHANNEL,c->second); c->second->doUnhookExtensions(items); const UserMembList* users = c->second->GetUsers(); for(UserMembCIter mi = users->begin(); mi != users->end(); mi++) @@ -549,21 +463,18 @@ bool ModuleManager::Unload(const char* filename) } for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) { - modfind->second.second->OnCleanup(TYPE_USER,u->second); + modfind->second->OnCleanup(TYPE_USER,u->second); u->second->doUnhookExtensions(items); } /* Tidy up any dangling resolvers */ - ServerInstance->Res->CleanResolvers(modfind->second.second); - - FOREACH_MOD_I(ServerInstance,I_OnUnloadModule,OnUnloadModule(modfind->second.second, modfind->first)); + ServerInstance->Res->CleanResolvers(modfind->second); - this->DetachAll(modfind->second.second); + FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modfind->second, modfind->first)); - ServerInstance->Parser->RemoveCommands(modfind->second.second); + this->DetachAll(modfind->second); - delete modfind->second.second; - delete modfind->second.first; + ServerInstance->GlobalCulls.AddItem(modfind->second); Modules.erase(modfind); ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename); @@ -581,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); @@ -747,33 +658,15 @@ const std::string& ModuleManager::GetModuleName(Module* m) { static std::string nothing; - for (std::map >::iterator n = Modules.begin(); n != Modules.end(); ++n) + for (std::map::iterator n = Modules.begin(); n != Modules.end(); ++n) { - if (n->second.second == m) + if (n->second == m) return n->first; } 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); @@ -786,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."); } } @@ -860,24 +752,24 @@ bool InspIRCd::AddResolver(Resolver* r, bool cached) Module* ModuleManager::Find(const std::string &name) { - std::map >::iterator modfind = Modules.find(name); + std::map::iterator modfind = Modules.find(name); if (modfind == Modules.end()) return NULL; else - return modfind->second.second; + return modfind->second; } const std::vector ModuleManager::GetAllModuleNames(int filter) { std::vector retval; - for (std::map >::iterator x = Modules.begin(); x != Modules.end(); ++x) - if (!filter || (x->second.second->GetVersion().Flags & filter)) + for (std::map::iterator x = Modules.begin(); x != Modules.end(); ++x) + if (!filter || (x->second->GetVersion().Flags & filter)) retval.push_back(x->first); return retval; } -ConfigReader::ConfigReader(InspIRCd* Instance) +ConfigReader::ConfigReader() { this->error = 0; } @@ -957,12 +849,12 @@ int ConfigReader::EnumerateValues(const std::string &tag, int index) return ServerInstance->Config->ConfVarEnum(tag, index); } -FileReader::FileReader(InspIRCd* Instance, const std::string &filename) +FileReader::FileReader(const std::string &filename) { LoadFile(filename); } -FileReader::FileReader(InspIRCd* Instance) +FileReader::FileReader() { }