]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_filter_pcre.cpp
kill_link() and Server::QuitUser() -> userrec::QuitUser() (static member) - this...
[user/henk/code/inspircd.git] / src / modules / extra / m_filter_pcre.cpp
index f6ec64d6c5ece563e2b99f8103430b409ad127ef..a658a60b6b879a364643f644e79ede3b354f9e9a 100644 (file)
@@ -28,6 +28,15 @@ using namespace std;
 #include "modules.h"
 #include "helperfuncs.h"
 
+class FilterPCREException : public ModuleException
+{
+ public:
+       virtual const char* GetReason()
+       {
+               return "Could not find <filter file=\"\"> definition in your config file!";
+       }
+};
+
 /* $ModDesc: m_filter with regexps */
 /* $CompileFlags: -I/usr/local/include */
 /* $LinkerFlags: -L/usr/local/lib -lpcre */
@@ -56,9 +65,8 @@ class ModuleFilterPCRE : public Module
                MyConf = new ConfigReader(filterfile);
                if ((filterfile == "") || (!MyConf->Verify()))
                {
-                       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;
+                       FilterPCREException e;
+                       throw(e);
                }
                Srv->Log(DEFAULT,std::string("m_filter_pcre: read configuration from ")+filterfile);
 
@@ -83,14 +91,14 @@ class ModuleFilterPCRE : public Module
        
        virtual ~ModuleFilterPCRE()
        {
-               delete MyConf;
-               delete Conf;
+               DELETE(MyConf);
+               DELETE(Conf);
        }
 
-        void Implements(char* List)
-        {
-                List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
-        }
+       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">
        
@@ -136,7 +144,7 @@ class ModuleFilterPCRE : public Module
 
                                if (do_action == "kill")
                                {
-                                       Srv->QuitUser(user,reason);
+                                       userrec::QuitUser(user,reason);
                                }
                                return 1;
                        }
@@ -144,41 +152,40 @@ class ModuleFilterPCRE : public Module
                return 0;
        }
        
-       virtual void OnRehash(std::string parameter)
+       virtual void OnRehash(const 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.
-               delete Conf;
-               delete MyConf;
+               DELETE(Conf);
+               DELETE(MyConf);
                Conf = new ConfigReader;
                std::string filterfile = Conf->ReadValue("filter","file",0);
                // this automatically re-reads the configuration file into the class
                MyConf = new ConfigReader(filterfile);
                if ((filterfile == "") || (!MyConf->Verify()))
                {
+                       FilterPCREException e;
                        // bail if the user forgot to create a config file
-                       printf("Error, could not find <filter file=\"\"> definition in your config file!");
-                       log(DEFAULT,"Error, could not find <filter file=\"\"> definition in your config file!");
-                       return;
+                       throw(e);
                }
                Srv->Log(DEFAULT,std::string("m_filter_pcre: read configuration from ")+filterfile);
 
-                filters.clear();
-                for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
-                {
-                        std::string pattern = MyConf->ReadValue("keyword","pattern",index);
-                        re = pcre_compile(pattern.c_str(),0,&error,&erroffset,NULL);
-                        if (!re)
-                        {
-                                log(DEFAULT,"Error in regular expression: %s at offset %d: %s\n", pattern.c_str(), erroffset, error);
-                                log(DEFAULT,"Regular expression %s not loaded.", pattern.c_str());
-                        }
-                        else
-                        {
-                                filters.push_back(re);
-                                log(DEFAULT,"Regular expression %s loaded.", pattern.c_str());
-                        }
-                }
+               filters.clear();
+               for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
+               {
+                       std::string pattern = MyConf->ReadValue("keyword","pattern",index);
+                       re = pcre_compile(pattern.c_str(),0,&error,&erroffset,NULL);
+                       if (!re)
+                       {
+                               log(DEFAULT,"Error in regular expression: %s at offset %d: %s\n", pattern.c_str(), erroffset, error);
+                               log(DEFAULT,"Regular expression %s not loaded.", pattern.c_str());
+                       }
+                       else
+                       {
+                               filters.push_back(re);
+                               log(DEFAULT,"Regular expression %s loaded.", pattern.c_str());
+                       }
+               }
 
        }