diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-10 17:54:14 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-10 17:54:14 +0000 |
commit | 9f477a1083574d01c78f12d95772ed122607a4ad (patch) | |
tree | 8294c89e61fe99079e31bfa55fe276c792b36eaf /src/modules/extra | |
parent | 6692d15462003157768a15c86192399b5b73e3c2 (diff) |
Implement the /filter command. Note that this is currently untested, and propogation of filters between servers on burst isnt implemented yet (This is next on my todo)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5667 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra')
-rw-r--r-- | src/modules/extra/m_filter_pcre.cpp | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp index e03d27b59..8d50193af 100644 --- a/src/modules/extra/m_filter_pcre.cpp +++ b/src/modules/extra/m_filter_pcre.cpp @@ -30,15 +30,16 @@ /* $ModDesc: m_filter with regexps */ /* $CompileFlags: `pcre-config --cflags` */ /* $LinkerFlags: `pcre-config --libs` `perl extra/pcre_rpath.pl` -lpcre */ -/* $ModDep: ../m_filter.h */ +/* $ModDep: m_filter.h */ class PCREFilter : public FilterResult { public: pcre* regexp; + std::string pattern; - PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time) - : FilterResult::FilterResult(rea, act, gline_time), regexp(r) + PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat) + : FilterResult::FilterResult(rea, act, gline_time), regexp(r), pattern(pat) { } }; @@ -74,7 +75,45 @@ class ModuleFilterPCRE : public FilterBase } return NULL; } - + + virtual bool DeleteFilter(const std::string &freeform) + { + for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++) + { + if (i->pattern == freeform) + { + filters.erase(i); + return true; + } + } + return false; + } + + virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration) + { + for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++) + { + if (i->pattern == freeform) + { + return std::make_pair(false, "Filter already exists"); + } + } + + re = pcre_compile(freeform.c_str(),0,&error,&erroffset,NULL); + + if (!re) + { + ServerInstance->Log(DEFAULT,"Error in regular expression: %s at offset %d: %s\n", freeform.c_str(), erroffset, error); + ServerInstance->Log(DEFAULT,"Regular expression %s not loaded.", freeform.c_str()); + return std::make_pair(false, "Error in regular expression at offset " + ConvToStr(erroffset) + ": "+error); + } + else + { + filters.push_back(PCREFilter(re, reason, type, duration, freeform)); + return std::make_pair(true, ""); + } + } + virtual void OnRehash(const std::string ¶meter) { ConfigReader MyConf(ServerInstance); @@ -100,7 +139,7 @@ class ModuleFilterPCRE : public FilterBase } else { - filters.push_back(PCREFilter(re, reason, action, gline_time)); + filters.push_back(PCREFilter(re, reason, action, gline_time, pattern)); ServerInstance->Log(DEFAULT,"Regular expression %s loaded.", pattern.c_str()); } } |