]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_filter_pcre.cpp
Updated copyrights in headers etc using perl inplace edit
[user/henk/code/inspircd.git] / src / modules / extra / m_filter_pcre.cpp
index 559bb686ae4ab0279e716bbd0e0f0e38f76a545c..ca002f578be98bd1b4adb480417891d3615a74c3 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2004 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -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.
@@ -27,7 +29,8 @@
 #include "helperfuncs.h"
 
 /* $ModDesc: m_filter with regexps */
-/* $CompileFlags: -I/usr/local/include -L/usr/local/lib -lpcre */
+/* $CompileFlags: -I/usr/local/include */
+/* $LinkerFlags: -L/usr/local/lib -lpcre */
 
 class ModuleFilterPCRE : public Module
 {
@@ -39,20 +42,21 @@ 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);
                if ((filterfile == "") || (!MyConf->Verify()))
                {
-                       printf("Error, could not find <filter file=\"\"> definition in your config file!");
+                       printf("Error, could not find <filter file=\"\"> definition in your config file!\n");
                        log(DEFAULT,"Error, could not find <filter file=\"\"> definition in your config file!");
                        return;
                }
@@ -79,16 +83,20 @@ class ModuleFilterPCRE : public Module
        
        virtual ~ModuleFilterPCRE()
        {
-               delete Srv;
                delete MyConf;
                delete Conf;
        }
-       
+
+        void Implements(char* List)
+        {
+                List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
+        }
+
        // format of a config entry is <keyword pattern="^regexp$" reason="Some reason here" action="kill/block">
        
        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++)
                {
                        if (pcre_exec(filters[index],NULL,text.c_str(),text.length(),0,0,NULL,0) > -1)
                        {
@@ -135,7 +143,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)
                        {
@@ -178,7 +186,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.
@@ -237,9 +245,9 @@ class ModuleFilterPCREFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleFilterPCRE;
+               return new ModuleFilterPCRE(Me);
        }
        
 };