summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/xline.h80
-rw-r--r--src/xline.cpp126
2 files changed, 73 insertions, 133 deletions
diff --git a/include/xline.h b/include/xline.h
index 6540d57f6..5b81eef82 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -46,8 +46,8 @@ class CoreExport XLine : public classbase
* @param src The sender of the xline
* @param re The reason of the xline
*/
- XLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re)
- : ServerInstance(Instance), set_time(s_time), duration(d)
+ XLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char t)
+ : ServerInstance(Instance), set_time(s_time), duration(d), type(t)
{
source = strdup(src);
reason = strdup(re);
@@ -66,14 +66,21 @@ class CoreExport XLine : public classbase
*/
virtual bool Matches(User *u) = 0;
+ /** Returns true wether or not the given string exactly matches the gline
+ * (no wildcard use in this method) -- used for removal of a line
+ */
+ virtual bool MatchesLiteral(std::string &str) = 0;
+
virtual bool Matches(const std::string &str);
virtual void Apply(User* u);
- virtual void Unset() { };
+ virtual void Unset() { }
virtual void DisplayExpiry() = 0;
+ virtual void OnAdd() { }
+
/** The time the line was added.
*/
time_t set_time;
@@ -96,7 +103,7 @@ class CoreExport XLine : public classbase
/** Q, K, etc. Don't change this. Constructors set it.
*/
- char type;
+ const char type;
};
/** KLine class
@@ -112,11 +119,10 @@ class CoreExport KLine : public XLine
* @param ident Ident to match
* @param host Host to match
*/
- KLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re)
+ KLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re, 'K')
{
identmask = strdup(ident);
hostmask = strdup(host);
- type = 'K';
}
/** Destructor
@@ -129,6 +135,8 @@ class CoreExport KLine : public XLine
virtual bool Matches(User *u);
+ virtual bool MatchesLiteral(const std::string &str);
+
virtual void Apply(User* u);
virtual void DisplayExpiry();
@@ -154,11 +162,10 @@ class CoreExport GLine : public XLine
* @param ident Ident to match
* @param host Host to match
*/
- GLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re)
+ GLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re, 'G')
{
identmask = strdup(ident);
hostmask = strdup(host);
- type = 'G';
}
/** Destructor
@@ -171,6 +178,8 @@ class CoreExport GLine : public XLine
virtual bool Matches(User *u);
+ virtual bool MatchesLiteral(const std::string &str);
+
virtual void Apply(User* u);
virtual void DisplayExpiry();
@@ -196,11 +205,10 @@ class CoreExport ELine : public XLine
* @param ident Ident to match
* @param host Host to match
*/
- ELine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re)
+ ELine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re, 'E')
{
identmask = strdup(ident);
hostmask = strdup(host);
- type = 'E';
}
~ELine()
@@ -211,10 +219,14 @@ class CoreExport ELine : public XLine
virtual bool Matches(User *u);
+ virtual bool MatchesLiteral(const std::string &str);
+
virtual void Unset();
virtual void DisplayExpiry();
+ virtual void OnAdd();
+
/** Ident mask
*/
char* identmask;
@@ -235,10 +247,9 @@ class CoreExport ZLine : public XLine
* @param re The reason of the xline
* @param ip IP to match
*/
- ZLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(Instance, s_time, d, src, re)
+ ZLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(Instance, s_time, d, src, re, 'Z')
{
ipaddr = strdup(ip);
- type = 'Z';
}
/** Destructor
@@ -252,6 +263,8 @@ class CoreExport ZLine : public XLine
virtual bool Matches(const std::string &str);
+ virtual bool MatchesLiteral(const std::string &str);
+
virtual void Apply(User* u);
virtual void DisplayExpiry();
@@ -273,10 +286,9 @@ class CoreExport QLine : public XLine
* @param re The reason of the xline
* @param nickname Nickname to match
*/
- QLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(Instance, s_time, d, src, re)
+ QLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(Instance, s_time, d, src, re, 'Q')
{
nick = strdup(nickname);
- type = 'Q';
}
/** Destructor
@@ -290,6 +302,8 @@ class CoreExport QLine : public XLine
virtual bool Matches(const std::string &str);
+ virtual bool MatchesLiteral(const std::string &str);
+
virtual void Apply(User* u);
virtual void DisplayExpiry();
@@ -357,43 +371,7 @@ class CoreExport XLineManager
* @param hostmask The hostmask
* @return True if the line was added successfully
*/
- bool AddGLine(long duration, const char* source, const char* reason, const char* hostmask);
-
- /** Add a new QLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param nickname The nickmask
- * @return True if the line was added successfully
- */
- bool AddQLine(long duration, const char* source, const char* reason, const char* nickname);
-
- /** Add a new ZLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param ipaddr The IP mask
- * @return True if the line was added successfully
- */
- bool AddZLine(long duration, const char* source, const char* reason, const char* ipaddr);
-
- /** Add a new KLine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param hostmask The hostmask
- * @return True if the line was added successfully
- */
- bool AddKLine(long duration, const char* source, const char* reason, const char* hostmask);
-
- /** Add a new ELine
- * @param duration The duration of the line
- * @param source The source of the line
- * @param reason The reason for the line
- * @param hostmask The hostmask
- * @return True if the line was added successfully
- */
- bool AddELine(long duration, const char* source, const char* reason, const char* hostmask);
+ bool AddLine(XLine* line);
/** Delete a GLine
* @param hostmask The host to remove
diff --git a/src/xline.cpp b/src/xline.cpp
index 08226f650..9a56450ff 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -125,104 +125,36 @@ IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host)
// adds a g:line
-bool XLineManager::AddGLine(long duration, const char* source,const char* reason,const char* hostmask)
+/*bool XLineManager::AddELine(long duration, const char* source, const char* reason, const char* hostmask)*/
+bool XLineManager::AddLine(XLine* line)
{
- IdentHostPair ih = IdentSplit(hostmask);
+ /*IdentHostPair ih = IdentSplit(hostmask);*/
- if (DelLine(hostmask, 'G', true))
+ if (DelLine(hostmask, line->type, true))
return false;
- GLine* item = new GLine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ /*ELine* item = new ELine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());*/
active_lines.push_back(item);
- sort(active_lines.begin(), active_lines.end(),XLineManager::XSortComparison);
- pending_lines.push_back(item);
- lookup_lines['G'][hostmask] = item;
-
- return true;
-}
-
-// adds an e:line (exception to bans)
-
-bool XLineManager::AddELine(long duration, const char* source, const char* reason, const char* hostmask)
-{
- IdentHostPair ih = IdentSplit(hostmask);
-
- if (DelLine(hostmask, 'E', true))
- return false;
-
- ELine* item = new ELine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
-
- active_lines.push_back(item);
- sort(active_lines.begin(), active_lines.end(),XLineManager::XSortComparison);
- lookup_lines['E'][hostmask] = item;
+ sort(active_lines.begin(), active_lines.end(), XLineManager::XSortComparison);
+ lookup_lines[line->type][hostmask] = item;
+ line->OnAdd();
// XXX we really only need to check one line (the new one) - this is a bit wasteful!
// we should really create a temporary var here and pass that instead.
// hmm, perhaps we can merge this with line "application" somehow.. and just force a recheck on DelELine?
- this->CheckELines(lookup_lines['E']);
- return true;
-}
-
-// adds a q:line
-
-bool XLineManager::AddQLine(long duration, const char* source, const char* reason, const char* nickname)
-{
- if (DelLine(nickname, 'Q', true))
- return false;
-
- QLine* item = new QLine(ServerInstance, ServerInstance->Time(), duration, source, reason, nickname);
-
- active_lines.push_back(item);
- sort(active_lines.begin(), active_lines.end(), XLineManager::XSortComparison);
- pending_lines.push_back(item);
- lookup_lines['Q'][nickname] = item;
-
- return true;
+ /*this->CheckELines(lookup_lines['E']);
+ return true;*/
}
-// adds a z:line
-
-bool XLineManager::AddZLine(long duration, const char* source, const char* reason, const char* ipaddr)
+/*bool XLineManager::AddZLine(long duration, const char* source, const char* reason, const char* ipaddr)
{
if (strchr(ipaddr,'@'))
{
while (*ipaddr != '@')
ipaddr++;
ipaddr++;
- }
-
- if (DelLine(ipaddr, 'Z', true))
- return false;
-
- ZLine* item = new ZLine(ServerInstance, ServerInstance->Time(), duration, source, reason, ipaddr);
-
- active_lines.push_back(item);
- sort(active_lines.begin(), active_lines.end(),XLineManager::XSortComparison);
- pending_lines.push_back(item);
- lookup_lines['Z'][ipaddr] = item;
-
- return true;
-}
-
-// adds a k:line
-
-bool XLineManager::AddKLine(long duration, const char* source, const char* reason, const char* hostmask)
-{
- IdentHostPair ih = IdentSplit(hostmask);
-
- if (DelLine(hostmask, 'K', true))
- return false;
-
- KLine* item = new KLine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
-
- active_lines.push_back(item);
- sort(active_lines.begin(), active_lines.end(),XLineManager::XSortComparison);
- pending_lines.push_back(item);
- lookup_lines['K'][hostmask] = item;
-
- return true;
-}
+ }*/
// deletes a g:line, returns true if the line existed and was removed
@@ -233,7 +165,7 @@ bool XLineManager::DelLine(const char* hostmask, char type, bool simulate)
{
if ((*i)->type == type)
{
- if ((*i)->Matches(hostmask))
+ if ((*i)->MatchesLiteral(hostmask))
{
if (!simulate)
{
@@ -626,6 +558,36 @@ bool QLine::Matches(const std::string &str)
return false;
}
+virtual bool ELine::MatchesLiteral(const std::string &str)
+{
+ return (assign(str) == irc::string(this->identmask) + '@' + this->hostmask);
+}
+
+virtual bool ZLine::MatchesLiteral(const std::string &str)
+{
+ return (assign(str) == this->ipmask);
+}
+
+virtual bool GLine::MatchesLiteral(const std::string &str)
+{
+ return (assign(str) == irc::string(this->identmask) + '@' + this->hostmask);
+}
+
+virtual bool KLine::MatchesLiteral(const std::string &str)
+{
+ return (assign(str) == irc::string(this->identmask) + '@' + this->hostmask);
+}
+
+virtual bool QLine::MatchesLiteral(const std::string &str)
+{
+ return (assign(str) == this->nickmask);
+}
+
+virtual void ELine::OnAdd()
+{
+ ServerInstance->XLines->CheckELines(ServerInstance->XLines->lookup_lines['E']);
+}
+
void ELine::DisplayExpiry()
{
ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed E-Line %s@%s (set by %s %d seconds ago)",this->identmask,this->hostmask,this->source,this->duration);
@@ -633,7 +595,7 @@ void ELine::DisplayExpiry()
void QLine::DisplayExpiry()
{
- ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed G-Line %s (set by %s %d seconds ago)",this->nick,this->source,this->duration);
+ ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed Q-Line %s (set by %s %d seconds ago)",this->nick,this->source,this->duration);
}
void ZLine::DisplayExpiry()