diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-11-02 13:45:02 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-11-02 13:45:02 +0000 |
commit | 5ecd5447d0f52592b121778f251965179597466d (patch) | |
tree | e74e92a0ca2d37f423fad58a1a5578cc0aef1124 | |
parent | 68b55aa455ad78bb5939aa7c94645df2d339bec1 (diff) |
Tidy up, and make the identifer for a line type be std::string not char
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8459 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/xline.h | 75 | ||||
-rw-r--r-- | src/commands/cmd_eline.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_gline.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_kline.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_nick.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_qline.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_rehash.cpp | 2 | ||||
-rw-r--r-- | src/commands/cmd_stats.cpp | 6 | ||||
-rw-r--r-- | src/commands/cmd_zline.cpp | 2 | ||||
-rw-r--r-- | src/configreader.cpp | 2 | ||||
-rw-r--r-- | src/inspircd.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket2.cpp | 8 | ||||
-rw-r--r-- | src/users.cpp | 10 | ||||
-rw-r--r-- | src/xline.cpp | 106 |
14 files changed, 94 insertions, 129 deletions
diff --git a/include/xline.h b/include/xline.h index 7e0e7f56e..5f982b1c5 100644 --- a/include/xline.h +++ b/include/xline.h @@ -36,7 +36,7 @@ class CoreExport XLine : public classbase protected: InspIRCd* ServerInstance; - void DefaultApply(User* u, char line); + void DefaultApply(User* u, const std::string &line); public: @@ -46,7 +46,7 @@ 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, const char t) + XLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const std::string &t) : ServerInstance(Instance), set_time(s_time), duration(d), type(t) { source = strdup(src); @@ -72,11 +72,6 @@ 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(const std::string &str) = 0; - virtual bool Matches(const std::string &str) = 0; virtual void Apply(User* u); @@ -111,7 +106,7 @@ class CoreExport XLine : public classbase /** Q, K, etc. Don't change this. Constructors set it. */ - const char type; + const std::string type; }; /** KLine class @@ -127,7 +122,7 @@ 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, 'K') + 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); @@ -147,8 +142,6 @@ class CoreExport KLine : public XLine virtual bool Matches(const std::string &str); - virtual bool MatchesLiteral(const std::string &str); - virtual void Apply(User* u); virtual void DisplayExpiry(); @@ -178,7 +171,7 @@ 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, 'G') + 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); @@ -198,8 +191,6 @@ class CoreExport GLine : public XLine virtual bool Matches(const std::string &str); - virtual bool MatchesLiteral(const std::string &str); - virtual void Apply(User* u); virtual void DisplayExpiry(); @@ -229,7 +220,7 @@ 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, 'E') + 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); @@ -247,8 +238,6 @@ class CoreExport ELine : public XLine virtual bool Matches(const std::string &str); - virtual bool MatchesLiteral(const std::string &str); - virtual void Unset(); virtual void DisplayExpiry(); @@ -279,7 +268,7 @@ 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, 'Z') + 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); } @@ -295,8 +284,6 @@ 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(); @@ -320,7 +307,7 @@ 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, 'Q') + 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); } @@ -336,8 +323,6 @@ 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(); @@ -359,13 +344,13 @@ class CoreExport XLineFactory protected: InspIRCd* ServerInstance; - const char type; + std::string type; public: - XLineFactory(InspIRCd* Instance, const char t) : ServerInstance(Instance), type(t) { } + XLineFactory(InspIRCd* Instance, const std::string &t) : ServerInstance(Instance), type(t) { } - virtual const char GetType() { return type; } + virtual const std::string& GetType() { return type; } virtual XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) = 0; @@ -383,6 +368,12 @@ class QLineFactory; class ZLineFactory; class KLineFactory; +typedef std::map<std::string, XLineFactory*> XLineFactMap; +typedef std::map<std::string, XLine *> XLineLookup; +typedef std::map<std::string, XLineLookup > XLineContainer; +typedef XLineContainer::iterator ContainerIter; +typedef XLineLookup::iterator LookupIter; + /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines. */ class CoreExport XLineManager @@ -396,7 +387,7 @@ class CoreExport XLineManager */ std::vector<XLine *> pending_lines; - std::map<char, XLineFactory*> line_factory; + XLineFactMap line_factory; GLineFactory* GFact; ELineFactory* EFact; @@ -406,7 +397,7 @@ class CoreExport XLineManager public: - std::map<char, std::map<std::string, XLine *> > lookup_lines; + XLineContainer lookup_lines; /** Constructor * @param Instance A pointer to the creator object @@ -420,10 +411,9 @@ class CoreExport XLineManager */ IdentHostPair IdentSplit(const std::string &ident_and_host); - /** Checks what users match a given list of ELines and sets their ban exempt flag accordingly. - * @param ELines List of E:Lines to check. + /** Checks what users match e:lines and sets their ban exempt flag accordingly. */ - void CheckELines(std::map<std::string, XLine *> &ELines); + void CheckELines(); /** Add a new GLine * @param line The line to be added @@ -439,7 +429,7 @@ class CoreExport XLineManager * @param simulate If this is true, don't actually remove the line, just return * @return True if the line was deleted successfully */ - bool DelLine(const char* hostmask, char type, User* user, bool simulate = false); + bool DelLine(const char* hostmask, const std::string &type, User* user, bool simulate = false); /** Registers an xline factory. * An xline factory is a class which when given a particular xline type, @@ -459,25 +449,25 @@ class CoreExport XLineManager /** Get the XLineFactory for a specific type. * Returns NULL if there is no known handler for this xline type */ - XLineFactory* GetFactory(const char type); + XLineFactory* GetFactory(const std::string &type); /** Check if a user matches an XLine * @param type The type of line to look up * @param user The user to match against (what is checked is specific to the xline type) * @return The reason for the line if there is a match, or NULL if there is no match */ - XLine* MatchesLine(const char type, User* user); + XLine* MatchesLine(const std::string &type, User* user); /** Check if a pattern matches an XLine * @param type The type of line to look up * @param pattern A pattern string specific to the xline type * @return The matching XLine if there is a match, or NULL if there is no match */ - XLine* MatchesLine(const char type, const std::string &pattern); + XLine* MatchesLine(const std::string &type, const std::string &pattern); /** Expire a line given two iterators which identify it */ - void ExpireLine(std::map<char, std::map<std::string, XLine*> >::iterator container, std::map<std::string, XLine*>::iterator item); + void ExpireLine(ContainerIter container, LookupIter item); /** Apply any new lines that are pending to be applied */ @@ -488,13 +478,13 @@ class CoreExport XLineManager * @param user The username making the query * @param results The string_list to receive the results */ - void InvokeStats(const char type, int numeric, User* user, string_list &results); + void InvokeStats(const std::string &type, int numeric, User* user, string_list &results); }; class CoreExport GLineFactory : public XLineFactory { public: - GLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'G') { } + GLineFactory(InspIRCd* Instance) : XLineFactory(Instance, "G") { } XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) { @@ -506,7 +496,7 @@ class CoreExport GLineFactory : public XLineFactory class CoreExport ELineFactory : public XLineFactory { public: - ELineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'E') { } + ELineFactory(InspIRCd* Instance) : XLineFactory(Instance, "E") { } XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) { @@ -518,7 +508,7 @@ class CoreExport ELineFactory : public XLineFactory class CoreExport KLineFactory : public XLineFactory { public: - KLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'K') { } + KLineFactory(InspIRCd* Instance) : XLineFactory(Instance, "K") { } XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) { @@ -530,7 +520,7 @@ class CoreExport KLineFactory : public XLineFactory class CoreExport QLineFactory : public XLineFactory { public: - QLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'Q') { } + QLineFactory(InspIRCd* Instance) : XLineFactory(Instance, "Q") { } XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) { @@ -541,7 +531,7 @@ class CoreExport QLineFactory : public XLineFactory class CoreExport ZLineFactory : public XLineFactory { public: - ZLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'Z') { } + ZLineFactory(InspIRCd* Instance) : XLineFactory(Instance, "Z") { } XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) { @@ -550,3 +540,4 @@ class CoreExport ZLineFactory : public XLineFactory }; #endif + diff --git a/src/commands/cmd_eline.cpp b/src/commands/cmd_eline.cpp index cd0627178..83c921d8b 100644 --- a/src/commands/cmd_eline.cpp +++ b/src/commands/cmd_eline.cpp @@ -60,7 +60,7 @@ CmdResult CommandEline::Handle (const char** parameters, int pcnt, User *user) } else { - if (ServerInstance->XLines->DelLine(parameters[0], 'E', user)) + if (ServerInstance->XLines->DelLine(parameters[0], "E", user)) { ServerInstance->SNO->WriteToSnoMask('x',"%s Removed E-line on %s.",user->nick,parameters[0]); } diff --git a/src/commands/cmd_gline.cpp b/src/commands/cmd_gline.cpp index abe29d18e..caed54ebe 100644 --- a/src/commands/cmd_gline.cpp +++ b/src/commands/cmd_gline.cpp @@ -67,7 +67,7 @@ CmdResult CommandGline::Handle (const char** parameters, int pcnt, User *user) } else { - if (ServerInstance->XLines->DelLine(parameters[0],'G',user)) + if (ServerInstance->XLines->DelLine(parameters[0],"G",user)) { ServerInstance->SNO->WriteToSnoMask('x',"%s Removed G-line on %s.",user->nick,parameters[0]); } diff --git a/src/commands/cmd_kline.cpp b/src/commands/cmd_kline.cpp index de225b0f0..7058de77f 100644 --- a/src/commands/cmd_kline.cpp +++ b/src/commands/cmd_kline.cpp @@ -66,7 +66,7 @@ CmdResult CommandKline::Handle (const char** parameters, int pcnt, User *user) } else { - if (ServerInstance->XLines->DelLine(parameters[0],'K',user)) + if (ServerInstance->XLines->DelLine(parameters[0],"K",user)) { ServerInstance->SNO->WriteToSnoMask('x',"%s Removed K-line on %s.",user->nick,parameters[0]); } diff --git a/src/commands/cmd_nick.cpp b/src/commands/cmd_nick.cpp index aaa6698ac..06fc5dcc3 100644 --- a/src/commands/cmd_nick.cpp +++ b/src/commands/cmd_nick.cpp @@ -60,7 +60,7 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user) } else { - XLine* mq = ServerInstance->XLines->MatchesLine('Q',parameters[0]); + XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]); if (mq) { ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason); diff --git a/src/commands/cmd_qline.cpp b/src/commands/cmd_qline.cpp index 2922c09cf..e4da8c5ff 100644 --- a/src/commands/cmd_qline.cpp +++ b/src/commands/cmd_qline.cpp @@ -59,7 +59,7 @@ CmdResult CommandQline::Handle (const char** parameters, int pcnt, User *user) } else { - if (ServerInstance->XLines->DelLine(parameters[0],'Q',user)) + if (ServerInstance->XLines->DelLine(parameters[0],"Q",user)) { ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Q-line on %s.",user->nick,parameters[0]); } diff --git a/src/commands/cmd_rehash.cpp b/src/commands/cmd_rehash.cpp index 5b1ab019c..174fba8ba 100644 --- a/src/commands/cmd_rehash.cpp +++ b/src/commands/cmd_rehash.cpp @@ -41,7 +41,7 @@ CmdResult CommandRehash::Handle (const char** parameters, int pcnt, User *user) FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); ServerInstance->Config->Read(false,user); // Get XLine to do it's thing. - ServerInstance->XLines->CheckELines(ServerInstance->XLines->lookup_lines['E']); + ServerInstance->XLines->CheckELines(ServerInstance->XLines->lookup_lines["E"]); ServerInstance->XLines->ApplyLines(); ServerInstance->Res->Rehash(); ServerInstance->ResetMaxBans(); diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp index 5d4417689..0e8a5a0b0 100644 --- a/src/commands/cmd_stats.cpp +++ b/src/commands/cmd_stats.cpp @@ -144,6 +144,7 @@ DllExport void DoStats(InspIRCd* ServerInstance, char statschar, User* user, str case 'q': case 'Z': case 'e': + { /* FIXME: Make the 216 here different depending on stats char: * k: 216 * g: 223 @@ -151,7 +152,10 @@ DllExport void DoStats(InspIRCd* ServerInstance, char statschar, User* user, str * z: 223 * e: 223 */ - ServerInstance->XLines->InvokeStats(toupper(statschar),216,user,results); + std::string stat; + stat += toupper(statschar); + ServerInstance->XLines->InvokeStats(stat,216,user,results); + } break; /* stats m (list number of times each command has been used, plus bytecount) */ diff --git a/src/commands/cmd_zline.cpp b/src/commands/cmd_zline.cpp index e701867fb..520bea306 100644 --- a/src/commands/cmd_zline.cpp +++ b/src/commands/cmd_zline.cpp @@ -67,7 +67,7 @@ CmdResult CommandZline::Handle (const char** parameters, int pcnt, User *user) } else { - if (ServerInstance->XLines->DelLine(parameters[0],'Z',user)) + if (ServerInstance->XLines->DelLine(parameters[0],"Z",user)) { ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Z-line on %s.",user->nick,parameters[0]); } diff --git a/src/configreader.cpp b/src/configreader.cpp index 8311ad58e..7c6f784f4 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -1983,7 +1983,7 @@ bool DoneELine(ServerConfig* conf, const char* tag) u->exempt = false; } - conf->GetInstance()->XLines->CheckELines(conf->GetInstance()->XLines->lookup_lines['E']); + conf->GetInstance()->XLines->CheckELines(); return true; } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 095787376..f62e2a74b 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -437,7 +437,7 @@ InspIRCd::InspIRCd(int argc, char** argv) Config->Read(true, NULL); // Get XLine to do it's thing. - this->XLines->CheckELines(this->XLines->lookup_lines['E']); + this->XLines->CheckELines(); this->XLines->ApplyLines(); this->Modules->modules.resize(255); diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 5468be25b..914de861f 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -523,7 +523,7 @@ bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> &par if (params.size() < 6) return true; - XLineFactory* xlf = Instance->XLines->GetFactory(params[0][0]); + XLineFactory* xlf = Instance->XLines->GetFactory(params[0]); if (!xlf) return false; @@ -534,11 +534,13 @@ bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> &par { if (xl->expiry) { - this->Instance->SNO->WriteToSnoMask('x',"%s Added %cLINE on %s to expire on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),Instance->TimeString(xl->expiry).c_str(),params[5].c_str()); + this->Instance->SNO->WriteToSnoMask('x',"%s Added %s%s on %s to expire on %s (%s).",prefix.c_str(),params[0].c_str(),params[0].length() == 1 ? "LINE" : "", + params[1].c_str(),Instance->TimeString(xl->expiry).c_str(),params[5].c_str()); } else { - this->Instance->SNO->WriteToSnoMask('x',"%s Added permenant %cLINE on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),params[5].c_str()); + this->Instance->SNO->WriteToSnoMask('x',"%s Added permenant %s%s on %s (%s).",prefix.c_str(),params[0].c_str(),params[0].length() == 1 ? "LINE" : "", + params[1].c_str(),params[5].c_str()); } params[5] = ":" + params[5]; Utils->DoOneToAllButSender(prefix,"ADDLINE",params,prefix); diff --git a/src/users.cpp b/src/users.cpp index 0f451d2a9..3803a7a9e 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -830,10 +830,10 @@ void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, in } #endif - New->exempt = (Instance->XLines->MatchesLine('E',New) != NULL); + New->exempt = (Instance->XLines->MatchesLine("E",New) != NULL); if (!New->exempt) { - XLine* r = Instance->XLines->MatchesLine('Z',New); + XLine* r = Instance->XLines->MatchesLine("Z",New); if (r) { @@ -942,7 +942,7 @@ void User::FullConnect() if (!this->exempt) { - XLine* r = ServerInstance->XLines->MatchesLine('G',this); + XLine* r = ServerInstance->XLines->MatchesLine("G",this); if (r) { @@ -955,7 +955,7 @@ void User::FullConnect() return; } - XLine* n = ServerInstance->XLines->MatchesLine('K',this); + XLine* n = ServerInstance->XLines->MatchesLine("K",this); if (n) { @@ -1065,7 +1065,7 @@ bool User::ForceNickChange(const char* newnick) return false; } - if (ServerInstance->XLines->MatchesLine('Q',newnick)) + if (ServerInstance->XLines->MatchesLine("Q",newnick)) { ServerInstance->stats->statsCollisions++; return false; diff --git a/src/xline.cpp b/src/xline.cpp index a26ca7f01..47522f77d 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -57,8 +57,15 @@ bool XLine::Matches(User *u) /* * Checks what users match a given vector of ELines and sets their ban exempt flag accordingly. */ -void XLineManager::CheckELines(std::map<std::string, XLine *> &ELines) +void XLineManager::CheckELines() { + ContainerIter n = ServerInstance->XLines->lookup_lines.find("E"); + + if (n == ServerInstance->XLines->lookup_lines.end()) + return; + + XLineLookup& ELines = n->second; + if (ELines.empty()) return; @@ -66,7 +73,7 @@ void XLineManager::CheckELines(std::map<std::string, XLine *> &ELines) { User* u = (User*)(*u2); - for (std::map<std::string, XLine *>::iterator i = ELines.begin(); i != ELines.end(); i++) + for (LookupIter i = ELines.begin(); i != ELines.end(); i++) { XLine *e = i->second; u->exempt = e->Matches(u); @@ -74,19 +81,6 @@ void XLineManager::CheckELines(std::map<std::string, XLine *> &ELines) } } -// this should probably be moved to configreader, but atm it relies on CheckELines above. -bool DoneELine(ServerConfig* conf, const char* tag) -{ - for (std::vector<User*>::const_iterator u2 = conf->GetInstance()->local_users.begin(); u2 != conf->GetInstance()->local_users.end(); u2++) - { - User* u = (User*)(*u2); - u->exempt = false; - } - - conf->GetInstance()->XLines->CheckELines(conf->GetInstance()->XLines->lookup_lines['E']); - return true; -} - IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host) { @@ -109,9 +103,8 @@ IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host) return n; } -// adds a g:line +// adds a line -/*bool XLineManager::AddELine(long duration, const char* source, const char* reason, const char* hostmask)*/ bool XLineManager::AddLine(XLine* line, User* user) { /*IdentHostPair ih = IdentSplit(hostmask);*/ @@ -131,14 +124,14 @@ bool XLineManager::AddLine(XLine* line, User* user) // deletes a line, returns true if the line existed and was removed -bool XLineManager::DelLine(const char* hostmask, char type, User* user, bool simulate) +bool XLineManager::DelLine(const char* hostmask, const std::string &type, User* user, bool simulate) { - std::map<char, std::map<std::string, XLine*> >::iterator x = lookup_lines.find(type); + ContainerIter x = lookup_lines.find(type); if (x == lookup_lines.end()) return false; - std::map<std::string, XLine*>::iterator y = x->second.find(hostmask); + LookupIter y = x->second.find(hostmask); if (y == x->second.end()) return false; @@ -170,23 +163,23 @@ void ELine::Unset() u->exempt = false; } - std::map<char, std::map<std::string, XLine*> >::iterator x = ServerInstance->XLines->lookup_lines.find('E'); + ContainerIter x = ServerInstance->XLines->lookup_lines.find("E"); if (x != ServerInstance->XLines->lookup_lines.end()) - ServerInstance->XLines->CheckELines(x->second); + ServerInstance->XLines->CheckELines(); } // returns a pointer to the reason if a nickname matches a qline, NULL if it didnt match -XLine* XLineManager::MatchesLine(const char type, User* user) +XLine* XLineManager::MatchesLine(const std::string &type, User* user) { - std::map<char, std::map<std::string, XLine*> >::iterator x = lookup_lines.find(type); + ContainerIter x = lookup_lines.find(type); if (x == lookup_lines.end()) return NULL; const time_t current = ServerInstance->Time(); - for (std::map<std::string, XLine*>::iterator i = x->second.begin(); i != x->second.end(); i++) + for (LookupIter i = x->second.begin(); i != x->second.end(); i++) { if (i->second->Matches(user)) { @@ -203,16 +196,16 @@ XLine* XLineManager::MatchesLine(const char type, User* user) return NULL; } -XLine* XLineManager::MatchesLine(const char type, const std::string &pattern) +XLine* XLineManager::MatchesLine(const std::string &type, const std::string &pattern) { - std::map<char, std::map<std::string, XLine*> >::iterator x = lookup_lines.find(type); + ContainerIter x = lookup_lines.find(type); if (x == lookup_lines.end()) return NULL; const time_t current = ServerInstance->Time(); - for (std::map<std::string, XLine*>::iterator i = x->second.begin(); i != x->second.end(); i++) + for (LookupIter i = x->second.begin(); i != x->second.end(); i++) { if (i->second->Matches(pattern)) { @@ -230,7 +223,7 @@ XLine* XLineManager::MatchesLine(const char type, const std::string &pattern) } // removes lines that have expired -void XLineManager::ExpireLine(std::map<char, std::map<std::string, XLine*> >::iterator container, std::map<std::string, XLine*>::iterator item) +void XLineManager::ExpireLine(ContainerIter container, LookupIter item) { item->second->DisplayExpiry(); item->second->Unset(); @@ -273,16 +266,16 @@ void XLineManager::ApplyLines() * e: 223 */ -void XLineManager::InvokeStats(const char type, int numeric, User* user, string_list &results) +void XLineManager::InvokeStats(const std::string &type, int numeric, User* user, string_list &results) { std::string sn = ServerInstance->Config->ServerName; - std::map<const char, std::map<std::string, XLine*> >::iterator n = lookup_lines.find(type); + ContainerIter n = lookup_lines.find(type); if (n != lookup_lines.end()) { - std::map<std::string, XLine*>& list = n->second; - for (std::map<std::string, XLine*>::iterator i = list.begin(); i != list.end(); i++) + XLineLookup& list = n->second; + for (LookupIter i = list.begin(); i != list.end(); i++) results.push_back(sn+" "+ConvToStr(numeric)+" "+user->nick+" :"+i->second->Displayable()+" "+ ConvToStr(i->second->set_time)+" "+ConvToStr(i->second->duration)+" "+std::string(i->second->source)+" :"+(i->second->reason)); } @@ -323,14 +316,14 @@ void XLine::Apply(User* u) { } -void XLine::DefaultApply(User* u, char line) +void XLine::DefaultApply(User* u, const std::string &line) { char reason[MAXBUF]; - snprintf(reason, MAXBUF, "%c-Lined: %s", line, this->reason); + snprintf(reason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason); if (*ServerInstance->Config->MoronBanner) u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner); if (ServerInstance->Config->HideBans) - User::QuitUser(ServerInstance, u, line + std::string("-Lined"), reason); + User::QuitUser(ServerInstance, u, line + "-Lined", reason); else User::QuitUser(ServerInstance, u, reason); } @@ -353,7 +346,7 @@ bool KLine::Matches(User *u) void KLine::Apply(User* u) { - DefaultApply(u, 'K'); + DefaultApply(u, "K"); } bool GLine::Matches(User *u) @@ -374,7 +367,7 @@ bool GLine::Matches(User *u) void GLine::Apply(User* u) { - DefaultApply(u, 'G'); + DefaultApply(u, "G"); } bool ELine::Matches(User *u) @@ -406,7 +399,7 @@ bool ZLine::Matches(User *u) void ZLine::Apply(User* u) { - DefaultApply(u, 'Z'); + DefaultApply(u, "Z"); } @@ -424,7 +417,7 @@ bool QLine::Matches(User *u) void QLine::Apply(User* u) { /* Can we force the user to their uid here instead? */ - DefaultApply(u, 'Q'); + DefaultApply(u, "Q"); } @@ -459,31 +452,6 @@ bool GLine::Matches(const std::string &str) return ((match(str.c_str(), matchtext.c_str(), true))); } -bool ELine::MatchesLiteral(const std::string &str) -{ - return (assign(str) == matchtext); -} - -bool ZLine::MatchesLiteral(const std::string &str) -{ - return (assign(str) == this->ipaddr); -} - -bool GLine::MatchesLiteral(const std::string &str) -{ - return (assign(str) == matchtext); -} - -bool KLine::MatchesLiteral(const std::string &str) -{ - return (assign(str) == matchtext); -} - -bool QLine::MatchesLiteral(const std::string &str) -{ - return (assign(str) == this->nick); -} - void ELine::OnAdd() { /* When adding one eline, only check the one eline */ @@ -547,7 +515,7 @@ const char* QLine::Displayable() bool XLineManager::RegisterFactory(XLineFactory* xlf) { - std::map<char, XLineFactory*>::iterator n = line_factory.find(xlf->GetType()); + XLineFactMap::iterator n = line_factory.find(xlf->GetType()); if (n != line_factory.end()) return false; @@ -559,7 +527,7 @@ bool XLineManager::RegisterFactory(XLineFactory* xlf) bool XLineManager::UnregisterFactory(XLineFactory* xlf) { - std::map<char, XLineFactory*>::iterator n = line_factory.find(xlf->GetType()); + XLineFactMap::iterator n = line_factory.find(xlf->GetType()); if (n == line_factory.end()) return false; @@ -569,9 +537,9 @@ bool XLineManager::UnregisterFactory(XLineFactory* xlf) return true; } -XLineFactory* XLineManager::GetFactory(const char type) +XLineFactory* XLineManager::GetFactory(const std::string &type) { - std::map<char, XLineFactory*>::iterator n = line_factory.find(type); + XLineFactMap::iterator n = line_factory.find(type); if (n != line_factory.end()) return NULL; |