diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-04-21 18:03:07 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-21 18:03:07 +0200 |
commit | 216877cc5b595b5b6bbc5f953e226618201cc0f6 (patch) | |
tree | 5341c63ad1e1baf702ae23cca2dcfb4e2488cd01 /src | |
parent | 822f3f13f18b7e79d5740416f9417dabb9296859 (diff) |
m_filter, m_rline Remove rlines and filters when the regex engine changes or becomes unavailable
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_filter.cpp | 57 | ||||
-rw-r--r-- | src/modules/m_rline.cpp | 38 |
2 files changed, 79 insertions, 16 deletions
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 25941e5d8..5e1b4d38d 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -165,6 +165,8 @@ class ImplFilter : public FilterResult class ModuleFilter : public Module { + bool initing; + RegexFactory* factory; void FreeFilters(); public: @@ -172,8 +174,6 @@ class ModuleFilter : public Module dynamic_reference<RegexFactory> RegexEngine; std::vector<ImplFilter> filters; - const char *error; - int erroffset; int flags; std::set<std::string> exemptfromfilter; // List of channel names excluded from filtering. @@ -194,6 +194,7 @@ class ModuleFilter : public Module void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata); ModResult OnStats(char symbol, User* user, string_list &results); ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser *user, bool validated, const std::string &original_line); + void OnUnloadModule(Module* mod); bool AppliesToMe(User* user, FilterResult* filter, int flags); void ReadFilters(); static bool StringToFilterAction(const std::string& str, FilterAction& fa); @@ -295,14 +296,15 @@ bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags) return true; } -ModuleFilter::ModuleFilter() : filtcommand(this), RegexEngine(this, "regex") +ModuleFilter::ModuleFilter() + : initing(true), filtcommand(this), RegexEngine(this, "regex") { } void ModuleFilter::init() { ServerInstance->Modules->AddService(filtcommand); - Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash }; + Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnUnloadModule }; ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); OnRehash(NULL); } @@ -474,20 +476,35 @@ void ModuleFilter::OnRehash(User* user) if (!chan.empty()) exemptfromfilter.insert(chan); } - std::string newrxengine = "regex/" + ServerInstance->Config->ConfValue("filteropts")->getString("engine"); - if (newrxengine == "regex/") - newrxengine = "regex"; - if (RegexEngine.GetProvider() == newrxengine) - return; - //ServerInstance->SNO->WriteGlobalSno('a', "Dumping all filters due to regex engine change (was '%s', now '%s')", RegexEngine.GetProvider().c_str(), newrxengine.c_str()); - //ServerInstance->XLines->DelAll("R"); + std::string newrxengine = ServerInstance->Config->ConfValue("filteropts")->getString("engine"); + + factory = RegexEngine ? (RegexEngine.operator->()) : NULL; + + if (newrxengine.empty()) + RegexEngine.SetProvider("regex"); + else + RegexEngine.SetProvider("regex/" + newrxengine); - RegexEngine.SetProvider(newrxengine); if (!RegexEngine) { - ServerInstance->SNO->WriteGlobalSno('a', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", newrxengine.c_str()); + if (newrxengine.empty()) + ServerInstance->SNO->WriteGlobalSno('a', "WARNING: No regex engine loaded - Filter functionality disabled until this is corrected."); + else + ServerInstance->SNO->WriteGlobalSno('a', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", newrxengine.c_str()); + + initing = false; + FreeFilters(); + return; + } + + if ((!initing) && (RegexEngine.operator->() != factory)) + { + ServerInstance->SNO->WriteGlobalSno('a', "Dumping all filters due to regex engine change"); + FreeFilters(); } + + initing = false; ReadFilters(); } @@ -714,4 +731,18 @@ ModResult ModuleFilter::OnStats(char symbol, User* user, string_list &results) return MOD_RES_PASSTHRU; } +void ModuleFilter::OnUnloadModule(Module* mod) +{ + // If the regex engine became unavailable or has changed, remove all filters + if (!RegexEngine) + { + FreeFilters(); + } + else if (RegexEngine.operator->() != factory) + { + factory = RegexEngine.operator->(); + FreeFilters(); + } +} + MODULE_INIT(ModuleFilter) diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index a234c02c6..bbe8ede9a 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -224,9 +224,13 @@ class ModuleRLine : public Module RLineFactory f; CommandRLine r; bool MatchOnNickChange; + bool initing; + RegexFactory* factory; public: - ModuleRLine() : rxfactory(this, "regex"), f(rxfactory), r(this, f) + ModuleRLine() + : rxfactory(this, "regex"), f(rxfactory), r(this, f) + , initing(true) { } @@ -237,7 +241,7 @@ class ModuleRLine : public Module ServerInstance->Modules->AddService(r); ServerInstance->XLines->RegisterFactory(&f); - Implementation eventlist[] = { I_OnUserConnect, I_OnRehash, I_OnUserPostNick, I_OnStats, I_OnBackgroundTimer }; + Implementation eventlist[] = { I_OnUserConnect, I_OnRehash, I_OnUserPostNick, I_OnStats, I_OnBackgroundTimer, I_OnUnloadModule }; ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } @@ -272,14 +276,29 @@ class ModuleRLine : public Module ZlineOnMatch = tag->getBool("zlineonmatch"); std::string newrxengine = tag->getString("engine"); + factory = rxfactory ? (rxfactory.operator->()) : NULL; + if (newrxengine.empty()) rxfactory.SetProvider("regex"); else rxfactory.SetProvider("regex/" + newrxengine); + if (!rxfactory) { - ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", newrxengine.c_str()); + if (newrxengine.empty()) + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: No regex engine loaded - R-Line functionality disabled until this is corrected."); + else + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", newrxengine.c_str()); + + ServerInstance->XLines->DelAll(f.GetType()); } + else if ((!initing) && (rxfactory.operator->() != factory)) + { + ServerInstance->SNO->WriteToSnoMask('a', "Regex engine has changed, removing all R-Lines"); + ServerInstance->XLines->DelAll(f.GetType()); + } + + initing = false; } virtual ModResult OnStats(char symbol, User* user, string_list &results) @@ -317,6 +336,19 @@ class ModuleRLine : public Module } } + void OnUnloadModule(Module* mod) + { + // If the regex engine became unavailable or has changed, remove all rlines + if (!rxfactory) + { + ServerInstance->XLines->DelAll(f.GetType()); + } + else if (rxfactory.operator->() != factory) + { + factory = rxfactory.operator->(); + ServerInstance->XLines->DelAll(f.GetType()); + } + } }; MODULE_INIT(ModuleRLine) |