From 9f477a1083574d01c78f12d95772ed122607a4ad Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 10 Nov 2006 17:54:14 +0000 Subject: 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 --- src/modules/extra/m_filter_pcre.cpp | 49 +++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/modules/extra') 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::iterator i = filters.begin(); i != filters.end(); i++) + { + if (i->pattern == freeform) + { + filters.erase(i); + return true; + } + } + return false; + } + + virtual std::pair AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration) + { + for (std::vector::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()); } } -- cgit v1.2.3