X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules.cpp;h=ee18112a1597dfaecad4a2bf42883be5af470df4;hb=c440038736f749a56dbac1badee5b2f099286117;hp=e382f145ec86adb9f70e8dc63ecb60f210eda339;hpb=069a2ef21425007d092342c8c11ec28da2f410d7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules.cpp b/src/modules.cpp index e382f145e..ee18112a1 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -27,8 +27,9 @@ // 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) -: version(modv + " - " + 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) { } @@ -90,7 +91,7 @@ Module* Event::GetSource() return this->source; } -char* Event::Send(InspIRCd* SI) +char* Event::Send() { FOREACH_MOD(I_OnEvent,OnEvent(this)); return NULL; @@ -104,7 +105,12 @@ std::string Event::GetEventID() // These declarations define the behavours of the base class Module (which does nothing at all) -Module::Module(InspIRCd*) { } +Module::Module() { } +bool Module::cull() +{ + ServerInstance->GlobalCulls.AddItem(ModuleDLLFactory); + return true; +} Module::~Module() { } ModResult Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return MOD_RES_PASSTHRU; } @@ -119,7 +125,6 @@ void Module::OnModuleRehash(User*, const std::string&) { } void Module::OnRehash(User*) { } ModResult Module::OnUserPreJoin(User*, Channel*, const char*, std::string&, const std::string&) { return MOD_RES_PASSTHRU; } void Module::OnMode(User*, void*, int, const std::vector&, const std::vector&) { } -Version Module::GetVersion() { return Version("Misconfigured", VF_VENDOR, -1); } void Module::OnOper(User*, const std::string&) { } void Module::OnPostOper(User*, const std::string&, const std::string &) { } void Module::OnInfo(User*) { } @@ -145,9 +150,9 @@ ModResult Module::OnRawMode(User*, Channel*, const char, const std::string &, bo ModResult Module::OnCheckInvite(User*, Channel*) { return MOD_RES_PASSTHRU; } ModResult Module::OnCheckKey(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; } ModResult Module::OnCheckLimit(User*, Channel*) { return MOD_RES_PASSTHRU; } -ModResult Module::OnCheckBan(User*, Channel*) { return MOD_RES_PASSTHRU; } -ModResult Module::OnCheckExtBan(User *, Channel *, char) { return MOD_RES_PASSTHRU; } -ModResult Module::OnCheckStringExtBan(const std::string &s, Channel *c, char type) { return MOD_RES_PASSTHRU; } +ModResult Module::OnCheckChannelBan(User*, Channel*) { return MOD_RES_PASSTHRU; } +ModResult Module::OnCheckBan(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; } +ModResult Module::OnExtBanCheck(User*, Channel*, char) { return MOD_RES_PASSTHRU; } 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; } @@ -159,11 +164,11 @@ void Module::OnGlobalOper(User*) { } void Module::OnPostConnect(User*) { } ModResult Module::OnAddBan(User*, Channel*, const std::string &) { return MOD_RES_PASSTHRU; } ModResult Module::OnDelBan(User*, Channel*, const std::string &) { return MOD_RES_PASSTHRU; } -void Module::OnRawSocketAccept(int, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { } -int Module::OnRawSocketWrite(int, const char*, int) { return 0; } -void Module::OnRawSocketClose(int) { } -void Module::OnRawSocketConnect(int) { } -int Module::OnRawSocketRead(int, char*, unsigned int, int&) { return 0; } +void Module::OnStreamSocketAccept(StreamSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { } +int Module::OnStreamSocketWrite(StreamSocket*, std::string&) { return -1; } +void Module::OnStreamSocketClose(StreamSocket*) { } +void Module::OnStreamSocketConnect(StreamSocket*) { } +int Module::OnStreamSocketRead(StreamSocket*, std::string&) { return -1; } void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { } void Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { } void Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { } @@ -189,15 +194,13 @@ 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(EventHandler*, ListenSocketBase*) { } -ModResult Module::OnHostCycle(User*) { return MOD_RES_PASSTHRU; } +void Module::OnHookIO(StreamSocket*, ListenSocketBase*) { } void Module::OnSendWhoLine(User*, User*, Channel*, std::string&) { } ModuleManager::ModuleManager() : ModCount(0) @@ -420,36 +423,26 @@ bool ModuleManager::Load(const char* filename) } Module* newmod = NULL; - ircd_module* newhandle = NULL; + DLLFactory* newhandle = NULL; 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(); + newhandle = new DLLFactory(modfile, "init_module"); + if (newhandle->init_func) + newmod = newhandle->init_func(); if (newmod) { newmod->ModuleSourceFile = filename_str; + newmod->ModuleDLLFactory = 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 { @@ -459,7 +452,9 @@ bool ModuleManager::Load(const char* filename) return false; } } - /** XXX: Is there anything we can do about this mess? -- Brain */ + /** XXX: Is there anything we can do about this mess? -- Brain + * Yeah, don't use exceptions without RAII. -- Daniel + */ catch (LoadModuleException& modexcept) { DetachAll(newmod); @@ -495,7 +490,7 @@ bool ModuleManager::Load(const char* filename) } 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 @@ -504,8 +499,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; @@ -520,17 +515,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 + "'"; @@ -538,29 +533,33 @@ bool ModuleManager::Unload(const char* filename) return false; } + 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++) + mi->second->doUnhookExtensions(items); } 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); - + ServerInstance->Res->CleanResolvers(modfind->second); - FOREACH_MOD_I(ServerInstance,I_OnUnloadModule,OnUnloadModule(modfind->second.second, modfind->first)); + FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modfind->second, modfind->first)); - this->DetachAll(modfind->second.second); + this->DetachAll(modfind->second); - ServerInstance->Parser->RemoveCommands(modfind->second.second); - Extensible::UnRegister(modfind->second.second); + ServerInstance->Parser->RemoveCommands(modfind->second); + ServerInstance->Modes->RemoveModes(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); @@ -744,9 +743,9 @@ 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; } @@ -857,24 +856,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; } @@ -954,12 +953,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() { }