summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-10 18:23:24 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-10 18:23:24 +0000
commitbfc97ea14213c1ee9cb34386dfc33c0c1f665aca (patch)
tree796773deb96bd44171a9b01310259174c6cde4e8 /src/modules
parent745994473896e59faa59e4caf3fb621ef974419a (diff)
Implement on-burst synching of filters
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5669 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_filter_pcre.cpp15
-rw-r--r--src/modules/m_filter.cpp10
-rw-r--r--src/modules/m_filter.h49
3 files changed, 69 insertions, 5 deletions
diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp
index 14b4d6d4a..dde7575ab 100644
--- a/src/modules/extra/m_filter_pcre.cpp
+++ b/src/modules/extra/m_filter_pcre.cpp
@@ -36,10 +36,9 @@ class PCREFilter : public FilterResult
{
public:
pcre* regexp;
- std::string pattern;
PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat)
- : FilterResult::FilterResult(rea, act, gline_time), regexp(r), pattern(pat)
+ : FilterResult::FilterResult(pat, rea, act, gline_time), regexp(r)
{
}
};
@@ -80,7 +79,7 @@ class ModuleFilterPCRE : public FilterBase
{
for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++)
{
- if (i->pattern == freeform)
+ if (i->freeform == freeform)
{
filters.erase(i);
return true;
@@ -89,11 +88,19 @@ class ModuleFilterPCRE : public FilterBase
return false;
}
+ virtual void SyncFilters(Module* proto, void* opaque)
+ {
+ for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++)
+ {
+ this->SendFilter(proto, opaque, &(*i));
+ }
+ }
+
virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration)
{
for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++)
{
- if (i->pattern == freeform)
+ if (i->freeform == freeform)
{
return std::make_pair(false, "Filter already exists");
}
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index 0b6c386ba..88665e8b3 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -83,11 +83,20 @@ class ModuleFilter : public FilterBase
x->reason = reason;
x->action = type;
x->gline_time = duration;
+ x->freeform = freeform;
filters[freeform] = x;
return std::make_pair(true, "");
}
+ virtual void SyncFilters(Module* proto, void* opaque)
+ {
+ for (filter_t::iterator n = filters.begin(); n != filters.end(); n++)
+ {
+ this->SendFilter(proto, opaque, n->second);
+ }
+ }
+
virtual void OnRehash(const std::string &parameter)
{
// this automatically re-reads the configuration file into the class
@@ -109,6 +118,7 @@ class ModuleFilter : public FilterBase
x->reason = reason;
x->action = do_action;
x->gline_time = gline_time;
+ x->freeform = pattern;
filters[pattern] = x;
}
DELETE(MyConf);
diff --git a/src/modules/m_filter.h b/src/modules/m_filter.h
index 437928a29..d93e94cb8 100644
--- a/src/modules/m_filter.h
+++ b/src/modules/m_filter.h
@@ -19,11 +19,12 @@
class FilterResult : public classbase
{
public:
+ std::string freeform;
std::string reason;
std::string action;
long gline_time;
- FilterResult(const std::string &rea, const std::string &act, long gt) : reason(rea), action(act), gline_time(gt)
+ FilterResult(const std::string free, const std::string &rea, const std::string &act, long gt) : freeform(free), reason(rea), action(act), gline_time(gt)
{
}
@@ -46,12 +47,20 @@ class FilterBase : public Module
virtual ~FilterBase();
virtual void Implements(char* List);
virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status);
+
virtual FilterResult* FilterMatch(const std::string &text) = 0;
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 int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status);
virtual void OnRehash(const std::string &parameter);
virtual Version GetVersion();
+ std::string EncodeFilter(FilterResult* filter);
+ FilterResult DecodeFilter(const std::string &data);
+ virtual void OnSyncOtherMetaData(Module* proto, void* opaque);
+ virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata);
};
class cmd_filter : public command_t
@@ -210,3 +219,41 @@ Version FilterBase::GetVersion()
return Version(1,1,0,2,VF_VENDOR,API_VERSION);
}
+
+std::string FilterBase::EncodeFilter(FilterResult* filter)
+{
+ std::ostringstream stream;
+ stream << filter->freeform << " " << filter->action << " " << filter->gline_time << " " << filter->reason;
+ return stream.str();
+}
+
+FilterResult FilterBase::DecodeFilter(const std::string &data)
+{
+ FilterResult res;
+ std::istringstream stream(data);
+ stream >> res.freeform;
+ stream >> res.action;
+ stream >> res.gline_time;
+ res.reason = stream.str();
+ return res;
+}
+
+void FilterBase::OnSyncOtherMetaData(Module* proto, void* opaque)
+{
+ this->SyncFilters(proto, opaque);
+}
+
+void FilterBase::SendFilter(Module* proto, void* opaque, FilterResult* iter)
+{
+ proto->ProtoSendMetaData(opaque, TYPE_OTHER, NULL, "filter", EncodeFilter(iter));
+}
+
+void FilterBase::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+{
+ if ((target_type == TYPE_OTHER) && (extname == "filter"))
+ {
+ FilterResult data = DecodeFilter(extdata);
+ this->AddFilter(data.freeform, data.action, data.reason, data.gline_time);
+ }
+}
+