X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules.cpp;h=ca312c4a5ec44d4500f23268f1c1fedeaf74d100;hb=fd1d19d6345943ecdb5ce4ef947f9b3c5c8bca86;hp=767322fc9a8963724b308d5478b9e409bce0c3b8;hpb=1858feabd342636df0b52780c978979b4e049fc3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules.cpp b/src/modules.cpp index 767322fc9..ca312c4a5 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -24,12 +24,12 @@ */ +#include #include "inspircd.h" #include "xline.h" #include "socket.h" #include "socketengine.h" #include "command_parse.h" -#include "dns.h" #include "exitcodes.h" #ifndef _WIN32 @@ -58,17 +58,6 @@ Version::Version(const std::string &desc, int flags, const std::string& linkdata { } -Request::Request(Module* src, Module* dst, const char* idstr) -: id(idstr), source(src), dest(dst) -{ -} - -void Request::Send() -{ - if (dest) - dest->OnRequest(*this); -} - Event::Event(Module* src, const std::string &eventid) : source(src), id(eventid) { } void Event::Send() @@ -97,15 +86,14 @@ void Module::OnUserPart(Membership*, std::string&, CUList&) { } void Module::OnPreRehash(User*, const std::string&) { } void Module::OnModuleRehash(User*, const std::string&) { } void Module::OnRehash(User*) { } -ModResult Module::OnUserPreJoin(User*, Channel*, const std::string&, std::string&, const std::string&) { return MOD_RES_PASSTHRU; } -void Module::OnMode(User*, void*, int, const std::vector&, const std::vector&) { } +ModResult Module::OnUserPreJoin(LocalUser*, Channel*, const std::string&, std::string&, const std::string&) { return MOD_RES_PASSTHRU; } +void Module::OnMode(User*, User*, Channel*, const std::vector&, const std::vector&) { } void Module::OnOper(User*, const std::string&) { } void Module::OnPostOper(User*, const std::string&, const std::string &) { } void Module::OnInfo(User*) { } void Module::OnWhois(User*, User*) { } ModResult Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return MOD_RES_PASSTHRU; } -ModResult Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; } -ModResult Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; } +ModResult Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&, MessageType) { return MOD_RES_PASSTHRU; } ModResult Module::OnUserPreNick(User*, const std::string&) { return MOD_RES_PASSTHRU; } void Module::OnUserPostNick(User*, const std::string&) { } ModResult Module::OnPreMode(User*, User*, Channel*, const std::vector&) { return MOD_RES_PASSTHRU; } @@ -115,7 +103,7 @@ void Module::OnLoadModule(Module*) { } void Module::OnUnloadModule(Module*) { } void Module::OnBackgroundTimer(time_t) { } ModResult Module::OnPreCommand(std::string&, std::vector&, LocalUser*, bool, const std::string&) { return MOD_RES_PASSTHRU; } -void Module::OnPostCommand(const std::string&, const std::vector&, LocalUser*, CmdResult, const std::string&) { } +void Module::OnPostCommand(Command*, const std::vector&, LocalUser*, CmdResult, const std::string&) { } void Module::OnUserInit(LocalUser*) { } ModResult Module::OnCheckReady(LocalUser*) { return MOD_RES_PASSTHRU; } ModResult Module::OnUserRegister(LocalUser*) { return MOD_RES_PASSTHRU; } @@ -133,18 +121,10 @@ ModResult Module::OnChangeLocalUserHost(LocalUser*, const std::string&) { return ModResult Module::OnChangeLocalUserGECOS(LocalUser*, const std::string&) { return MOD_RES_PASSTHRU; } ModResult Module::OnPreTopicChange(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; } 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*) { } -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&) { } +void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { } void Module::OnUserInvite(User*, User*, Channel*, time_t) { } void Module::OnPostTopicChange(User*, Channel*, const std::string&) { } void Module::OnGetServerDescription(const std::string&, std::string&) { } @@ -154,7 +134,6 @@ void Module::OnSyncNetwork(Module*, void*) { } void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::vector&, const std::vector&) { } void Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { } void Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { } -void Module::OnWallops(User*, const std::string&) { } void Module::OnChangeHost(User*, const std::string&) { } void Module::OnChangeName(User*, const std::string&) { } void Module::OnChangeIdent(User*, const std::string&) { } @@ -328,18 +307,20 @@ bool ModuleManager::CanUnload(Module* mod) { std::map::iterator modfind = Modules.find(mod->ModuleSourceFile); - if (modfind == Modules.end() || modfind->second != mod) + if ((modfind == Modules.end()) || (modfind->second != mod) || (mod->dying)) { LastModuleError = "Module " + mod->ModuleSourceFile + " is not loaded, cannot unload it!"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); return false; } if (mod->GetVersion().Flags & VF_STATIC) { LastModuleError = "Module " + mod->ModuleSourceFile + " not unloadable (marked static)"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); return false; } + + mod->dying = true; return true; } @@ -387,15 +368,12 @@ void ModuleManager::DoSafeUnload(Module* mod) dynamic_reference_base::reset_all(); - /* Tidy up any dangling resolvers */ - ServerInstance->Res->CleanResolvers(mod); - DetachAll(mod); Modules.erase(modfind); ServerInstance->GlobalCulls.AddItem(mod); - ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",mod->ModuleSourceFile.c_str()); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Module %s unloaded",mod->ModuleSourceFile.c_str()); this->ModCount--; ServerInstance->ISupport.Build(); } @@ -437,11 +415,14 @@ void ModuleManager::AddService(ServiceProvider& item) throw ModuleException("Command "+std::string(item.name)+" already exists."); return; case SERVICE_MODE: - if (!ServerInstance->Modes->AddMode(static_cast(&item))) + { + ModeHandler* mh = static_cast(&item); + if (!ServerInstance->Modes->AddMode(mh)) throw ModuleException("Mode "+std::string(item.name)+" already exists."); - DataProviders.insert(std::make_pair("mode/" + item.name, &item)); + DataProviders.insert(std::make_pair((mh->GetModeType() == MODETYPE_CHANNEL ? "mode/" : "umode/") + item.name, &item)); dynamic_reference_base::reset_all(); return; + } case SERVICE_METADATA: if (!ServerInstance->Extensions.Register(static_cast(&item))) throw ModuleException("Extension " + std::string(item.name) + " already exists."); @@ -449,8 +430,8 @@ void ModuleManager::AddService(ServiceProvider& item) case SERVICE_DATA: case SERVICE_IOHOOK: { - if (item.name.substr(0, 5) == "mode/") - throw ModuleException("The \"mode/\" service name prefix is reserved."); + if ((item.name.substr(0, 5) == "mode/") || (item.name.substr(0, 6) == "umode/")) + throw ModuleException("The \"mode/\" and the \"umode\" service name prefixes are reserved."); DataProviders.insert(std::make_pair(item.name, &item)); std::string::size_type slash = item.name.find('/'); @@ -555,31 +536,6 @@ void dynamic_reference_base::resolve() value = NULL; } -void InspIRCd::SendMode(const std::vector& parameters, User *user) -{ - this->Modes->Process(parameters, user); -} - - -void InspIRCd::SendGlobalMode(const std::vector& parameters, User *user) -{ - Modes->Process(parameters, user); - if (!Modes->GetLastParse().empty()) - this->PI->SendMode(parameters[0], Modes->GetLastParseParams(), Modes->GetLastParseTranslate()); -} - -bool InspIRCd::AddResolver(Resolver* r, bool cached) -{ - if (!cached) - return this->Res->AddResolverClass(r); - else - { - r->TriggerCachedResult(); - delete r; - return true; - } -} - Module* ModuleManager::Find(const std::string &name) { std::map::iterator modfind = Modules.find(name); @@ -599,82 +555,45 @@ const std::vector ModuleManager::GetAllModuleNames(int filter) return retval; } -FileReader::FileReader(const std::string &filename) -{ - LoadFile(filename); -} - -FileReader::FileReader() +FileReader::FileReader(const std::string& filename) { + Load(filename); } -std::string FileReader::Contents() +void FileReader::Load(const std::string& filename) { - std::string x; - for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++) + // If the file is stored in the file cache then we used that version instead. + ConfigFileCache::iterator it = ServerInstance->Config->Files.find(filename); + if (it != ServerInstance->Config->Files.end()) { - x.append(*a); - x.append("\r\n"); - } - return x; -} - -unsigned long FileReader::ContentSize() -{ - return this->contentsize; -} - -void FileReader::CalcSize() -{ - unsigned long n = 0; - for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++) - n += (a->length() + 2); - this->contentsize = n; -} - -void FileReader::LoadFile(const std::string &filename) -{ - std::map::iterator file = ServerInstance->Config->Files.find(filename); - if (file != ServerInstance->Config->Files.end()) - { - this->fc = file->second; + this->lines = it->second; } else { - fc.clear(); - FILE* f = fopen(filename.c_str(), "r"); - if (!f) - return; - char linebuf[MAXBUF*10]; - while (fgets(linebuf, sizeof(linebuf), f)) - { - int len = strlen(linebuf); - if (len) - fc.push_back(std::string(linebuf, len - 1)); - } - fclose(f); - } - CalcSize(); -} + lines.clear(); + std::ifstream stream(filename.c_str()); + if (!stream.is_open()) + throw CoreException(filename + " does not exist or is not readable!"); -FileReader::~FileReader() -{ -} - -bool FileReader::Exists() -{ - return (!(fc.size() == 0)); -} + std::string line; + while (std::getline(stream, line)) + { + lines.push_back(line); + totalSize += line.size() + 2; + } -std::string FileReader::GetLine(int x) -{ - if ((x<0) || ((unsigned)x>fc.size())) - return ""; - return fc[x]; + stream.close(); + } } -int FileReader::FileSize() +std::string FileReader::GetString() { - return fc.size(); + std::string buffer; + for (file_cache::iterator it = this->lines.begin(); it != this->lines.end(); ++it) + { + buffer.append(*it); + buffer.append("\r\n"); + } + return buffer; }