#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 */
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);
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">
if (do_action == "kill")
{
- Srv->QuitUser(user,reason);
+ userrec::QuitUser(user,reason);
}
return 1;
}
return 0;
}
- virtual void OnRehash(std::string parameter)
+ virtual void OnRehash(const std::string ¶meter)
{
// 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());
+ }
+ }
}