]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_filter_pcre.cpp
Changed behaviour of module API to pass Server* to the constructor, rather than have...
[user/henk/code/inspircd.git] / src / modules / extra / m_filter_pcre.cpp
index d05a72200df22b8cccf1acc3ea2d76ffef48e438..0e36115b9e2d5f9f6abb404e9ecae34a48758967 100644 (file)
@@ -14,6 +14,8 @@
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 // Message and notice filtering using regex patterns
 // a module based on the original work done by Craig Edwards in 2003
 // for the chatspike network.
@@ -24,6 +26,7 @@
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "helperfuncs.h"
 
 /* $ModDesc: m_filter with regexps */
 /* $CompileFlags: -I/usr/local/include -L/usr/local/lib -lpcre */
@@ -38,14 +41,15 @@ class ModuleFilterPCRE : public Module
        int erroffset;
  
  public:
-       ModuleFilterPCRE()
+       ModuleFilterPCRE(Server* Me)
+               : Module::Module(Me)
        {
                // read the configuration file on startup.
-               // it is perfectly valid to set <FilterPCRE file> to the value of the
+               // it is perfectly valid to set <filter file> to the value of the
                // main config file, then append your <keyword> tags to the bottom
                // of the main config... but rather messy. That's why the capability
                // of using a seperate config file is provided.
-               Srv = new Server;
+               Srv = Me;
                Conf = new ConfigReader;
                std::string filterfile = Conf->ReadValue("filter","file",0);
                MyConf = new ConfigReader(filterfile);
@@ -78,7 +82,6 @@ class ModuleFilterPCRE : public Module
        
        virtual ~ModuleFilterPCRE()
        {
-               delete Srv;
                delete MyConf;
                delete Conf;
        }
@@ -87,9 +90,8 @@ class ModuleFilterPCRE : public Module
        
        virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
        {
-               for (int index = 0; index < filters.size(); index++)
+               for (unsigned int index = 0; index < filters.size(); index++)
                {
-                       log(DEFAULT,"Match regexp %d: returned %d",index,pcre_exec(filters[index],NULL,text.c_str(),text.length(),0,0,NULL,0));
                        if (pcre_exec(filters[index],NULL,text.c_str(),text.length(),0,0,NULL,0) > -1)
                        {
                                std::string target = "";
@@ -135,7 +137,7 @@ class ModuleFilterPCRE : public Module
        
        virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
        {
-               for (int index = 0; index < filters.size(); index++)
+               for (unsigned int index = 0; index < filters.size(); index++)
                {
                        if (pcre_exec(filters[index],NULL,text.c_str(),text.length(),0,0,NULL,0) > -1)
                        {
@@ -158,13 +160,13 @@ class ModuleFilterPCRE : public Module
                                }
                                if (do_action == "block")
                                {       
-                                       Srv->SendOpers(std::string("FilterPCRE: ")+std::string(user->nick)+
+                                       Srv->SendOpers(std::string("Filter: ")+std::string(user->nick)+
                                                        std::string(" had their notice filtered, target was ")+
                                                        target+": "+reason);
                                        Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+
                                                        " :Your notice has been filtered and opers notified: "+reason);
                                }
-                               Srv->Log(DEFAULT,std::string("FilterPCRE: ")+std::string(user->nick)+
+                               Srv->Log(DEFAULT,std::string("Filter: ")+std::string(user->nick)+
                                                std::string(" had their notice filtered, target was ")+
                                                target+": "+reason+" Action: "+do_action);
 
@@ -178,7 +180,7 @@ class ModuleFilterPCRE : public Module
                return 0;
        }
        
-       virtual void OnRehash()
+       virtual void OnRehash(std::string parameter)
        {
                // reload our config file on rehash - we must destroy and re-allocate the classes
                // to call the constructor again and re-read our data.
@@ -195,7 +197,7 @@ class ModuleFilterPCRE : public Module
                        log(DEFAULT,"Error, could not find <filter file=\"\"> definition in your config file!");
                        return;
                }
-               Srv->Log(DEFAULT,std::string("m_Filter_pcre: read configuration from ")+filterfile);
+               Srv->Log(DEFAULT,std::string("m_filter_pcre: read configuration from ")+filterfile);
 
                 filters.clear();
                 for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
@@ -237,9 +239,9 @@ class ModuleFilterPCREFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleFilterPCRE;
+               return new ModuleFilterPCRE(Me);
        }
        
 };