diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-09-10 17:51:03 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-09-10 17:51:03 +0000 |
commit | a9c93027da4901123f9170a654d7c9802c40ea65 (patch) | |
tree | a62c632c4e4ff59891b7e8d51b533b16dd8361f4 | |
parent | 7ee9ca88a8a4aa0d671d331cee7ae132c7c1e1a3 (diff) |
Split hostmasks into ident and host pairs for matching as g/k/e lines. This allows them to be matched faster and more efficiently
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5203 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/xline.h | 7 | ||||
-rw-r--r-- | src/xline.cpp | 135 |
2 files changed, 106 insertions, 36 deletions
diff --git a/include/xline.h b/include/xline.h index 521035098..34bd0d920 100644 --- a/include/xline.h +++ b/include/xline.h @@ -67,6 +67,7 @@ class KLine : public XLine /** Hostmask (ident@host) to match against * May contain wildcards. */ + char identmask[20]; char hostmask[200]; }; @@ -78,6 +79,7 @@ class GLine : public XLine /** Hostmask (ident@host) to match against * May contain wildcards. */ + char identmask[20]; char hostmask[200]; }; @@ -89,6 +91,7 @@ class ELine : public XLine /** Hostmask (ident@host) to match against * May contain wildcards. */ + char identmask[20]; char hostmask[200]; }; @@ -133,6 +136,8 @@ bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); +typedef std::pair<std::string, std::string> IdentHostPair; + /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines. */ class XLineManager @@ -201,6 +206,8 @@ class XLineManager */ XLineManager(InspIRCd* Instance); + IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host); + /** Add a new GLine * @param duration The duration of the line * @param source The source of the line diff --git a/src/xline.cpp b/src/xline.cpp index 17dfa3f63..1c2ad77f9 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -92,15 +92,39 @@ bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, return true; } +IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host) +{ + IdentHostPair n = std::make_pair<std::string,std::string>("*","*"); + std::string::size_type x = ident_and_host.find('@'); + if (x != std::string::npos) + { + n.second = ident_and_host.substr(x + 1,ident_and_host.length()); + n.first = ident_and_host.substr(0, x); + if (!n.first.length()) + n.first = "*"; + if (!n.second.length()) + n.second = "*"; + } + else + { + n.second = ident_and_host; + } + + return n; +} + // adds a g:line bool XLineManager::add_gline(long duration, const char* source,const char* reason,const char* hostmask) { + IdentHostPair ih = IdentSplit(hostmask); + bool ret = del_gline(hostmask); GLine item; item.duration = duration; - strlcpy(item.hostmask,hostmask,199); + 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; @@ -123,10 +147,14 @@ bool XLineManager::add_gline(long duration, const char* source,const char* reaso bool XLineManager::add_eline(long duration, const char* source, const char* reason, const char* hostmask) { + IdentHostPair ih = IdentSplit(hostmask); + bool ret = del_eline(hostmask); + ELine item; item.duration = duration; - strlcpy(item.hostmask,hostmask,199); + 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; @@ -203,10 +231,14 @@ bool XLineManager::add_zline(long duration, const char* source, const char* reas bool XLineManager::add_kline(long duration, const char* source, const char* reason, const char* hostmask) { + IdentHostPair ih = IdentSplit(hostmask); + bool ret = del_kline(hostmask); + KLine item; item.duration = duration; - strlcpy(item.hostmask,hostmask,200); + 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; @@ -227,9 +259,10 @@ bool XLineManager::add_kline(long duration, const char* source, const char* reas bool XLineManager::del_gline(const char* hostmask) { + IdentHostPair ih = IdentSplit(hostmask); for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++) { - if (!strcasecmp(hostmask,i->hostmask)) + if (!strcasecmp(ih.first.c_str(),i->identmask) && !strcasecmp(ih.second.c_str(),i->hostmask)) { glines.erase(i); return true; @@ -237,7 +270,7 @@ bool XLineManager::del_gline(const char* hostmask) } for (std::vector<GLine>::iterator i = pglines.begin(); i != pglines.end(); i++) { - if (!strcasecmp(hostmask,i->hostmask)) + if (!strcasecmp(ih.first.c_str(),i->identmask) && !strcasecmp(ih.second.c_str(),i->hostmask)) { pglines.erase(i); return true; @@ -250,9 +283,10 @@ bool XLineManager::del_gline(const char* hostmask) bool XLineManager::del_eline(const char* hostmask) { + IdentHostPair ih = IdentSplit(hostmask); for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++) { - if (!strcasecmp(hostmask,i->hostmask)) + if (!strcasecmp(ih.first.c_str(),i->identmask) && !strcasecmp(ih.second.c_str(),i->hostmask)) { elines.erase(i); return true; @@ -260,7 +294,7 @@ bool XLineManager::del_eline(const char* hostmask) } for (std::vector<ELine>::iterator i = pelines.begin(); i != pelines.end(); i++) { - if (!strcasecmp(hostmask,i->hostmask)) + if (!strcasecmp(ih.first.c_str(),i->identmask) && !strcasecmp(ih.second.c_str(),i->hostmask)) { pelines.erase(i); return true; @@ -345,9 +379,10 @@ bool XLineManager::del_zline(const char* ipaddr) bool XLineManager::del_kline(const char* hostmask) { + IdentHostPair ih = IdentSplit(hostmask); for (std::vector<KLine>::iterator i = klines.begin(); i != klines.end(); i++) { - if (!strcasecmp(hostmask,i->hostmask)) + if (!strcasecmp(ih.first.c_str(),i->identmask) && !strcasecmp(ih.second.c_str(),i->hostmask)) { klines.erase(i); return true; @@ -355,7 +390,7 @@ bool XLineManager::del_kline(const char* hostmask) } for (std::vector<KLine>::iterator i = pklines.begin(); i != pklines.end(); i++) { - if (!strcasecmp(hostmask,i->hostmask)) + if (!strcasecmp(ih.first.c_str(),i->identmask) && !strcasecmp(ih.second.c_str(),i->hostmask)) { pklines.erase(i); return true; @@ -383,39 +418,57 @@ char* XLineManager::matches_qline(const char* nick) char* XLineManager::matches_gline(userrec* user) { - char match1[MAXBUF]; - char match2[MAXBUF]; - snprintf(match1, MAXBUF, "%s@%s", user->ident, user->GetIPString()); - snprintf(match2, MAXBUF, "%s@%s", user->ident, user->host); - if ((glines.empty()) && (pglines.empty())) return NULL; for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++) - if (match(match1,i->hostmask, true) || (match(match2,i->hostmask, true))) - return i->reason; + { + if ((match(user->ident,i->identmask))) + { + if ((match(user->host,i->hostmask, true)) || (match(user->GetIPString(),i->hostmask, true))) + { + return i->reason; + } + } + } for (std::vector<GLine>::iterator i = pglines.begin(); i != pglines.end(); i++) - if (match(match1,i->hostmask, true) || (match(match2,i->hostmask, true))) - return i->reason; + { + if ((match(user->ident,i->identmask))) + { + if ((match(user->host,i->hostmask, true)) || (match(user->GetIPString(),i->hostmask, true))) + { + return i->reason; + } + } + } return NULL; } char* XLineManager::matches_exception(userrec* user) -{ - char match1[MAXBUF]; - char match2[MAXBUF]; - snprintf(match1, MAXBUF, "%s@%s", user->ident, user->GetIPString()); - snprintf(match2, MAXBUF, "%s@%s", user->ident, user->host); - +{ if ((elines.empty()) && (pelines.empty())) return NULL; char host2[MAXBUF]; snprintf(host2,MAXBUF,"*@%s",user->host); for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++) - if ((match(match1,i->hostmask)) || (match(host2,i->hostmask, true)) || (match(match2,i->hostmask, true))) - return i->reason; + { + if ((match(user->ident,i->identmask))) + { + if ((match(user->host,i->hostmask, true)) || (match(user->GetIPString(),i->hostmask, true))) + { + return i->reason; + } + } + } for (std::vector<ELine>::iterator i = pelines.begin(); i != pelines.end(); i++) - if ((match(match1,i->hostmask)) || (match(host2,i->hostmask, true)) || (match(match2,i->hostmask, true))) - return i->reason; + { + if ((match(user->ident,i->identmask))) + { + if ((match(user->host,i->hostmask, true)) || (match(user->GetIPString(),i->hostmask, true))) + { + return i->reason; + } + } + } return NULL; } @@ -523,18 +576,28 @@ char* XLineManager::matches_zline(const char* ipaddr) char* XLineManager::matches_kline(userrec* user) { - char match1[MAXBUF]; - char match2[MAXBUF]; - snprintf(match1, MAXBUF, "%s@%s", user->ident, user->GetIPString()); - snprintf(match2, MAXBUF, "%s@%s", user->ident, user->host); if ((klines.empty()) && (pklines.empty())) return NULL; for (std::vector<KLine>::iterator i = klines.begin(); i != klines.end(); i++) - if ((match(match1,i->hostmask, true)) || (match(match2,i->hostmask, true))) - return i->reason; + { + if ((match(user->ident,i->identmask))) + { + if ((match(user->host,i->hostmask, true)) || (match(user->GetIPString(),i->hostmask, true))) + { + return i->reason; + } + } + } for (std::vector<KLine>::iterator i = pklines.begin(); i != pklines.end(); i++) - if ((match(match1,i->hostmask, true)) || (match(match2,i->hostmask, true))) - return i->reason; + { + if ((match(user->ident,i->identmask))) + { + if ((match(user->host,i->hostmask, true)) || (match(user->GetIPString(),i->hostmask, true))) + { + return i->reason; + } + } + } return NULL; } |