summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-19 13:44:09 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-19 13:44:09 +0000
commit89dc9ab19899e8bde4761da2e3f86194cf34fc21 (patch)
treec7b89f6b06c22164620cc0841feee35f4a747a11
parent136b8e0f8c75f61e063f9c4f0acdf0c139d0f892 (diff)
Make xline more memory-efficient and faster/neater. Eliminate a mass of fixed-size buffer and strlcpy
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5300 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/xline.h113
-rw-r--r--src/xline.cpp77
2 files changed, 89 insertions, 101 deletions
diff --git a/include/xline.h b/include/xline.h
index bfa810c97..bec693da6 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -37,6 +37,18 @@ class XLine : public classbase
{
public:
+ XLine(time_t s_time, long d, const char* src, const char* re)
+ : set_time(s_time), duration(d)
+ {
+ source = strdup(src);
+ reason = strdup(re);
+ }
+
+ virtual ~XLine()
+ {
+ free(reason);
+ free(source);
+ }
/** The time the line was added.
*/
time_t set_time;
@@ -47,16 +59,11 @@ class XLine : public classbase
/** Source of the ban. This can be a servername or an oper nickname
*/
- char source[256];
+ char* source;
/** Reason for the ban
*/
- char reason[MAXBUF];
-
- /** Number of times the core matches the ban, for statistics
- */
- long n_matches;
-
+ char* reason;
};
/** KLine class
@@ -67,8 +74,20 @@ class KLine : public XLine
/** Hostmask (ident@host) to match against
* May contain wildcards.
*/
- char identmask[20];
- char hostmask[200];
+ KLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
+ {
+ identmask = strdup(ident);
+ hostmask = strdup(host);
+ }
+
+ ~KLine()
+ {
+ free(identmask);
+ free(hostmask);
+ }
+
+ char* identmask;
+ char* hostmask;
};
/** GLine class
@@ -79,8 +98,20 @@ class GLine : public XLine
/** Hostmask (ident@host) to match against
* May contain wildcards.
*/
- char identmask[20];
- char hostmask[200];
+ GLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
+ {
+ identmask = strdup(ident);
+ hostmask = strdup(host);
+ }
+
+ ~GLine()
+ {
+ free(identmask);
+ free(hostmask);
+ }
+
+ char* identmask;
+ char* hostmask;
};
/** ELine class
@@ -91,8 +122,20 @@ class ELine : public XLine
/** Hostmask (ident@host) to match against
* May contain wildcards.
*/
- char identmask[20];
- char hostmask[200];
+ ELine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
+ {
+ identmask = strdup(ident);
+ hostmask = strdup(host);
+ }
+
+ ~ELine()
+ {
+ free(identmask);
+ free(hostmask);
+ }
+
+ char* identmask;
+ char* hostmask;
};
/** ZLine class
@@ -103,11 +146,17 @@ class ZLine : public XLine
/** IP Address (xx.yy.zz.aa) to match against
* May contain wildcards.
*/
- char ipaddr[40];
- /** Set if this is a global Z:line
- * (e.g. it came from another server)
- */
- bool is_global;
+ ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
+ {
+ ipaddr = strdup(ip);
+ }
+
+ ~ZLine()
+ {
+ free(ipaddr);
+ }
+
+ char* ipaddr;
};
/** QLine class
@@ -118,11 +167,17 @@ class QLine : public XLine
/** Nickname to match against.
* May contain wildcards.
*/
- char nick[64];
- /** Set if this is a global Z:line
- * (e.g. it came from another server)
- */
- bool is_global;
+ QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
+ {
+ nick = strdup(nickname);
+ }
+
+ ~QLine()
+ {
+ free(nick);
+ }
+
+ char* nick;
};
class ServerConfig;
@@ -376,18 +431,6 @@ class XLineManager
* @param create_Time The new creation time
*/
void eline_set_creation_time(const char* host, time_t create_time);
-
- /** Make a ZLine global
- * @param ipaddr The zline to change
- * @return True if the zline was updated
- */
- bool zline_make_global(const char* ipaddr);
-
- /** Make a QLine global
- * @param nickname The qline to change
- * @return True if the qline was updated
- */
- bool qline_make_global(const char* nickname);
};
#endif
diff --git a/src/xline.cpp b/src/xline.cpp
index a0ac98df2..eb00eaee0 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -121,14 +121,7 @@ bool XLineManager::add_gline(long duration, const char* source,const char* reaso
bool ret = del_gline(hostmask);
- GLine item;
- item.duration = duration;
- strlcpy(item.identmask,ih.first.c_str(),19);
- strlcpy(item.hostmask,ih.second.c_str(),199);
- strlcpy(item.reason,reason,MAXBUF);
- strlcpy(item.source,source,255);
- item.n_matches = 0;
- item.set_time = ServerInstance->Time();
+ GLine item(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
if (duration)
{
@@ -151,14 +144,8 @@ bool XLineManager::add_eline(long duration, const char* source, const char* reas
bool ret = del_eline(hostmask);
- ELine item;
- item.duration = duration;
- strlcpy(item.identmask,ih.first.c_str(),19);
- strlcpy(item.hostmask,ih.second.c_str(),199);
- strlcpy(item.reason,reason,MAXBUF);
- strlcpy(item.source,source,255);
- item.n_matches = 0;
- item.set_time = ServerInstance->Time();
+ ELine item(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
+
if (duration)
{
elines.push_back(item);
@@ -176,14 +163,8 @@ bool XLineManager::add_eline(long duration, const char* source, const char* reas
bool XLineManager::add_qline(long duration, const char* source, const char* reason, const char* nickname)
{
bool ret = del_qline(nickname);
- QLine item;
- item.duration = duration;
- strlcpy(item.nick,nickname,63);
- strlcpy(item.reason,reason,MAXBUF);
- strlcpy(item.source,source,255);
- item.n_matches = 0;
- item.is_global = false;
- item.set_time = ServerInstance->Time();
+ QLine item(ServerInstance->Time(), duration, source, reason, nickname);
+
if (duration)
{
qlines.push_back(item);
@@ -201,20 +182,16 @@ bool XLineManager::add_qline(long duration, const char* source, const char* reas
bool XLineManager::add_zline(long duration, const char* source, const char* reason, const char* ipaddr)
{
bool ret = del_zline(ipaddr);
- ZLine item;
- item.duration = duration;
+
if (strchr(ipaddr,'@'))
{
while (*ipaddr != '@')
ipaddr++;
ipaddr++;
}
- strlcpy(item.ipaddr,ipaddr,39);
- strlcpy(item.reason,reason,MAXBUF);
- strlcpy(item.source,source,255);
- item.n_matches = 0;
- item.is_global = false;
- item.set_time = ServerInstance->Time();
+
+ ZLine item(ServerInstance->Time(), duration, source, reason, ipaddr);
+
if (duration)
{
zlines.push_back(item);
@@ -235,14 +212,8 @@ bool XLineManager::add_kline(long duration, const char* source, const char* reas
bool ret = del_kline(hostmask);
- KLine item;
- item.duration = duration;
- strlcpy(item.identmask,ih.first.c_str(),19);
- strlcpy(item.hostmask,ih.second.c_str(),200);
- strlcpy(item.reason,reason,MAXBUF);
- strlcpy(item.source,source,255);
- item.n_matches = 0;
- item.set_time = ServerInstance->Time();
+ KLine item(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
+
if (duration)
{
klines.push_back(item);
@@ -326,32 +297,6 @@ bool XLineManager::del_qline(const char* nickname)
return false;
}
-bool XLineManager::qline_make_global(const char* nickname)
-{
- for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
- {
- if (!strcasecmp(nickname,i->nick))
- {
- i->is_global = true;
- return true;
- }
- }
- return false;
-}
-
-bool XLineManager::zline_make_global(const char* ipaddr)
-{
- for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
- {
- if (!strcasecmp(ipaddr,i->ipaddr))
- {
- i->is_global = true;
- return true;
- }
- }
- return false;
-}
-
// deletes a z:line, returns true if the line existed and was removed
bool XLineManager::del_zline(const char* ipaddr)