A flags section for filters. Do not use yet.

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7177 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2007-05-28 20:30:51 +00:00
parent d12b1c4897
commit 30904ef950
3 changed files with 36 additions and 18 deletions

View File

@ -28,8 +28,8 @@ class PCREFilter : public FilterResult
public:
pcre* regexp;
PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat)
: FilterResult::FilterResult(pat, rea, act, gline_time), regexp(r)
PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat, bool operex)
: FilterResult::FilterResult(pat, rea, act, gline_time, operex), regexp(r)
{
}
@ -97,7 +97,7 @@ class ModuleFilterPCRE : public FilterBase
}
}
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration)
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, bool operexception)
{
for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++)
{
@ -117,7 +117,7 @@ class ModuleFilterPCRE : public FilterBase
}
else
{
filters.push_back(PCREFilter(re, reason, type, duration, freeform));
filters.push_back(PCREFilter(re, reason, type, duration, freeform, operexception));
return std::make_pair(true, "");
}
}
@ -133,6 +133,8 @@ class ModuleFilterPCRE : public FilterBase
std::string pattern = MyConf.ReadValue("keyword", "pattern", index);
std::string reason = MyConf.ReadValue("keyword", "reason", index);
std::string action = MyConf.ReadValue("keyword", "action", index);
// = MyConf.ReadFlag("keyword", "flags")
bool operexception = false;
long gline_time = ServerInstance->Duration(MyConf.ReadValue("keyword", "duration", index).c_str());
re = pcre_compile(pattern.c_str(),0,&error,&erroffset,NULL);
@ -144,7 +146,7 @@ class ModuleFilterPCRE : public FilterBase
}
else
{
filters.push_back(PCREFilter(re, reason, action, gline_time, pattern));
filters.push_back(PCREFilter(re, reason, action, gline_time, pattern, operexception));
ServerInstance->Log(DEFAULT,"Regular expression %s loaded.", pattern.c_str());
}
}

View File

@ -68,7 +68,7 @@ class ModuleFilter : public FilterBase
return false;
}
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration)
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, bool operexclusion)
{
if (filters.find(freeform) != filters.end())
{
@ -80,6 +80,7 @@ class ModuleFilter : public FilterBase
x->action = type;
x->gline_time = duration;
x->freeform = freeform;
x->opers_exempt = operexclusion;
filters[freeform] = x;
return std::make_pair(true, "");

View File

@ -20,8 +20,10 @@ class FilterResult : public classbase
std::string reason;
std::string action;
long gline_time;
bool opers_exempt;
FilterResult(const std::string free, const std::string &rea, const std::string &act, long gt) : freeform(free), reason(rea), action(act), gline_time(gt)
FilterResult(const std::string free, const std::string &rea, const std::string &act, long gt, bool operex = false) : freeform(free), reason(rea),
action(act), gline_time(gt), opers_exempt(operex)
{
}
@ -48,7 +50,7 @@ class FilterBase : public Module
virtual bool DeleteFilter(const std::string &freeform) = 0;
virtual void SyncFilters(Module* proto, void* opaque) = 0;
virtual void SendFilter(Module* proto, void* opaque, FilterResult* iter);
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration) = 0;
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, bool operexempt) = 0;
virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
virtual void OnRehash(userrec* user, const std::string &parameter);
virtual Version GetVersion();
@ -67,7 +69,7 @@ class cmd_filter : public command_t
cmd_filter(FilterBase* f, InspIRCd* Me, const std::string &source) : command_t(Me, "FILTER", 'o', 1), Base(f)
{
this->source = source;
this->syntax = "<filter-definition> <type> [<gline-duration>] :<reason>";
this->syntax = "<filter-definition> <type> <flags> [<gline-duration>] :<reason>";
}
CmdResult Handle(const char** parameters, int pcnt, userrec *user)
@ -89,12 +91,24 @@ class cmd_filter : public command_t
else
{
/* Adding a filter */
if (pcnt >= 3)
if (pcnt >= 4)
{
std::string freeform = parameters[0];
std::string type = parameters[1];
std::string flags = parameters[2];
std::string reason;
long duration = 0;
bool operexempt = false;
for (std::string::const_iterator n = flags.begin(); n != flags.end(); ++n)
{
switch (*n)
{
case 'o':
operexempt = true;
break;
}
}
if ((type != "gline") && (type != "none") && (type != "block") && (type != "kill") && (type != "silent"))
{
@ -104,10 +118,10 @@ class cmd_filter : public command_t
if (type == "gline")
{
if (pcnt >= 4)
if (pcnt >= 5)
{
duration = ServerInstance->Duration(parameters[2]);
reason = parameters[3];
duration = ServerInstance->Duration(parameters[3]);
reason = parameters[4];
}
else
{
@ -117,13 +131,13 @@ class cmd_filter : public command_t
}
else
{
reason = parameters[2];
reason = parameters[3];
}
std::pair<bool, std::string> result = Base->AddFilter(freeform, type, reason, duration);
std::pair<bool, std::string> result = Base->AddFilter(freeform, type, reason, duration, operexempt);
if (result.first)
{
user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s'%s%s, reason: '%s'", user->nick, freeform.c_str(),
type.c_str(), (duration ? " duration: " : ""), (duration ? parameters[2] : ""),
type.c_str(), (duration ? " duration: " : ""), (duration ? parameters[3] : ""),
reason.c_str());
return CMD_SUCCESS;
}
@ -322,7 +336,7 @@ std::string FilterBase::EncodeFilter(FilterResult* filter)
if (*n == ' ')
*n = '\7';
stream << x << " " << filter->action << " " << filter->gline_time << " " << filter->reason;
stream << x << " " << filter->action << " " << filter->opers_exempt << " " << filter->gline_time << " " << filter->reason;
return stream.str();
}
@ -333,6 +347,7 @@ FilterResult FilterBase::DecodeFilter(const std::string &data)
stream >> res.freeform;
stream >> res.action;
stream >> res.opers_exempt;
stream >> res.gline_time;
res.reason = stream.str();
@ -358,7 +373,7 @@ void FilterBase::OnDecodeMetaData(int target_type, void* target, const std::stri
if ((target_type == TYPE_OTHER) && (extname == "filter"))
{
FilterResult data = DecodeFilter(extdata);
this->AddFilter(data.freeform, data.action, data.reason, data.gline_time);
this->AddFilter(data.freeform, data.action, data.reason, data.gline_time, data.opers_exempt);
}
}