diff --git a/Chan.cpp b/Chan.cpp index cb99141b..246c43c6 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -269,7 +269,7 @@ void CChan::ModeChange(const CString& sModes, const CString& sOpNick) { IncPermCount(uPerm); } - if (pNick->GetNick().CaseCmp(m_pUser->GetCurNick()) == 0) { + if (pNick->GetNick().Equals(m_pUser->GetCurNick())) { AddPerm(uPerm); } } else { @@ -277,7 +277,7 @@ void CChan::ModeChange(const CString& sModes, const CString& sOpNick) { DecPermCount(uPerm); } - if (pNick->GetNick().CaseCmp(m_pUser->GetCurNick()) == 0) { + if (pNick->GetNick().Equals(m_pUser->GetCurNick())) { RemPerm(uPerm); } } @@ -466,7 +466,7 @@ bool CChan::AddNick(const CString& sNick) { } } - if (pNick->GetNick().CaseCmp(m_pUser->GetCurNick()) == 0) { + if (pNick->GetNick().Equals(m_pUser->GetCurNick())) { for (CString::size_type i = 0; i < sPrefix.length(); i++) { AddPerm(sPrefix[i]); } diff --git a/Client.cpp b/Client.cpp index 3846c728..7c9e6e23 100644 --- a/Client.cpp +++ b/Client.cpp @@ -83,7 +83,7 @@ void CClient::ReadLine(const CString& sData) { sCommand = sLine.Token(0); } - if (sCommand.CaseCmp("PASS") == 0) { + if (sCommand.Equals("PASS")) { if (!IsAttached()) { m_bGotPass = true; m_sPass = sLine.Token(1); @@ -99,7 +99,7 @@ void CClient::ReadLine(const CString& sData) { return; // Don't forward this msg. ZNC has already registered us. } - } else if (sCommand.CaseCmp("NICK") == 0) { + } else if (sCommand.Equals("NICK")) { CString sNick = sLine.Token(1); if (sNick.Left(1) == ":") { sNick.LeftChomp(); @@ -119,7 +119,7 @@ void CClient::ReadLine(const CString& sData) { // No need to forward it return; } - } else if (sCommand.CaseCmp("USER") == 0) { + } else if (sCommand.Equals("USER")) { if (!IsAttached()) { if (m_sUser.empty()) { m_sUser = sLine.Token(1); @@ -144,7 +144,7 @@ void CClient::ReadLine(const CString& sData) { return; } - if (sCommand.CaseCmp("ZNC") == 0) { + if (sCommand.Equals("ZNC")) { CString sTarget = sLine.Token(1); CString sModCommand; @@ -155,7 +155,7 @@ void CClient::ReadLine(const CString& sData) { sModCommand = sLine.Token(1, true); } - if (sTarget.CaseCmp("status") == 0) { + if (sTarget.Equals("status")) { if (sModCommand.empty()) PutStatus("Hello. How may I help you?"); else @@ -169,7 +169,7 @@ void CClient::ReadLine(const CString& sData) { #endif } return; - } else if (sCommand.CaseCmp("DETACH") == 0) { + } else if (sCommand.Equals("DETACH")) { CString sChan = sLine.Token(1); if (sChan.empty()) { @@ -186,19 +186,19 @@ void CClient::ReadLine(const CString& sData) { pChan->DetachUser(); PutStatusNotice("Detached from [" + sChan + "]"); return; - } else if (sCommand.CaseCmp("PING") == 0) { + } else if (sCommand.Equals("PING")) { CString sTarget = sLine.Token(1); // If the client meant to ping us or we can be sure the server // won't answer the ping (=no server connected) -> PONG back. // else: It's the server's job to send a PONG. - if (sTarget.CaseCmp("irc.znc.in") == 0 || !m_pIRCSock) { + if (sTarget.Equals("irc.znc.in") || !m_pIRCSock) { PutClient("PONG " + sLine.substr(5)); return; } - } else if (sCommand.CaseCmp("PONG") == 0) { + } else if (sCommand.Equals("PONG")) { return; // Block pong replies, we already responded to the pings - } else if (sCommand.CaseCmp("JOIN") == 0) { + } else if (sCommand.Equals("JOIN")) { CString sChans = sLine.Token(1); CString sKey = sLine.Token(2); @@ -235,7 +235,7 @@ void CClient::ReadLine(const CString& sData) { if (!sKey.empty()) { sLine += " " + sKey; } - } else if (sCommand.CaseCmp("PART") == 0) { + } else if (sCommand.Equals("PART")) { CString sChan = sLine.Token(1); CString sMessage = sLine.Token(2, true); @@ -262,7 +262,7 @@ void CClient::ReadLine(const CString& sData) { if (!sMessage.empty()) { sLine += " :" + sMessage; } - } else if (sCommand.CaseCmp("TOPIC") == 0) { + } else if (sCommand.Equals("TOPIC")) { CString sChan = sLine.Token(1); CString sTopic = sLine.Token(2, true); @@ -274,7 +274,7 @@ void CClient::ReadLine(const CString& sData) { } else { MODULECALL(OnUserTopicRequest(sChan), m_pUser, this, return); } - } else if (sCommand.CaseCmp("MODE") == 0) { + } else if (sCommand.Equals("MODE")) { CString sTarget = sLine.Token(1); CString sModes = sLine.Token(2, true); @@ -289,23 +289,23 @@ void CClient::ReadLine(const CString& sData) { return; } } - } else if (sCommand.CaseCmp("QUIT") == 0) { + } else if (sCommand.Equals("QUIT")) { m_pUser->UserDisconnected(this); Close(); // Treat a client quit as a detach return; // Don't forward this msg. We don't want the client getting us disconnected. - } else if (sCommand.CaseCmp("PROTOCTL") == 0) { + } else if (sCommand.Equals("PROTOCTL")) { unsigned int i = 1; while (!sLine.Token(i).empty()) { - if (sLine.Token(i).CaseCmp("NAMESX") == 0) { + if (sLine.Token(i).Equals("NAMESX")) { m_bNamesx = true; - } else if (sLine.Token(i).CaseCmp("UHNAMES") == 0) { + } else if (sLine.Token(i).Equals("UHNAMES")) { m_bUHNames = true; } i++; } return; // If the server understands it, we already enabled namesx / uhnames - } else if (sCommand.CaseCmp("NOTICE") == 0) { + } else if (sCommand.Equals("NOTICE")) { CString sTarget = sLine.Token(1); CString sMsg = sLine.Token(2, true); @@ -315,7 +315,7 @@ void CClient::ReadLine(const CString& sData) { if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) { #ifdef _MODULES - if (sTarget.CaseCmp("status") != 0) { + if (!sTarget.Equals("status")) { CALLMOD(sTarget, this, m_pUser, OnModNotice(sMsg)); } #endif @@ -342,7 +342,7 @@ void CClient::ReadLine(const CString& sData) { if (!m_pIRCSock) { // Some lagmeters do a NOTICE to their own nick, ignore those. - if (sTarget.CaseCmp(m_sNick) != 0) + if (!sTarget.Equals(m_sNick)) PutStatus("Your notice to [" + sTarget + "] got lost, " "you are not connected to IRC!"); return; @@ -369,7 +369,7 @@ void CClient::ReadLine(const CString& sData) { PutIRC("NOTICE " + sTarget + " :" + sMsg); return; - } else if (sCommand.CaseCmp("PRIVMSG") == 0) { + } else if (sCommand.Equals("PRIVMSG")) { CString sTarget = sLine.Token(1); CString sMsg = sLine.Token(2, true); @@ -382,7 +382,7 @@ void CClient::ReadLine(const CString& sData) { sCTCP.LeftChomp(); sCTCP.RightChomp(); - if (sCTCP.CaseCmp("DCC ", 4) == 0 && m_pUser->BounceDCCs()) { + if (sCTCP.Equals("DCC ", false, 4) && m_pUser->BounceDCCs()) { CString sType = sCTCP.Token(1); CString sFile = sCTCP.Token(2); unsigned long uLongIP = strtoul(sCTCP.Token(3).c_str(), NULL, 10); @@ -394,18 +394,18 @@ void CClient::ReadLine(const CString& sData) { uLongIP = CUtils::GetLongIP(GetRemoteIP()); } - if (sType.CaseCmp("CHAT") == 0) { + if (sType.Equals("CHAT")) { if (!sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) { unsigned short uBNCPort = CDCCBounce::DCCRequest(sTarget, uLongIP, uPort, "", true, m_pUser, (m_pIRCSock) ? m_pIRCSock->GetLocalIP() : GetLocalIP(), ""); if (uBNCPort) { PutIRC("PRIVMSG " + sTarget + " :\001DCC CHAT chat " + CString(CUtils::GetLongIP(sIP)) + " " + CString(uBNCPort) + "\001"); } } - } else if (sType.CaseCmp("SEND") == 0) { + } else if (sType.Equals("SEND")) { // DCC SEND readme.txt 403120438 5550 1104 if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) { - if (sTarget.CaseCmp("status") == 0) { + if (sTarget.Equals("status")) { CString sPath = m_pUser->GetDLPath(); if (!CFile::Exists(sPath)) { PutStatus("Could not create [" + sPath + "] directory."); @@ -427,14 +427,14 @@ void CClient::ReadLine(const CString& sData) { PutIRC("PRIVMSG " + sTarget + " :\001DCC SEND " + sFile + " " + CString(CUtils::GetLongIP(sIP)) + " " + CString(uBNCPort) + " " + CString(uFileSize) + "\001"); } } - } else if (sType.CaseCmp("RESUME") == 0) { + } else if (sType.Equals("RESUME")) { // PRIVMSG user :DCC RESUME "znc.o" 58810 151552 unsigned short uResumePort = atoi(sCTCP.Token(3).c_str()); unsigned long uResumeSize = strtoul(sCTCP.Token(4).c_str(), NULL, 10); // Need to lookup the connection by port, filter the port, and forward to the user CString sStatusPrefix = m_pUser->GetStatusPrefix(); - if (sTarget.CaseCmp(sStatusPrefix, sStatusPrefix.length()) == 0) { + if (sTarget.Equals(sStatusPrefix, false, sStatusPrefix.length())) { if (m_pUser->ResumeFile(uResumePort, uResumeSize)) { PutClient(":" + sTarget + "!znc@znc.in PRIVMSG " + GetNick() + " :\001DCC ACCEPT " + sFile + " " + CString(uResumePort) + " " + CString(uResumeSize) + "\001"); } else { @@ -442,20 +442,20 @@ void CClient::ReadLine(const CString& sData) { } } else { CDCCBounce* pSock = (CDCCBounce*) CZNC::Get().GetManager().FindSockByLocalPort(uResumePort); - if ((pSock) && (pSock->GetSockName().CaseCmp("DCC::", 5) == 0)) { + if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) { PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetUserPort()) + " " + sCTCP.Token(4) + "\001"); } } - } else if (sType.CaseCmp("ACCEPT") == 0) { + } else if (sType.Equals("ACCEPT")) { CString sStatusPrefix = m_pUser->GetStatusPrefix(); - if (sTarget.CaseCmp(sStatusPrefix, sStatusPrefix.length()) != 0) { + if (!sTarget.Equals(sStatusPrefix, false, sStatusPrefix.length())) { // Need to lookup the connection by port, filter the port, and forward to the user CSockManager& Manager = CZNC::Get().GetManager(); for (unsigned int a = 0; a < Manager.size(); a++) { CDCCBounce* pSock = (CDCCBounce*) Manager[a]; - if ((pSock) && (pSock->GetSockName().CaseCmp("DCC::", 5) == 0)) { + if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) { if (pSock->GetUserPort() == atoi(sCTCP.Token(3).c_str())) { PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sCTCP.Token(4) + "\001"); } @@ -468,7 +468,7 @@ void CClient::ReadLine(const CString& sData) { } if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) { - if (sTarget.CaseCmp("status") == 0) { + if (sTarget.Equals("status")) { StatusCTCP(sCTCP); } else { #ifdef _MODULES @@ -480,7 +480,7 @@ void CClient::ReadLine(const CString& sData) { CChan* pChan = m_pUser->FindChan(sTarget); - if (sCTCP.Token(0).CaseCmp("ACTION") == 0) { + if (sCTCP.Token(0).Equals("ACTION")) { CString sMessage = sCTCP.Token(1, true); MODULECALL(OnUserAction(sTarget, sMessage), m_pUser, this, return); sCTCP = "ACTION " + sMessage; @@ -510,7 +510,7 @@ void CClient::ReadLine(const CString& sData) { } if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) { - if (sTarget.CaseCmp("status") == 0) { + if (sTarget.Equals("status")) { MODULECALL(OnStatusCommand(sMsg), m_pUser, this, return); UserCommand(sMsg); } else { @@ -525,7 +525,7 @@ void CClient::ReadLine(const CString& sData) { if (!m_pIRCSock) { // Some lagmeters do a PRIVMSG to their own nick, ignore those. - if (sTarget.CaseCmp(m_sNick) != 0) + if (!sTarget.Equals(m_sNick)) PutStatus("Your message to [" + sTarget + "] got lost, " "you are not connected to IRC!"); return; @@ -566,9 +566,9 @@ void CClient::SetNick(const CString& s) { void CClient::StatusCTCP(const CString& sLine) { CString sCommand = sLine.Token(0); - if (sCommand.CaseCmp("PING") == 0) { + if (sCommand.Equals("PING")) { PutStatusNotice("\001PING " + sLine.Token(1, true) + "\001"); - } else if (sCommand.CaseCmp("VERSION") == 0) { + } else if (sCommand.Equals("VERSION")) { PutStatusNotice("\001VERSION " + CZNC::GetTag() + "\001"); } } diff --git a/ClientCommand.cpp b/ClientCommand.cpp index c1ab6198..f3f753ae 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -26,9 +26,9 @@ void CClient::UserCommand(const CString& sLine) { CString sCommand = sLine.Token(0); - if (sCommand.CaseCmp("HELP") == 0) { + if (sCommand.Equals("HELP")) { HelpUser(); - } else if (sCommand.CaseCmp("LISTNICKS") == 0) { + } else if (sCommand.Equals("LISTNICKS")) { CString sChan = sLine.Token(1); if (sChan.empty()) { @@ -86,7 +86,7 @@ void CClient::UserCommand(const CString& sLine) { } PutStatus(Table); - } else if (sCommand.CaseCmp("DETACH") == 0) { + } else if (sCommand.Equals("DETACH")) { CString sChan = sLine.Token(1); if (sChan.empty()) { @@ -102,13 +102,13 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Detaching you from [" + sChan + "]"); pChan->DetachUser(); - } else if (sCommand.CaseCmp("VERSION") == 0) { + } else if (sCommand.Equals("VERSION")) { PutStatus(CZNC::GetTag()); - } else if (sCommand.CaseCmp("MOTD") == 0 || sCommand.CaseCmp("ShowMOTD") == 0) { + } else if (sCommand.Equals("MOTD") || sCommand.Equals("ShowMOTD")) { if (!SendMotd()) { PutStatus("There is no MOTD set."); } - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("Rehash") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("Rehash")) { CString sRet; if (CZNC::Get().RehashConfig(sRet)) { @@ -116,13 +116,13 @@ void CClient::UserCommand(const CString& sLine) { } else { PutStatus("Rehashing failed: " + sRet); } - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SaveConfig") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("SaveConfig")) { if (CZNC::Get().WriteConfig()) { PutStatus("Wrote config to [" + CZNC::Get().GetConfigFile() + "]"); } else { PutStatus("Error while trying to write config."); } - } else if (sCommand.CaseCmp("LISTCLIENTS") == 0) { + } else if (sCommand.Equals("LISTCLIENTS")) { CUser* pUser = m_pUser; CString sNick = sLine.Token(1); @@ -156,7 +156,7 @@ void CClient::UserCommand(const CString& sLine) { } PutStatus(Table); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("LISTUSERS") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("LISTUSERS")) { const map& msUsers = CZNC::Get().GetUserMap(); CTable Table; Table.AddColumn("Username"); @@ -179,7 +179,7 @@ void CClient::UserCommand(const CString& sLine) { } PutStatus(Table); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SetMOTD") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("SetMOTD")) { CString sMessage = sLine.Token(1, true); if (sMessage.empty()) { @@ -188,7 +188,7 @@ void CClient::UserCommand(const CString& sLine) { CZNC::Get().SetMotd(sMessage); PutStatus("MOTD set to [" + sMessage + "]"); } - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("AddMOTD") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("AddMOTD")) { CString sMessage = sLine.Token(1, true); if (sMessage.empty()) { @@ -197,12 +197,12 @@ void CClient::UserCommand(const CString& sLine) { CZNC::Get().AddMotd(sMessage); PutStatus("Added [" + sMessage + "] to MOTD"); } - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("ClearMOTD") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("ClearMOTD")) { CZNC::Get().ClearMotd(); PutStatus("Cleared MOTD"); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("BROADCAST") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("BROADCAST")) { CZNC::Get().Broadcast(sLine.Token(1, true)); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SHUTDOWN") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("SHUTDOWN")) { CString sMessage = sLine.Token(1, true); if (sMessage.empty()) { @@ -213,7 +213,7 @@ void CClient::UserCommand(const CString& sLine) { usleep(100000); // Sleep for 10ms to attempt to allow the previous Broadcast() to go through to all users throw CException(CException::EX_Shutdown); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("RESTART") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("RESTART")) { CString sMessage = sLine.Token(1, true); if (sMessage.empty()) { @@ -222,8 +222,7 @@ void CClient::UserCommand(const CString& sLine) { CZNC::Get().Broadcast(sMessage); throw CException(CException::EX_Restart); - } else if (sCommand.CaseCmp("JUMP") == 0 || - sCommand.CaseCmp("CONNECT") == 0) { + } else if (sCommand.Equals("JUMP") || sCommand.Equals("CONNECT")) { if (!m_pUser->HasServers()) { PutStatus("You don't have any servers added."); return; @@ -239,7 +238,7 @@ void CClient::UserCommand(const CString& sLine) { m_pUser->SetIRCConnectEnabled(true); m_pUser->CheckIRCConnect(); return; - } else if (sCommand.CaseCmp("DISCONNECT") == 0) { + } else if (sCommand.Equals("DISCONNECT")) { // m_pIRCSock is only set after the low level connection // to the IRC server was established. Before this we can // only find the IRC socket by its name. @@ -257,7 +256,7 @@ void CClient::UserCommand(const CString& sLine) { m_pUser->SetIRCConnectEnabled(false); PutStatus("Disconnected from IRC. Use 'connect' to reconnect."); return; - } else if (sCommand.CaseCmp("ENABLECHAN") == 0) { + } else if (sCommand.Equals("ENABLECHAN")) { CString sChan = sLine.Token(1, true); if (sChan.empty()) { @@ -272,7 +271,7 @@ void CClient::UserCommand(const CString& sLine) { pChan->Enable(); PutStatus("Channel [" + sChan + "] enabled."); } - } else if (sCommand.CaseCmp("LISTCHANS") == 0) { + } else if (sCommand.Equals("LISTCHANS")) { const vector& vChans = m_pUser->GetChans(); CIRCSock* pIRCSock = (!m_pUser) ? NULL : m_pUser->GetIRCSock(); const CString& sPerms = (pIRCSock) ? pIRCSock->GetPerms() : ""; @@ -314,7 +313,7 @@ void CClient::UserCommand(const CString& sLine) { } PutStatus(Table); - } else if (sCommand.CaseCmp("ADDSERVER") == 0) { + } else if (sCommand.Equals("ADDSERVER")) { CString sServer = sLine.Token(1); if (sServer.empty()) { @@ -332,7 +331,7 @@ void CClient::UserCommand(const CString& sLine) { } else { PutStatus("Unable to add that server"); } - } else if (sCommand.CaseCmp("REMSERVER") == 0 || sCommand.CaseCmp("DELSERVER") == 0) { + } else if (sCommand.Equals("REMSERVER") || sCommand.Equals("DELSERVER")) { CString sServer = sLine.Token(1); if (sServer.empty()) { @@ -352,7 +351,7 @@ void CClient::UserCommand(const CString& sLine) { } else { PutStatus("No such server"); } - } else if (sCommand.CaseCmp("LISTSERVERS") == 0) { + } else if (sCommand.Equals("LISTSERVERS")) { if (m_pUser->HasServers()) { const vector& vServers = m_pUser->GetServers(); CTable Table; @@ -374,7 +373,7 @@ void CClient::UserCommand(const CString& sLine) { } else { PutStatus("You don't have any servers added."); } - } else if (sCommand.CaseCmp("TOPICS") == 0) { + } else if (sCommand.Equals("TOPICS")) { const vector& vChans = m_pUser->GetChans(); CTable Table; Table.AddColumn("Name"); @@ -390,7 +389,7 @@ void CClient::UserCommand(const CString& sLine) { } PutStatus(Table); - } else if (sCommand.CaseCmp("SEND") == 0) { + } else if (sCommand.Equals("SEND")) { CString sToNick = sLine.Token(1); CString sFile = sLine.Token(2); CString sAllowedPath = m_pUser->GetDLPath(); @@ -409,7 +408,7 @@ void CClient::UserCommand(const CString& sLine) { } m_pUser->SendFile(sToNick, sFile); - } else if (sCommand.CaseCmp("GET") == 0) { + } else if (sCommand.Equals("GET")) { CString sFile = sLine.Token(1); CString sAllowedPath = m_pUser->GetDLPath(); CString sAbsolutePath; @@ -427,7 +426,7 @@ void CClient::UserCommand(const CString& sLine) { } m_pUser->SendFile(GetNick(), sFile); - } else if (sCommand.CaseCmp("LISTDCCS") == 0) { + } else if (sCommand.Equals("LISTDCCS")) { CSockManager& Manager = CZNC::Get().GetManager(); CTable Table; @@ -439,18 +438,18 @@ void CClient::UserCommand(const CString& sLine) { Table.AddColumn("File"); for (unsigned int a = 0; a < Manager.size(); a++) { - const CString& sSockName = Manager[a]->GetSockName(); + CString sSockName = Manager[a]->GetSockName(); - if (strncasecmp(sSockName.c_str(), "DCC::", 5) == 0) { - if (strncasecmp(sSockName.c_str() +5, "XFER::REMOTE::", 14) == 0) { + if (sSockName.TrimPrefix("DCC::")) { + if (sSockName.Equals("XFER::REMOTE::", false, 14)) { continue; } - if (strncasecmp(sSockName.c_str() +5, "CHAT::REMOTE::", 14) == 0) { + if (sSockName.Equals("CHAT::REMOTE::", false, 14)) { continue; } - if (strncasecmp(sSockName.c_str() +5, "SEND", 4) == 0) { + if (sSockName.Equals("SEND", false, 4)) { CDCCSock* pSock = (CDCCSock*) Manager[a]; Table.AddRow(); @@ -460,7 +459,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Nick", pSock->GetRemoteNick()); Table.SetCell("IP", pSock->GetRemoteIP()); Table.SetCell("File", pSock->GetFileName()); - } else if (strncasecmp(sSockName.c_str() +5, "GET", 3) == 0) { + } else if (sSockName.Equals("GET", false, 3)) { CDCCSock* pSock = (CDCCSock*) Manager[a]; Table.AddRow(); @@ -470,7 +469,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Nick", pSock->GetRemoteNick()); Table.SetCell("IP", pSock->GetRemoteIP()); Table.SetCell("File", pSock->GetFileName()); - } else if (strncasecmp(sSockName.c_str() +5, "LISTEN", 6) == 0) { + } else if (sSockName.Equals("LISTEN", false, 6)) { CDCCSock* pSock = (CDCCSock*) Manager[a]; Table.AddRow(); @@ -479,7 +478,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Nick", pSock->GetRemoteNick()); Table.SetCell("IP", pSock->GetRemoteIP()); Table.SetCell("File", pSock->GetFileName()); - } else if (strncasecmp(sSockName.c_str() +5, "XFER::LOCAL", 11) == 0) { + } else if (sSockName.Equals("XFER::LOCAL", false, 11)) { CDCCBounce* pSock = (CDCCBounce*) Manager[a]; CString sState = "Waiting"; @@ -496,7 +495,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Nick", pSock->GetRemoteNick()); Table.SetCell("IP", pSock->GetRemoteIP()); Table.SetCell("File", pSock->GetFileName()); - } else if (strncasecmp(sSockName.c_str() +5, "CHAT::LOCAL", 11) == 0) { + } else if (sSockName.Equals("CHAT::LOCAL", false, 11)) { CDCCBounce* pSock = (CDCCBounce*) Manager[a]; CString sState = "Waiting"; @@ -519,7 +518,7 @@ void CClient::UserCommand(const CString& sLine) { if (PutStatus(Table) == 0) { PutStatus("You have no active DCCs."); } - } else if ((sCommand.CaseCmp("LISTMODS") == 0) || (sCommand.CaseCmp("LISTMODULES") == 0)) { + } else if (sCommand.Equals("LISTMODS") || sCommand.Equals("LISTMODULES")) { #ifdef _MODULES if (m_pUser->IsAdmin()) { CModules& GModules = CZNC::Get().GetModules(); @@ -564,7 +563,7 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Modules are not enabled."); #endif return; - } else if ((sCommand.CaseCmp("LISTAVAILMODS") == 0) || (sCommand.CaseCmp("LISTAVAILABLEMODULES") == 0)) { + } else if (sCommand.Equals("LISTAVAILMODS") || sCommand.Equals("LISTAVAILABLEMODULES")) { #ifdef _MODULES if (m_pUser->DenyLoadMod()) { PutStatus("Access Denied."); @@ -620,12 +619,12 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Modules are not enabled."); #endif return; - } else if ((sCommand.CaseCmp("LOADMOD") == 0) || (sCommand.CaseCmp("LOADMODULE") == 0)) { + } else if (sCommand.Equals("LOADMOD") || sCommand.Equals("LOADMODULE")) { CString sMod; CString sArgs; bool bGlobal = false; - if (sLine.Token(1).CaseCmp("-global") == 0) { + if (sLine.Token(1).Equals("-global")) { sMod = sLine.Token(2); if (!m_pUser->IsAdmin()) { @@ -668,11 +667,11 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Unable to load [" + sMod + "] Modules are not enabled."); #endif return; - } else if ((sCommand.CaseCmp("UNLOADMOD") == 0) || (sCommand.CaseCmp("UNLOADMODULE") == 0)) { + } else if (sCommand.Equals("UNLOADMOD") || sCommand.Equals("UNLOADMODULE")) { CString sMod; bool bGlobal = false; - if (sLine.Token(1).CaseCmp("-global") == 0) { + if (sLine.Token(1).Equals("-global")) { sMod = sLine.Token(2); if (!m_pUser->IsAdmin()) { @@ -707,12 +706,12 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Unable to unload [" + sMod + "] Modules are not enabled."); #endif return; - } else if ((sCommand.CaseCmp("RELOADMOD") == 0) || (sCommand.CaseCmp("RELOADMODULE") == 0)) { + } else if (sCommand.Equals("RELOADMOD") || sCommand.Equals("RELOADMODULE")) { CString sMod; CString sArgs; bool bGlobal = false; - if (sLine.Token(1).CaseCmp("-global") == 0) { + if (sLine.Token(1).Equals("-global")) { sMod = sLine.Token(2); if (!m_pUser->IsAdmin()) { @@ -750,7 +749,7 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Unable to unload [" + sMod + "] Modules are not enabled."); #endif return; - } else if (sCommand.CaseCmp("SETVHOST") == 0 && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { + } else if (sCommand.Equals("SETVHOST") && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { CString sVHost = sLine.Token(1); if (sVHost.empty()) { @@ -760,10 +759,10 @@ void CClient::UserCommand(const CString& sLine) { m_pUser->SetVHost(sVHost); PutStatus("Set VHost to [" + m_pUser->GetVHost() + "]"); - } else if (sCommand.CaseCmp("CLEARVHOST") == 0 && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { + } else if (sCommand.Equals("CLEARVHOST") && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { m_pUser->SetVHost(""); PutStatus("VHost Cleared"); - } else if (sCommand.CaseCmp("PLAYBUFFER") == 0) { + } else if (sCommand.Equals("PLAYBUFFER")) { CString sChan = sLine.Token(1); if (sChan.empty()) { @@ -789,7 +788,7 @@ void CClient::UserCommand(const CString& sLine) { } pChan->SendBuffer(this); - } else if (sCommand.CaseCmp("CLEARBUFFER") == 0) { + } else if (sCommand.Equals("CLEARBUFFER")) { CString sChan = sLine.Token(1); if (sChan.empty()) { @@ -811,7 +810,7 @@ void CClient::UserCommand(const CString& sLine) { pChan->ClearBuffer(); PutStatus("The buffer for [" + sChan + "] has been cleared"); - } else if (sCommand.CaseCmp("CLEARALLCHANNELBUFFERS") == 0) { + } else if (sCommand.Equals("CLEARALLCHANNELBUFFERS")) { vector::const_iterator it; const vector& vChans = m_pUser->GetChans(); @@ -819,7 +818,7 @@ void CClient::UserCommand(const CString& sLine) { (*it)->ClearBuffer(); } PutStatus("All channel buffers have been cleared"); - } else if (sCommand.CaseCmp("SETBUFFER") == 0) { + } else if (sCommand.Equals("SETBUFFER")) { CString sChan = sLine.Token(1); if (sChan.empty()) { @@ -849,7 +848,7 @@ void CClient::UserCommand(const CString& sLine) { pChan->SetBufferCount(uLineCount); PutStatus("BufferCount for [" + sChan + "] set to [" + CString(pChan->GetBufferCount()) + "]"); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("TRAFFIC") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("TRAFFIC")) { CZNC::Get().UpdateTrafficStats(); const map& msUsers = CZNC::Get().GetUserMap(); CTable Table; @@ -887,7 +886,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Total", CString::ToByteStr(users_total_in + CZNC::Get().BytesRead() + users_total_out + CZNC::Get().BytesWritten())); PutStatus(Table); - } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("UPTIME") == 0) { + } else if (m_pUser->IsAdmin() && sCommand.Equals("UPTIME")) { PutStatus("Running for " + CZNC::Get().GetUptime()); } else { PutStatus("Unknown command [" + sCommand + "] try 'Help'"); diff --git a/HTTPSock.cpp b/HTTPSock.cpp index 337f5da3..4edddb14 100644 --- a/HTTPSock.cpp +++ b/HTTPSock.cpp @@ -65,21 +65,21 @@ void CHTTPSock::ReadLine(const CString& sData) { CString sName = sLine.Token(0); - if (sName.CaseCmp("GET") == 0) { + if (sName.Equals("GET")) { m_bPost = false; m_sURI = sLine.Token(1); ParseURI(); - } else if (sName.CaseCmp("POST") == 0) { + } else if (sName.Equals("POST")) { m_bPost = true; m_sURI = sLine.Token(1); ParseURI(); - } else if (sName.CaseCmp("Authorization:") == 0) { + } else if (sName.Equals("Authorization:")) { CString sUnhashed; sLine.Token(2).Base64Decode(sUnhashed); m_sUser = sUnhashed.Token(0, false, ":"); m_sPass = sUnhashed.Token(1, true, ":"); m_bLoggedIn = OnLogin(m_sUser, m_sPass); - } else if (sName.CaseCmp("Content-Length:") == 0) { + } else if (sName.Equals("Content-Length:")) { m_uPostLen = sLine.Token(1).ToULong(); } else if (sLine.empty()) { m_bGotHeader = true; @@ -136,21 +136,21 @@ bool CHTTPSock::PrintFile(const CString& sFileName, CString sContentType) { } if (sContentType.empty()) { - if (sFileName.Right(5).CaseCmp(".html") == 0 || sFileName.Right(4).CaseCmp(".htm") == 0) { + if (sFileName.Right(5).Equals(".html") || sFileName.Right(4).Equals(".htm")) { sContentType = "text/html"; - } else if (sFileName.Right(4).CaseCmp(".css") == 0) { + } else if (sFileName.Right(4).Equals(".css")) { sContentType = "text/css"; - } else if (sFileName.Right(3).CaseCmp(".js") == 0) { + } else if (sFileName.Right(3).Equals(".js")) { sContentType = "application/x-javascript"; - } else if (sFileName.Right(4).CaseCmp(".jpg") == 0) { + } else if (sFileName.Right(4).Equals(".jpg")) { sContentType = "image/jpeg"; - } else if (sFileName.Right(4).CaseCmp(".gif") == 0) { + } else if (sFileName.Right(4).Equals(".gif")) { sContentType = "image/gif"; - } else if (sFileName.Right(4).CaseCmp(".ico") == 0) { + } else if (sFileName.Right(4).Equals(".ico")) { sContentType = "image/x-icon"; - } else if (sFileName.Right(4).CaseCmp(".png") == 0) { + } else if (sFileName.Right(4).Equals(".png")) { sContentType = "image/png"; - } else if (sFileName.Right(4).CaseCmp(".bmp") == 0) { + } else if (sFileName.Right(4).Equals(".bmp")) { sContentType = "image/bmp"; } else { sContentType = "text/plain"; diff --git a/IRCSock.cpp b/IRCSock.cpp index 1983aeb6..c6823ac8 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -79,9 +79,9 @@ void CIRCSock::ReadLine(const CString& sData) { MODULECALL(OnRaw(sLine), m_pUser, NULL, return); - if (strncasecmp(sLine.c_str(), "PING ", 5) == 0) { + if (sLine.Equals("PING ", false, 5)) { PutIRC("PONG " + sLine.substr(5)); - } else if (strncasecmp(sLine.c_str(), "ERROR ", 6) == 0) { + } else if (sLine.Equals("ERROR ", false, 6)) { //ERROR :Closing Link: nick[24.24.24.24] (Excess Flood) CString sError(sLine.substr(7)); @@ -114,7 +114,7 @@ void CIRCSock::ReadLine(const CString& sData) { CClient* pClient = vClients[a]; CString sClientNick = pClient->GetNick(false); - if (sClientNick.CaseCmp(sNick) != 0) { + if (!sClientNick.Equals(sNick)) { // If they connected with a nick that doesn't match the one we got on irc, then we need to update them pClient->PutClient(":" + sClientNick + "!" + m_Nick.GetIdent() + "@" + m_Nick.GetHost() + " NICK :" + sNick); } @@ -240,7 +240,7 @@ void CIRCSock::ReadLine(const CString& sData) { sServer.LeftChomp(); - if (sNick.CaseCmp(GetNick()) == 0) { + if (sNick.Equals(GetNick())) { m_Nick.SetIdent(sIdent); m_Nick.SetHost(sHost); } @@ -326,7 +326,7 @@ void CIRCSock::ReadLine(const CString& sData) { sCmd = sLine.Token(1); CString sRest = sLine.Token(2, true); - if (sCmd.CaseCmp("NICK") == 0) { + if (sCmd.Equals("NICK")) { CString sNewNick = sRest; bool bIsVisible = false; @@ -350,7 +350,7 @@ void CIRCSock::ReadLine(const CString& sData) { } // Todo: use nick compare function here - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { // We are changing our own nick, the clients always must see this! bIsVisible = true; SetNick(sNewNick); @@ -361,7 +361,7 @@ void CIRCSock::ReadLine(const CString& sData) { if (!bIsVisible) { return; } - } else if (sCmd.CaseCmp("QUIT") == 0) { + } else if (sCmd.Equals("QUIT")) { CString sMessage = sRest; bool bIsVisible = false; @@ -371,7 +371,7 @@ void CIRCSock::ReadLine(const CString& sData) { // :nick!ident@host.com QUIT :message - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { m_pUser->PutStatus("You quit [" + sMessage + "]"); } @@ -395,7 +395,7 @@ void CIRCSock::ReadLine(const CString& sData) { if (!bIsVisible) { return; } - } else if (sCmd.CaseCmp("JOIN") == 0) { + } else if (sCmd.Equals("JOIN")) { CString sChan = sRest.Token(0); if (sChan.Left(1) == ":") { sChan.LeftChomp(); @@ -404,7 +404,7 @@ void CIRCSock::ReadLine(const CString& sData) { CChan* pChan; // Todo: use nick compare function - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { m_pUser->AddChan(sChan, false); pChan = m_pUser->FindChan(sChan); if (pChan) { @@ -426,7 +426,7 @@ void CIRCSock::ReadLine(const CString& sData) { return; } } - } else if (sCmd.CaseCmp("PART") == 0) { + } else if (sCmd.Equals("PART")) { CString sChan = sRest.Token(0); if (sChan.Left(1) == ":") { sChan.LeftChomp(); @@ -443,7 +443,7 @@ void CIRCSock::ReadLine(const CString& sData) { } // Todo: use nick compare function - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { m_pUser->DelChan(sChan); } @@ -456,7 +456,7 @@ void CIRCSock::ReadLine(const CString& sData) { if (bDetached) { return; } - } else if (sCmd.CaseCmp("MODE") == 0) { + } else if (sCmd.Equals("MODE")) { CString sTarget = sRest.Token(0); CString sModes = sRest.Token(1, true); if (sModes.Left(1) == ":") @@ -492,7 +492,7 @@ void CIRCSock::ReadLine(const CString& sData) { } } } - } else if (sCmd.CaseCmp("KICK") == 0) { + } else if (sCmd.Equals("KICK")) { // :opnick!ident@host.com KICK #chan nick :msg CString sChan = sRest.Token(0); CString sKickedNick = sRest.Token(1); @@ -506,7 +506,7 @@ void CIRCSock::ReadLine(const CString& sData) { MODULECALL(OnKick(Nick.GetNickMask(), sKickedNick, *pChan, sMsg), m_pUser, NULL, ); } - if (GetNick().CaseCmp(sKickedNick) == 0 && pChan) { + if (GetNick().Equals(sKickedNick) && pChan) { pChan->SetIsOn(false); // Don't try to rejoin! @@ -516,7 +516,7 @@ void CIRCSock::ReadLine(const CString& sData) { if ((pChan) && (pChan->IsDetached())) { return; } - } else if (sCmd.CaseCmp("NOTICE") == 0) { + } else if (sCmd.Equals("NOTICE")) { // :nick!ident@host.com NOTICE #chan :Message CString sTarget = sRest.Token(0); CString sMsg = sRest.Token(1, true); @@ -526,7 +526,7 @@ void CIRCSock::ReadLine(const CString& sData) { sMsg.LeftChomp(); sMsg.RightChomp(); - if (sTarget.CaseCmp(GetNick()) == 0) { + if (sTarget.Equals(GetNick())) { if (OnCTCPReply(Nick, sMsg)) { return; } @@ -535,7 +535,7 @@ void CIRCSock::ReadLine(const CString& sData) { m_pUser->PutUser(":" + Nick.GetNickMask() + " NOTICE " + sTarget + " :\001" + sMsg + "\001"); return; } else { - if (sTarget.CaseCmp(GetNick()) == 0) { + if (sTarget.Equals(GetNick())) { if (OnPrivNotice(Nick, sMsg)) { return; } @@ -546,14 +546,14 @@ void CIRCSock::ReadLine(const CString& sData) { } } - if (Nick.GetNick().CaseCmp(m_pUser->GetIRCServer()) == 0) { + if (Nick.GetNick().Equals(m_pUser->GetIRCServer())) { m_pUser->PutUser(":" + Nick.GetNick() + " NOTICE " + sTarget + " :" + sMsg); } else { m_pUser->PutUser(":" + Nick.GetNickMask() + " NOTICE " + sTarget + " :" + sMsg); } return; - } else if (sCmd.CaseCmp("TOPIC") == 0) { + } else if (sCmd.Equals("TOPIC")) { // :nick!ident@host.com TOPIC #chan :This is a topic CChan* pChan = m_pUser->FindChan(sLine.Token(2)); @@ -573,7 +573,7 @@ void CIRCSock::ReadLine(const CString& sData) { sLine = ":" + Nick.GetNickMask() + " TOPIC " + pChan->GetName() + " :" + sTopic; } - } else if (sCmd.CaseCmp("PRIVMSG") == 0) { + } else if (sCmd.Equals("PRIVMSG")) { // :nick!ident@host.com PRIVMSG #chan :Message CString sTarget = sRest.Token(0); CString sMsg = sRest.Token(1, true); @@ -586,7 +586,7 @@ void CIRCSock::ReadLine(const CString& sData) { sMsg.LeftChomp(); sMsg.RightChomp(); - if (sTarget.CaseCmp(GetNick()) == 0) { + if (sTarget.Equals(GetNick())) { if (OnPrivCTCP(Nick, sMsg)) { return; } @@ -599,7 +599,7 @@ void CIRCSock::ReadLine(const CString& sData) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + sTarget + " :\001" + sMsg + "\001"); return; } else { - if (sTarget.CaseCmp(GetNick()) == 0) { + if (sTarget.Equals(GetNick())) { if (OnPrivMsg(Nick, sMsg)) { return; } @@ -612,7 +612,7 @@ void CIRCSock::ReadLine(const CString& sData) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + sTarget + " :" + sMsg); return; } - } else if (sCmd.CaseCmp("WALLOPS") == 0) { + } else if (sCmd.Equals("WALLOPS")) { // :blub!dummy@rox-8DBEFE92 WALLOPS :this is a test CString sMsg = sRest.Token(0, true); @@ -635,14 +635,13 @@ bool CIRCSock::OnCTCPReply(CNick& Nick, CString& sMessage) { } bool CIRCSock::OnPrivCTCP(CNick& Nick, CString& sMessage) { - if (sMessage.Left(7).CaseCmp("ACTION ") == 0) { - sMessage = sMessage.substr(7); + if (sMessage.TrimPrefix("ACTION ")) { MODULECALL(OnPrivAction(Nick, sMessage), m_pUser, NULL, return true); sMessage = "ACTION " + sMessage; } MODULECALL(OnPrivCTCP(Nick, sMessage), m_pUser, NULL, return true); - if (strncasecmp(sMessage.c_str(), "DCC ", 4) == 0 && m_pUser && m_pUser->BounceDCCs() && m_pUser->IsUserAttached()) { + if (sMessage.Equals("DCC ", false, 4) && m_pUser && m_pUser->BounceDCCs() && m_pUser->IsUserAttached()) { // DCC CHAT chat 2453612361 44592 CString sType = sMessage.Token(1); CString sFile = sMessage.Token(2); @@ -650,33 +649,33 @@ bool CIRCSock::OnPrivCTCP(CNick& Nick, CString& sMessage) { unsigned short uPort = strtoul(sMessage.Token(4).c_str(), NULL, 10); unsigned long uFileSize = strtoul(sMessage.Token(5).c_str(), NULL, 10); - if (sType.CaseCmp("CHAT") == 0) { + if (sType.Equals("CHAT")) { CNick FromNick(Nick.GetNickMask()); unsigned short uBNCPort = CDCCBounce::DCCRequest(FromNick.GetNick(), uLongIP, uPort, "", true, m_pUser, GetLocalIP(), CUtils::GetIP(uLongIP)); if (uBNCPort) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + GetNick() + " :\001DCC CHAT chat " + CString(CUtils::GetLongIP(GetLocalIP())) + " " + CString(uBNCPort) + "\001"); } - } else if (sType.CaseCmp("SEND") == 0) { + } else if (sType.Equals("SEND")) { // DCC SEND readme.txt 403120438 5550 1104 unsigned short uBNCPort = CDCCBounce::DCCRequest(Nick.GetNick(), uLongIP, uPort, sFile, false, m_pUser, GetLocalIP(), CUtils::GetIP(uLongIP)); if (uBNCPort) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + GetNick() + " :\001DCC SEND " + sFile + " " + CString(CUtils::GetLongIP(GetLocalIP())) + " " + CString(uBNCPort) + " " + CString(uFileSize) + "\001"); } - } else if (sType.CaseCmp("RESUME") == 0) { + } else if (sType.Equals("RESUME")) { // Need to lookup the connection by port, filter the port, and forward to the user CDCCBounce* pSock = (CDCCBounce*) CZNC::Get().GetManager().FindSockByLocalPort(sMessage.Token(3).ToUShort()); - if ((pSock) && (strncasecmp(pSock->GetSockName().c_str(), "DCC::", 5) == 0)) { + if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + GetNick() + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetUserPort()) + " " + sMessage.Token(4) + "\001"); } - } else if (sType.CaseCmp("ACCEPT") == 0) { + } else if (sType.Equals("ACCEPT")) { // Need to lookup the connection by port, filter the port, and forward to the user CSockManager& Manager = CZNC::Get().GetManager(); for (unsigned int a = 0; a < Manager.size(); a++) { CDCCBounce* pSock = (CDCCBounce*) Manager[a]; - if ((pSock) && (strncasecmp(pSock->GetSockName().c_str(), "DCC::", 5) == 0)) { + if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) { if (pSock->GetUserPort() == atoi(sMessage.Token(3).c_str())) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + GetNick() + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sMessage.Token(4) + "\001"); } @@ -750,8 +749,7 @@ bool CIRCSock::OnChanCTCP(CNick& Nick, const CString& sChan, CString& sMessage) CChan* pChan = m_pUser->FindChan(sChan); if (pChan) { // Record a /me - if (sMessage.Left(7).CaseCmp("ACTION ") == 0) { - sMessage = sMessage.substr(7); + if (sMessage.TrimPrefix("ACTION ")) { if (pChan->KeepBuffer() || !m_pUser->IsUserAttached()) { pChan->AddBuffer(":" + Nick.GetNickMask() + " PRIVMSG " + sChan + " :\001ACTION " + m_pUser->AddTimestamp(sMessage) + "\001"); } @@ -895,7 +893,7 @@ void CIRCSock::ParseISupport(const CString& sLine) { CString sName = sArg.Token(0, false, "="); CString sValue = sArg.Token(1, true, "="); - if (sName.CaseCmp("PREFIX") == 0) { + if (sName.Equals("PREFIX")) { CString sPrefixes = sValue.Token(1, false, ")"); CString sPermModes = sValue.Token(0, false, ")"); sPermModes.TrimLeft("("); @@ -904,15 +902,15 @@ void CIRCSock::ParseISupport(const CString& sLine) { m_sPerms = sPrefixes; m_sPermModes = sPermModes; } - } else if (sName.CaseCmp("CHANTYPES") == 0) { + } else if (sName.Equals("CHANTYPES")) { m_pUser->SetChanPrefixes(sValue); - } else if (sName.CaseCmp("NICKLEN") == 0) { + } else if (sName.Equals("NICKLEN")) { unsigned int uMax = sValue.ToUInt(); if (uMax) { m_uMaxNickLen = uMax; } - } else if (sName.CaseCmp("CHANMODES") == 0) { + } else if (sName.Equals("CHANMODES")) { if (!sValue.empty()) { m_mueChanModes.clear(); @@ -924,10 +922,10 @@ void CIRCSock::ParseISupport(const CString& sLine) { } } } - } else if (sName.CaseCmp("NAMESX") == 0) { + } else if (sName.Equals("NAMESX")) { m_bNamesx = true; PutIRC("PROTOCTL NAMESX"); - } else if (sName.CaseCmp("UHNAMES") == 0) { + } else if (sName.Equals("UHNAMES")) { m_bUHNames = true; PutIRC("PROTOCTL UHNAMES"); } @@ -986,19 +984,19 @@ void CIRCSock::SendAltNick(const CString& sBadNick) { const CString& sConfNick = m_pUser->GetNick().Left(uMax); const CString& sAltNick = m_pUser->GetAltNick().Left(uMax); - if (sBadNick.CaseCmp(sConfNick) == 0) { - if ((!sAltNick.empty()) && (sConfNick.CaseCmp(sAltNick) != 0)) { + if (sBadNick.Equals(sConfNick)) { + if ((!sAltNick.empty()) && (!sConfNick.Equals(sAltNick))) { PutIRC("NICK " + sAltNick); } else { PutIRC("NICK " + sConfNick.Left(uMax -1) + "-"); } - } else if (sBadNick.CaseCmp(sAltNick) == 0) { + } else if (sBadNick.Equals(sAltNick)) { PutIRC("NICK " + sConfNick.Left(uMax -1) + "-"); - } else if (sBadNick.CaseCmp(CString(sConfNick.Left(uMax -1) + "-")) == 0) { + } else if (sBadNick.Equals(CString(sConfNick.Left(uMax -1) + "-"))) { PutIRC("NICK " + sConfNick.Left(uMax -1) + "|"); - } else if (sBadNick.CaseCmp(CString(sConfNick.Left(uMax -1) + "|")) == 0) { + } else if (sBadNick.Equals(CString(sConfNick.Left(uMax -1) + "|"))) { PutIRC("NICK " + sConfNick.Left(uMax -1) + "^"); - } else if (sBadNick.CaseCmp(CString(sConfNick.Left(uMax -1) + "^")) == 0) { + } else if (sBadNick.Equals(CString(sConfNick.Left(uMax -1) + "^"))) { PutIRC("NICK " + sConfNick.Left(uMax -1) + "a"); } else { char cLetter = 0; diff --git a/Modules.cpp b/Modules.cpp index bab4c8d8..8d85c2c0 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -290,7 +290,7 @@ bool CModule::RemTimer(const CString& sLabel) { for (unsigned int a = 0; a < m_vTimers.size(); a++) { CTimer* pTimer = m_vTimers[a]; - if (pTimer->GetName().CaseCmp(sLabel) == 0) { + if (pTimer->GetName().Equals(sLabel)) { m_vTimers.erase(m_vTimers.begin() +a); m_pManager->DelCronByAddr(pTimer); return true; @@ -314,7 +314,7 @@ bool CModule::UnlinkTimer(CTimer* pTimer) { CTimer* CModule::FindTimer(const CString& sLabel) { for (unsigned int a = 0; a < m_vTimers.size(); a++) { CTimer* pTimer = m_vTimers[a]; - if (pTimer->GetName().CaseCmp(sLabel) == 0) { + if (pTimer->GetName().Equals(sLabel)) { return pTimer; } } @@ -373,7 +373,7 @@ bool CModule::RemSocket(const CString& sSockName) { for (unsigned int a = 0; a < m_vSockets.size(); a++) { CSocket* pSocket = m_vSockets[a]; - if (pSocket->GetSockName().CaseCmp(sSockName) == 0) { + if (pSocket->GetSockName().Equals(sSockName)) { m_vSockets.erase(m_vSockets.begin() +a); m_pManager->DelSockByAddr(pSocket); return true; @@ -397,7 +397,7 @@ bool CModule::UnlinkSocket(CSocket* pSocket) { CSocket* CModule::FindSocket(const CString& sSockName) { for (unsigned int a = 0; a < m_vSockets.size(); a++) { CSocket* pSocket = m_vSockets[a]; - if (pSocket->GetSockName().CaseCmp(sSockName) == 0) { + if (pSocket->GetSockName().Equals(sSockName)) { return pSocket; } } @@ -639,7 +639,7 @@ void CGlobalModules::OnFailedLogin(const CString& sUsername, const CString& sRem CModule* CModules::FindModule(const CString& sModule) const { for (unsigned int a = 0; a < size(); a++) { - if (sModule.CaseCmp((*this)[a]->GetModName()) == 0) { + if (sModule.Equals((*this)[a]->GetModName())) { return (*this)[a]; } } diff --git a/Nick.cpp b/Nick.cpp index 3e4599e4..0ea96a27 100644 --- a/Nick.cpp +++ b/Nick.cpp @@ -65,7 +65,7 @@ unsigned int CNick::GetCommonChans(vector& vRetChans, CUser* pUser) cons const map& msNicks = pChan->GetNicks(); for (map::const_iterator it = msNicks.begin(); it != msNicks.end(); it++) { - if (it->first.CaseCmp(m_sNick) == 0) { + if (it->first.Equals(m_sNick)) { vRetChans.push_back(pChan); continue; } diff --git a/Template.cpp b/Template.cpp index 4be69edc..c1050199 100644 --- a/Template.cpp +++ b/Template.cpp @@ -38,21 +38,21 @@ CString CTemplateLoopContext::GetValue(const CString& sName) { return ""; } - if (sName.CaseCmp("__ID__") == 0) { + if (sName.Equals("__ID__")) { return CString(GetRowIndex() +1); - } else if (sName.CaseCmp("__COUNT__") == 0) { + } else if (sName.Equals("__COUNT__")) { return CString(GetRowCount()); - } else if (sName.CaseCmp("__ODD__") == 0) { + } else if (sName.Equals("__ODD__")) { return ((GetRowIndex() %2) ? "" : "1"); - } else if (sName.CaseCmp("__EVEN__") == 0) { + } else if (sName.Equals("__EVEN__")) { return ((GetRowIndex() %2) ? "1" : ""); - } else if (sName.CaseCmp("__FIRST__") == 0) { + } else if (sName.Equals("__FIRST__")) { return ((GetRowIndex() == 0) ? "1" : ""); - } else if (sName.CaseCmp("__LAST__") == 0) { + } else if (sName.Equals("__LAST__")) { return ((GetRowIndex() == m_pvRows->size() -1) ? "1" : ""); - } else if (sName.CaseCmp("__OUTER__") == 0) { + } else if (sName.Equals("__OUTER__")) { return ((GetRowIndex() == 0 || GetRowIndex() == m_pvRows->size() -1) ? "1" : ""); - } else if (sName.CaseCmp("__INNER__") == 0) { + } else if (sName.Equals("__INNER__")) { return ((GetRowIndex() == 0 || GetRowIndex() == m_pvRows->size() -1) ? "" : "1"); } @@ -185,13 +185,13 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { CString sArgs = sMid.Token(1, true); if (!uSkip) { - if (sAction.CaseCmp("INC") == 0) { + if (sAction.Equals("INC")) { if (!Print(File.GetDir() + sArgs, oOut)) { return false; } - } else if (sAction.CaseCmp("SETOPTION") == 0) { + } else if (sAction.Equals("SETOPTION")) { m_spOptions->Parse(sArgs); - } else if (sAction.CaseCmp("ADDROW") == 0) { + } else if (sAction.Equals("ADDROW")) { CString sLoopName = sArgs.Token(0); MCString msRow; @@ -202,12 +202,12 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { NewRow[it->first] = it->second; } } - } else if (sAction.CaseCmp("SET") == 0) { + } else if (sAction.Equals("SET")) { CString sName = sArgs.Token(0); CString sValue = sArgs.Token(1, true); (*this)[sName] = sValue; - } else if (sAction.CaseCmp("JOIN") == 0) { + } else if (sAction.Equals("JOIN")) { VCString vsArgs; sArgs.Split(" ", vsArgs, false, "\"", "\""); @@ -219,7 +219,7 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { for (unsigned int a = 1; a < vsArgs.size(); a++) { const CString& sArg = vsArgs[a]; - if (sArg.Left(4).CaseCmp("ESC=") == 0) { + if (sArg.Equals("ESC=", false, 4)) { eEscape = CString::ToEscape(sArg.LeftChomp_n(4)); } else { CString sValue = GetValue(sArg); @@ -235,9 +235,9 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { } } } - } else if (sAction.CaseCmp("VAR") == 0) { + } else if (sAction.Equals("VAR")) { sOutput += GetValue(sArgs); - } else if (sAction.CaseCmp("LOOP") == 0) { + } else if (sAction.Equals("LOOP")) { CTemplateLoopContext* pContext = GetCurLoopContext(); if (!pContext || pContext->GetFilePosition() != uCurPos) { @@ -253,7 +253,7 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { uSkip++; } } - } else if (sAction.CaseCmp("IF") == 0) { + } else if (sAction.Equals("IF")) { if (ValidIf(sArgs)) { uNestedIfs++; bValidLastIf = true; @@ -262,19 +262,19 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { bValidLastIf = false; } } - } else if (sAction.CaseCmp("IF") == 0) { + } else if (sAction.Equals("IF")) { uSkip++; - } else if (sAction.CaseCmp("LOOP") == 0) { + } else if (sAction.Equals("LOOP")) { uSkip++; } - if (sAction.CaseCmp("ENDIF") == 0) { + if (sAction.Equals("ENDIF")) { if (uSkip) { uSkip--; } else { uNestedIfs--; } - } else if (sAction.CaseCmp("ENDLOOP") == 0) { + } else if (sAction.Equals("ENDLOOP")) { if (uSkip) { uSkip--; } else { @@ -296,11 +296,11 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { } } } - } else if (sAction.CaseCmp("ELSE") == 0) { + } else if (sAction.Equals("ELSE")) { if (!bValidLastIf && uSkip == 1) { CString sArg = sArgs.Token(0); - if (sArg.empty() || (sArg.CaseCmp("IF") == 0 && ValidIf(sArgs.Token(1, true)))) { + if (sArg.empty() || (sArg.Equals("IF") && ValidIf(sArgs.Token(1, true)))) { uSkip = 0; bValidLastIf = true; } @@ -413,7 +413,7 @@ bool CTemplate::ValidExpr(const CString& sExpr) { return (bNegate != IsTrue(sName)); } - return (bNegate != (GetValue(sName).CaseCmp(sValue) == 0)); + return (bNegate != GetValue(sName).Equals(sValue)); } bool CTemplate::IsTrue(const CString& sName) { diff --git a/User.cpp b/User.cpp index 244afb8a..8c9d133b 100644 --- a/User.cpp +++ b/User.cpp @@ -368,7 +368,7 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneChans) { } for (a = 0; a < m_vServers.size(); a++) { - if (sServer.CaseCmp(m_vServers[a]->GetName()) == 0) { + if (sServer.Equals(m_vServers[a]->GetName())) { m_uServerIdx = a +1; break; } @@ -513,7 +513,7 @@ bool CUser::AddChan(CChan* pChan) { } for (unsigned int a = 0; a < m_vChans.size(); a++) { - if (m_vChans[a]->GetName().CaseCmp(pChan->GetName()) == 0) { + if (m_vChans[a]->GetName().Equals(pChan->GetName())) { delete pChan; return false; } @@ -535,7 +535,7 @@ bool CUser::AddChan(const CString& sName, bool bInConfig) { bool CUser::DelChan(const CString& sName) { for (vector::iterator a = m_vChans.begin(); a != m_vChans.end(); a++) { - if (sName.CaseCmp((*a)->GetName()) == 0) { + if (sName.Equals((*a)->GetName())) { delete *a; m_vChans.erase(a); return true; @@ -651,7 +651,7 @@ bool CUser::WriteConfig(CFile& File) { CChan* CUser::FindChan(const CString& sName) const { for (unsigned int a = 0; a < m_vChans.size(); a++) { CChan* pChan = m_vChans[a]; - if (sName.CaseCmp(pChan->GetName()) == 0) { + if (sName.Equals(pChan->GetName())) { return pChan; } } @@ -682,7 +682,7 @@ void CUser::JoinChans() { CServer* CUser::FindServer(const CString& sName) const { for (unsigned int a = 0; a < m_vServers.size(); a++) { CServer* pServer = m_vServers[a]; - if (sName.CaseCmp(pServer->GetName()) == 0) { + if (sName.Equals(pServer->GetName())) { return pServer; } } @@ -700,7 +700,7 @@ bool CUser::DelServer(const CString& sName) { for (vector::iterator it = m_vServers.begin(); it != m_vServers.end(); it++, a++) { CServer* pServer = *it; - if (pServer->GetName().CaseCmp(sName) == 0) { + if (pServer->GetName().Equals(sName)) { CServer* pCurServer = GetCurrentServer(); m_vServers.erase(it); @@ -813,7 +813,7 @@ bool CUser::CheckPass(const CString& sPass) const { CString sSaltedPass = sPass + m_sPassSalt; - return (m_sPass.CaseCmp(sSaltedPass.MD5()) == 0); + return (m_sPass.Equals(sSaltedPass.MD5())); } /*CClient* CUser::GetClient() { @@ -823,7 +823,7 @@ bool CUser::CheckPass(const CString& sPass) const { for (unsigned int a = 0; a < Manager.size(); a++) { Csock* pSock = Manager[a]; - if (pSock->GetSockName().CaseCmp(sSockName) == 0) { + if (pSock->GetSockName().Equals(sSockName)) { if (!pSock->IsClosed()) { return (CClient*) pSock; } @@ -918,7 +918,7 @@ bool CUser::ResumeFile(unsigned short uPort, unsigned long uFileSize) { CSockManager& Manager = CZNC::Get().GetManager(); for (unsigned int a = 0; a < Manager.size(); a++) { - if (strncasecmp(Manager[a]->GetSockName().c_str(), "DCC::LISTEN::", 13) == 0) { + if (Manager[a]->GetSockName().Equals("DCC::LISTEN::", false, 13)) { CDCCSock* pSock = (CDCCSock*) Manager[a]; if (pSock->GetLocalPort() == uPort) { @@ -948,7 +948,7 @@ bool CUser::SendFile(const CString& sRemoteNick, const CString& sFileName, const unsigned short uPort = CZNC::Get().GetManager().ListenRand("DCC::LISTEN::" + sRemoteNick, GetLocalIP(), false, SOMAXCONN, pSock, 120); - if (GetNick().CaseCmp(sRemoteNick) == 0) { + if (GetNick().Equals(sRemoteNick)) { PutUser(":" + GetStatusPrefix() + "status!znc@znc.in PRIVMSG " + sRemoteNick + " :\001DCC SEND " + pFile->GetShortName() + " " + CString(CUtils::GetLongIP(GetLocalIP())) + " " + CString(uPort) + " " + CString(pFile->GetSize()) + "\001"); } else { diff --git a/Utils.cpp b/Utils.cpp index 3ced88cb..b9d44562 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -260,9 +260,9 @@ bool CUtils::GetBoolInput(const CString& sPrompt, bool *pbDefault) { GetInput(sPrompt, sRet, sDefault, "yes/no"); - if (sRet.CaseCmp("yes") == 0) { + if (sRet.Equals("yes")) { return true; - } else if (sRet.CaseCmp("no") == 0) { + } else if (sRet.Equals("no")) { return false; } @@ -403,7 +403,7 @@ void CUtils::PrintStatus(bool bSuccess, const CString& sMessage) { bool CTable::AddColumn(const CString& sName) { for (unsigned int a = 0; a < m_vsHeaders.size(); a++) { - if (m_vsHeaders[a].CaseCmp(sName) == 0) { + if (m_vsHeaders[a].Equals(sName)) { return false; } } diff --git a/ZNCString.cpp b/ZNCString.cpp index 353b9169..2ae79402 100644 --- a/ZNCString.cpp +++ b/ZNCString.cpp @@ -276,13 +276,13 @@ CString CString::AsLower() const { } CString::EEscape CString::ToEscape(const CString& sEsc) { - if (sEsc.CaseCmp("ASCII") == 0) { + if (sEsc.Equals("ASCII")) { return EASCII; - } else if (sEsc.CaseCmp("HTML") == 0) { + } else if (sEsc.Equals("HTML")) { return EHTML; - } else if (sEsc.CaseCmp("URL") == 0) { + } else if (sEsc.Equals("URL")) { return EURL; - } else if (sEsc.CaseCmp("SQL") == 0) { + } else if (sEsc.Equals("SQL")) { return ESQL; } @@ -919,7 +919,7 @@ CString CString::ToTimeStr(unsigned long s) { return sRet.RightChomp_n(); } -bool CString::ToBool() const { return (!Trim_n().Trim_n("0").empty() && Trim_n().CaseCmp("false") != 0); } +bool CString::ToBool() const { return (!Trim_n().Trim_n("0").empty() && !Trim_n().Equals("false")); } short CString::ToShort() const { return strtoul(this->c_str(), (char**) NULL, 10); } unsigned short CString::ToUShort() const { return strtoul(this->c_str(), (char**) NULL, 10); } unsigned int CString::ToUInt() const { return strtoul(this->c_str(), (char**) NULL, 10); } @@ -976,7 +976,7 @@ CString CString::TrimRight_n(const CString& s) const { } bool CString::TrimPrefix(const CString& sPrefix) { - if (CaseCmp(sPrefix, sPrefix.length()) == 0) { + if (Equals(sPrefix, false, sPrefix.length())) { LeftChomp(sPrefix.length()); return true; } else { @@ -985,7 +985,7 @@ bool CString::TrimPrefix(const CString& sPrefix) { } bool CString::TrimSuffix(const CString& sSuffix) { - if (Right(sSuffix.length()).CaseCmp(sSuffix) == 0) { + if (Right(sSuffix.length()).Equals(sSuffix)) { RightChomp(sSuffix.length()); return true; } else { diff --git a/modules/autoattach.cpp b/modules/autoattach.cpp index c5e789c9..71e47030 100644 --- a/modules/autoattach.cpp +++ b/modules/autoattach.cpp @@ -58,7 +58,7 @@ public: virtual void OnModCommand(const CString& sLine) { CString sCommand = sLine.Token(0); - if (sCommand.CaseCmp("ADD") == 0) { + if (sCommand.Equals("ADD")) { CString sChan = sLine.Token(1); if (AlreadyAdded(sChan)) { @@ -68,14 +68,14 @@ public: } else { PutModule("Usage: Add [!]<#chan>"); } - } else if (sCommand.CaseCmp("DEL") == 0) { + } else if (sCommand.Equals("DEL")) { CString sChan = sLine.Token(1); if (Del(sChan)) PutModule("Removed " + sChan + " from list"); else PutModule("Usage: Del [!]<#chan>"); - } else if (sCommand.CaseCmp("LIST") == 0) { + } else if (sCommand.Equals("LIST")) { CTable Table; Table.AddColumn("Chan"); @@ -94,7 +94,7 @@ public: } else { PutModule("You have no entries."); } - } else if (sCommand.CaseCmp("HELP") == 0) { + } else if (sCommand.Equals("HELP")) { CTable Table; Table.AddColumn("Command"); Table.AddColumn("Description"); diff --git a/modules/autocycle.cpp b/modules/autocycle.cpp index c84c16a8..d862c188 100644 --- a/modules/autocycle.cpp +++ b/modules/autocycle.cpp @@ -42,7 +42,7 @@ public: virtual void OnModCommand(const CString& sLine) { CString sCommand = sLine.Token(0); - if (sCommand.CaseCmp("ADD") == 0) { + if (sCommand.Equals("ADD")) { CString sChan = sLine.Token(1); if (AlreadyAdded(sChan)) { @@ -52,14 +52,14 @@ public: } else { PutModule("Usage: Add [!]<#chan>"); } - } else if (sCommand.CaseCmp("DEL") == 0) { + } else if (sCommand.Equals("DEL")) { CString sChan = sLine.Token(1); if (Del(sChan)) PutModule("Removed " + sChan + " from list"); else PutModule("Usage: Del [!]<#chan>"); - } else if (sCommand.CaseCmp("LIST") == 0) { + } else if (sCommand.Equals("LIST")) { CTable Table; Table.AddColumn("Chan"); @@ -78,7 +78,7 @@ public: } else { PutModule("You have no entries."); } - } else if (sCommand.CaseCmp("HELP") == 0) { + } else if (sCommand.Equals("HELP")) { CTable Table; Table.AddColumn("Command"); Table.AddColumn("Description"); @@ -127,7 +127,7 @@ protected: // Is that person us and we don't have op? const CNick* pNick = Channel.GetNicks().begin()->second; - if (!pNick->HasPerm(CChan::Op) && pNick->GetNick().CaseCmp(m_pUser->GetCurNick()) == 0) + if (!pNick->HasPerm(CChan::Op) && pNick->GetNick().Equals(m_pUser->GetCurNick())) Channel.Cycle(); } diff --git a/modules/autoop.cpp b/modules/autoop.cpp index d2c04586..31759994 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -163,7 +163,7 @@ public: for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); it++) { // and the nick who joined is a valid user if (it->second->HostMatches(Nick.GetHostMask()) && it->second->ChannelMatches(Channel.GetName())) { - if (it->second->GetUserKey().CaseCmp("__NOKEY__") == 0) { + if (it->second->GetUserKey().Equals("__NOKEY__")) { PutIRC("MODE " + Channel.GetName() + " +o " + Nick.GetNick()); } else { // then insert this nick into the queue, the timer does the rest @@ -195,15 +195,15 @@ public: } virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) { - if (sMessage.Token(0).CaseCmp("!ZNCAO") != 0) { + if (!sMessage.Token(0).Equals("!ZNCAO")) { return CONTINUE; } CString sCommand = sMessage.Token(1); - if (sCommand.CaseCmp("CHALLENGE") == 0) { + if (sCommand.Equals("CHALLENGE")) { ChallengeRespond(Nick, sMessage.Token(2)); - } else if (sCommand.CaseCmp("RESPONSE") == 0) { + } else if (sCommand.Equals("RESPONSE")) { VerifyResponse(Nick, sMessage.Token(2)); } @@ -213,16 +213,16 @@ public: virtual void OnModCommand(const CString& sLine) { CString sCommand = sLine.Token(0).AsUpper(); - if (sCommand.CaseCmp("HELP") == 0) { + if (sCommand.Equals("HELP")) { PutModule("Commands are: ListUsers, AddChans, DelChans, AddUser, DelUser"); - } else if (sCommand.CaseCmp("TIMERS") == 0) { + } else if (sCommand.Equals("TIMERS")) { ListTimers(); - } else if (sCommand.CaseCmp("ADDUSER") == 0 || sCommand.CaseCmp("DELUSER") == 0) { + } else if (sCommand.Equals("ADDUSER") || sCommand.Equals("DELUSER")) { CString sUser = sLine.Token(1); CString sHost = sLine.Token(2); CString sKey = sLine.Token(3); - if (sCommand.CaseCmp("ADDUSER") == 0) { + if (sCommand.Equals("ADDUSER")) { if (sHost.empty()) { PutModule("Usage: " + sCommand + " [channels]"); } else { @@ -236,7 +236,7 @@ public: DelUser(sUser); DelNV(sUser); } - } else if (sCommand.CaseCmp("LISTUSERS") == 0) { + } else if (sCommand.Equals("LISTUSERS")) { if (m_msUsers.empty()) { PutModule("There are no users defined"); return; @@ -258,7 +258,7 @@ public: } PutModule(Table); - } else if (sCommand.CaseCmp("ADDCHANS") == 0 || sCommand.CaseCmp("DELCHANS") == 0) { + } else if (sCommand.Equals("ADDCHANS") || sCommand.Equals("DELCHANS")) { CString sUser = sLine.Token(1); CString sChans = sLine.Token(2, true); @@ -274,7 +274,7 @@ public: return; } - if (sCommand.CaseCmp("ADDCHANS") == 0) { + if (sCommand.Equals("ADDCHANS")) { pUser->AddChans(sChans); PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]"); } else { diff --git a/modules/awaynick.cpp b/modules/awaynick.cpp index 0706c3ac..c99be272 100644 --- a/modules/awaynick.cpp +++ b/modules/awaynick.cpp @@ -76,7 +76,7 @@ public: if (pIRCSock) { CString sConfNick = m_pUser->GetNick(); - if (pIRCSock->GetNick().CaseCmp(GetAwayNick().Left(pIRCSock->GetNick().length())) == 0) { + if (pIRCSock->GetNick().Equals(GetAwayNick().Left(pIRCSock->GetNick().length()))) { RemTimer("BackNickTimer"); AddTimer(new CBackNickTimer(*this)); } @@ -104,11 +104,13 @@ public: } } - virtual void OnModCommand(const CString& sCommand) { - if (strcasecmp(sCommand.c_str(), "TIMERS") == 0) { + virtual void OnModCommand(const CString& sLine) { + CString sCommand = sLine.Token(0); + if (sCommand.Equals("TIMERS")) { ListTimers(); - } else if (sCommand.Token(0).CaseCmp("SET") == 0) { - CString sFormat(sCommand.Token(1)); + } + else if (sCommand.Equals("SET")) { + CString sFormat = sLine.Token(1); if (!sFormat.empty()) { m_sFormat = sFormat; @@ -125,7 +127,7 @@ public: PutModule(sMsg); } - } else if (sCommand.Token(0).CaseCmp("SHOW") == 0) { + } else if (sCommand.Equals("SHOW")) { if (m_pUser) { CString sExpanded = GetAwayNick(); CString sMsg = "AwayNick is set to [" + m_sFormat + "]"; @@ -136,7 +138,7 @@ public: PutModule(sMsg); } - } else if (sCommand.Token(0).CaseCmp("HELP") == 0) { + } else if (sCommand.Equals("HELP")) { PutModule("Commands are: show, timers, set [awaynick]"); } } diff --git a/modules/crypt.cpp b/modules/crypt.cpp index a9da9846..72814858 100644 --- a/modules/crypt.cpp +++ b/modules/crypt.cpp @@ -91,7 +91,7 @@ public: virtual void OnModCommand(const CString& sCommand) { CString sCmd = sCommand.Token(0); - if (sCmd.CaseCmp("DELKEY") == 0) { + if (sCmd.Equals("DELKEY")) { CString sTarget = sCommand.Token(1); if (!sTarget.empty()) { @@ -103,14 +103,12 @@ public: } else { PutModule("Usage DelKey <#chan|Nick>"); } - } else if (sCmd.CaseCmp("SETKEY") == 0) { + } else if (sCmd.Equals("SETKEY")) { CString sTarget = sCommand.Token(1); CString sKey = sCommand.Token(2, true); // Strip "cbc:" from beginning of string incase someone pastes directly from mircryption - if (sKey.Left(4).CaseCmp("cbc:") == 0) { - sKey.LeftChomp(4); - } + sKey.TrimPrefix("cbc:"); if (!sKey.empty()) { SetNV(sTarget.AsLower(), sKey); @@ -118,7 +116,7 @@ public: } else { PutModule("Usage: SetKey <#chan|Nick> "); } - } else if (sCmd.CaseCmp("LISTKEYS") == 0) { + } else if (sCmd.Equals("LISTKEYS")) { if (BeginNV() == EndNV()) { PutModule("You have no encryption keys set."); } else { @@ -134,7 +132,7 @@ public: PutModule(Table); } - } else if (sCmd.CaseCmp("HELP") == 0) { + } else if (sCmd.Equals("HELP")) { PutModule("Try: SetKey, DelKey, ListKeys"); } else { PutModule("Unknown command, try 'Help'"); diff --git a/modules/email.cpp b/modules/email.cpp index 2f33e348..07475fc6 100644 --- a/modules/email.cpp +++ b/modules/email.cpp @@ -182,9 +182,9 @@ public: if (sLine.empty()) break; // out of the headers - if (strncasecmp(sLine.c_str(), "From: ", 6) == 0) + if (sLine.Equals("From: ", false, 6)) tmp.sFrom = sLine.substr(6, CString::npos); - else if (strncasecmp(sLine.c_str(), "Subject: ", 9) == 0) + else if (sLine.Equals("Subject: ", false, 9)) tmp.sSubject = sLine.substr(9, CString::npos); if ((!tmp.sFrom.empty()) && (!tmp.sSubject.empty())) diff --git a/modules/imapauth.cpp b/modules/imapauth.cpp index 06aba5ab..5161138d 100644 --- a/modules/imapauth.cpp +++ b/modules/imapauth.cpp @@ -137,7 +137,7 @@ void CIMAPSock::ReadLine(const CString& sLine) { } else { CUser* pUser = CZNC::Get().FindUser(m_spAuth->GetUsername()); - if (pUser && sLine.Left(7).CaseCmp("AUTH OK") == 0) { + if (pUser && sLine.Equals("AUTH OK", false, 7)) { m_spAuth->AcceptLogin(*pUser); m_pIMAPMod->CacheLogin(CString(m_spAuth->GetUsername() + ":" + m_spAuth->GetPassword()).MD5()); // Use MD5 so passes don't sit in memory in plain text DEBUG_ONLY(cerr << "+++ Successful IMAP lookup" << endl); diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index d04fd6e0..314b5793 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -50,7 +50,7 @@ public: return; // Do we already have the nick we want? - if (pIRCSock->GetNick().CaseCmp(GetNick()) == 0) + if (pIRCSock->GetNick().Equals(GetNick())) return; PutIRC("NICK " + GetNick()); @@ -69,12 +69,12 @@ public: void OnNick(const CNick& Nick, const CString& sNewNick, const vector& vChans) { if (sNewNick == GetUser()->GetIRCSock()->GetNick()) { // We are changing our own nick - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { // We are changing our nick away from the conf setting. // Let's assume the user wants this and disable // this module (to avoid fighting nickserv). Disable(); - } else if (sNewNick.CaseCmp(GetNick()) == 0) { + } else if (sNewNick.Equals(GetNick())) { // We are changing our nick to the conf setting, // so we don't need that timer anymore. Disable(); @@ -83,14 +83,14 @@ public: } // If the nick we want is free now, be fast and get the nick - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { KeepNick(); } } void OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { // If someone with the nick we want quits, be fast and get the nick - if (Nick.GetNick().CaseCmp(GetNick()) == 0) { + if (Nick.GetNick().Equals(GetNick())) { KeepNick(); } } @@ -101,7 +101,7 @@ public: } void OnIRCConnected() { - if (GetUser()->GetIRCSock()->GetNick().CaseCmp(GetNick()) != 0) { + if (!GetUser()->GetIRCSock()->GetNick().Equals(GetNick())) { // We don't have the nick we want, try to get it Enable(); } @@ -130,7 +130,7 @@ public: return CONTINUE; // We are trying to get the config nick and this is a /nick? - if (!m_pTimer || sLine.Token(0).CaseCmp("NICK") != 0) + if (!m_pTimer || !sLine.Token(0).Equals("NICK")) return CONTINUE; // Is the nick change for the nick we are trying to get? @@ -140,7 +140,7 @@ public: if (sNick.Left(1) == ":") sNick.LeftChomp(); - if (sNick.CaseCmp(GetNick()) != 0) + if (!sNick.Equals(GetNick())) return CONTINUE; // Indeed trying to change to this nick, generate a 433 for it. @@ -153,7 +153,7 @@ public: virtual EModRet OnRaw(CString& sLine) { // Are we trying to get our primary nick and we caused this error? // :irc.server.net 433 mynick badnick :Nickname is already in use. - if (m_pTimer && sLine.Token(1) == "433" && sLine.Token(3).CaseCmp(GetNick()) == 0) + if (m_pTimer && sLine.Token(1) == "433" && sLine.Token(3).Equals(GetNick())) return HALT; return CONTINUE; diff --git a/modules/kickrejoin.cpp b/modules/kickrejoin.cpp index 351f0594..90688690 100644 --- a/modules/kickrejoin.cpp +++ b/modules/kickrejoin.cpp @@ -96,7 +96,7 @@ public: } virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& pChan, const CString& sMessage) { - if (m_pUser->GetCurNick().CaseCmp(sKickedNick) == 0) { + if (m_pUser->GetCurNick().Equals(sKickedNick)) { if (!delay) { PutIRC("JOIN " + pChan.GetName() + " " + pChan.GetKey()); pChan.Enable(); diff --git a/modules/modperl.cpp b/modules/modperl.cpp index fe5da6d3..515dc5d4 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -260,7 +260,7 @@ public: virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) { - if ((sName.CaseCmp("loadperlmodule") == 0) && (pUser)) + if (sName.Equals("loadperlmodule") && pUser) { m_pUser = pUser; if (sValue.Right(3) == ".pm") @@ -475,14 +475,14 @@ public: { CString sCommand = sLine.Token(0); - if (sCommand.CaseCmp("loadperlmod", 11) == 0 || sCommand.CaseCmp("unloadperlmod", 13) == 0 || sCommand.CaseCmp("reloadperlmod", 13) == 0) + if (sCommand.Equals("loadperlmod", false, 11) || sCommand.Equals("unloadperlmod", false, 13) || sCommand.Equals("reloadperlmod", false, 13)) { CString sModule = sLine.Token(1); if (sModule.Right(3) != ".pm") sModule += ".pm"; - if (sCommand.CaseCmp("loadperlmod", 11) == 0) + if (sCommand.Equals("loadperlmod", false, 11)) LoadPerlMod(sModule); - else if (sCommand.CaseCmp("unloadperlmod", 13) == 0) + else if (sCommand.Equals("unloadperlmod", false, 13)) UnloadPerlMod(sModule); else { diff --git a/modules/nickserv.cpp b/modules/nickserv.cpp index d9a386ad..1f011028 100644 --- a/modules/nickserv.cpp +++ b/modules/nickserv.cpp @@ -52,7 +52,7 @@ public: void HandleMessage(CNick& Nick, const CString& sMessage) { if (!m_sPass.empty() - && Nick.GetNick().CaseCmp("NickServ") == 0 + && Nick.GetNick().Equals("NickServ") && sMessage.find("msg") != CString::npos && sMessage.AsUpper().find("IDENTIFY") != CString::npos && sMessage.find("help") == CString::npos) { diff --git a/modules/partyline.cpp b/modules/partyline.cpp index 19069720..54d8edd6 100644 --- a/modules/partyline.cpp +++ b/modules/partyline.cpp @@ -219,17 +219,15 @@ public: } virtual EModRet OnUserRaw(CString& sLine) { - if (sLine.Left(5).CaseCmp("WHO ~") == 0) { + if (sLine.Equals("WHO ~", false, 5)) { return HALT; - } else if (sLine.Left(6).CaseCmp("MODE ~") == 0) { + } else if (sLine.Equals("MODE ~", false, 6)) { return HALT; - } else if (sLine.Left(8).CaseCmp("TOPIC ~#") == 0) { + } else if (sLine.Equals("TOPIC ~#", false, 8)) { CString sChannel = sLine.Token(1); CString sTopic = sLine.Token(2, true); - if (sTopic.Left(1) == ":") { - sTopic.LeftChomp(); - } + sTopic.TrimPrefix(":"); CPartylineChannel* pChannel = FindChannel(sChannel); @@ -391,7 +389,7 @@ public: virtual void OnModCommand(const CString& sLine) { CString sCommand = sLine.Token(0); - if (sCommand.CaseCmp("HELP") == 0) { + if (sCommand.Equals("HELP")) { CTable Table; Table.AddColumn("Command"); Table.AddColumn("Arguments"); @@ -428,7 +426,7 @@ public: Table.SetCell("Description", "Show which users can not part this channel"); PutModule(Table); - } else if (sCommand.CaseCmp("LIST") == 0) { + } else if (sCommand.Equals("LIST")) { if (!m_ssChannels.size()) { PutModule("There are no open channels."); return; @@ -447,7 +445,7 @@ public: } PutModule(Table); - } else if (sCommand.CaseCmp("ADDFIXCHAN") == 0) { + } else if (sCommand.Equals("ADDFIXCHAN")) { if (!m_pUser->IsAdmin()) { PutModule("Access denied"); return; @@ -474,7 +472,7 @@ public: SaveFixedChans(pUser); PutModule("Fixed " + sUser + " to channel " + sChan); - } else if (sCommand.CaseCmp("DELFIXCHAN") == 0) { + } else if (sCommand.Equals("DELFIXCHAN")) { if (!m_pUser->IsAdmin()) { PutModule("Access denied"); return; @@ -499,7 +497,7 @@ public: SaveFixedChans(pUser); PutModule("Removed " + sUser + " from " + sChan); - } else if (sCommand.CaseCmp("LISTFIXCHANS") == 0) { + } else if (sCommand.Equals("LISTFIXCHANS")) { if (!m_pUser->IsAdmin()) { PutModule("Access denied"); return; @@ -517,7 +515,7 @@ public: } } PutModule("--- End of list"); - } else if (sCommand.CaseCmp("LISTFIXUSERS") == 0) { + } else if (sCommand.Equals("LISTFIXUSERS")) { if (!m_pUser->IsAdmin()) { PutModule("Access denied"); return; diff --git a/modules/perform.cpp b/modules/perform.cpp index 9a7f73ab..d57fa86b 100644 --- a/modules/perform.cpp +++ b/modules/perform.cpp @@ -41,12 +41,12 @@ public: if (sPerf.Left(1) == "/") sPerf.LeftChomp(); - if (sPerf.Token(0).CaseCmp("MSG") == 0) { + if (sPerf.Token(0).Equals("MSG")) { sPerf = "PRIVMSG " + sPerf.Token(1, true); } - if ((sPerf.Token(0).CaseCmp("PRIVMSG") == 0 || - sPerf.Token(0).CaseCmp("NOTICE") == 0) && + if ((sPerf.Token(0).Equals("PRIVMSG") || + sPerf.Token(0).Equals("NOTICE")) && sPerf.Token(2).Left(1) != ":") { sPerf = sPerf.Token(0) + " " + sPerf.Token(1) + " :" + sPerf.Token(2, true); diff --git a/modules/q.cpp b/modules/q.cpp index bdf4cf11..5204b5ca 100755 --- a/modules/q.cpp +++ b/modules/q.cpp @@ -303,7 +303,7 @@ private: } EModRet HandleMessage(const CNick& Nick, CString sMessage) { - if (Nick.GetNick().CaseCmp("Q") != 0 || Nick.GetHost().CaseCmp("CServe.quakenet.org") != 0) + if (!Nick.GetNick().Equals("Q") || !Nick.GetHost().Equals("CServe.quakenet.org")) return CONTINUE; sMessage.Trim(); @@ -330,14 +330,14 @@ private: m_msChanModes[sChannel] = sFlags; } else if (m_bRequestedWhoami && m_bCatchResponse - && (sMessage.CaseCmp("End of list.") == 0 - || sMessage.CaseCmp("account, or HELLO to create an account.") == 0)) { + && (sMessage.Equals("End of list.") + || sMessage.Equals("account, or HELLO to create an account."))) { m_bRequestedWhoami = m_bCatchResponse = false; return HALT; } // AUTH - else if (sMessage.CaseCmp("Username or password incorrect.") == 0) { + else if (sMessage.Equals("Username or password incorrect.")) { m_bAuthed = false; PutModule("Auth failed: " + sMessage); return HALT; @@ -348,7 +348,7 @@ private: WhoAmI(); return HALT; } - else if (m_bRequestedChallenge && sMessage.Token(0).CaseCmp("CHALLENGE") == 0) { + else if (m_bRequestedChallenge && sMessage.Token(0).Equals("CHALLENGE")) { m_bRequestedChallenge = false; if (sMessage.find("not available once you have authed") != CString::npos) { m_bAuthed = true; @@ -409,7 +409,7 @@ private: } bool IsSelf(const CNick& Nick) { - return Nick.GetNick().CaseCmp(m_pUser->GetCurNick()) == 0; + return Nick.GetNick().Equals(m_pUser->GetCurNick()); } bool PackHex(const CString& sHex, CString& sPackedHex) { diff --git a/modules/sample.cpp b/modules/sample.cpp index 3d05e86e..fe6a0327 100644 --- a/modules/sample.cpp +++ b/modules/sample.cpp @@ -205,13 +205,13 @@ public: } virtual void OnModCommand(const CString& sCommand) { - if (strcasecmp(sCommand.c_str(), "TIMERS") == 0) { + if (sCommand.Equals("TIMERS")) { ListTimers(); } } virtual EModRet OnStatusCommand(const CString& sCommand) { - if (strcasecmp(sCommand.c_str(), "SAMPLE") == 0) { + if (sCommand.Equals("SAMPLE")) { PutModule("Hi, I'm your friendly sample module."); return HALT; } diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index 70dd2657..1b09df51 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -157,30 +157,23 @@ public: } } - virtual void OnModCommand(const CString& sCommand) + virtual void OnModCommand(const CString& sCmdLine) { - CString::size_type iPos = sCommand.find(" "); - CString sCom, sArgs; - if (iPos == CString::npos) - sCom = sCommand; - else - { - sCom = sCommand.substr(0, iPos); - sArgs = sCommand.substr(iPos + 1, CString::npos); - } + CString sCommand = sCmdLine.Token(0); + CString sArgs = sCmdLine.Token(1, true); - if (strcasecmp(sCom.c_str(), "setpass") == 0) + if (sCommand.Equals("setpass")) { PutModule("Password set to [" + sArgs + "]"); m_sPassword = CBlowfish::MD5(sArgs); - } else if (strcasecmp(sCom.c_str(), "dumpbuff") == 0) + } else if (sCommand.Equals("dumpbuff")) { CString sFile; if (DecryptChannel(sArgs, sFile)) { CString sLine; - iPos = 0; + CString::size_type iPos = 0; while (ReadLine(sFile, sLine, iPos)) { sLine.Trim(); @@ -188,12 +181,12 @@ public: } } PutModule("//!-- EOF " + sArgs); - } else if (strcasecmp(sCom.c_str(), "replay") == 0) + } else if (sCommand.Equals("replay")) { Replay(sArgs); PutModule("Replayed " + sArgs); - } else if (strcasecmp(sCom.c_str(), "save") == 0) + } else if (sCommand.Equals("save")) { SaveBufferToDisk(); PutModule("Done."); @@ -247,7 +240,7 @@ public: continue; vChans[a]->AddBuffer(SpoofChanMsg(vChans[a]->GetName(), cNick.GetNickMask() + " QUIT " + sMessage)); } - if (cNick.GetNick().CaseCmp(m_pUser->GetNick()) == 0) + if (cNick.GetNick().Equals(m_pUser->GetNick())) SaveBufferToDisk(); // need to force a save here to see this! } @@ -268,7 +261,7 @@ public: } virtual void OnJoin(const CNick& cNick, CChan& cChannel) { - if ((cNick.GetNick().CaseCmp(m_pUser->GetNick()) == 0) && (cChannel.GetBuffer().empty())) + if (cNick.GetNick().Equals(m_pUser->GetNick()) && cChannel.GetBuffer().empty()) { BootStrap((CChan *)&cChannel); if (!cChannel.GetBuffer().empty()) @@ -283,7 +276,7 @@ public: if (!cChannel.KeepBuffer()) return; ((CChan &)cChannel).AddBuffer(SpoofChanMsg(cChannel.GetName(), cNick.GetNickMask() + " PART")); - if (cNick.GetNick().CaseCmp(m_pUser->GetNick()) == 0) + if (cNick.GetNick().Equals(m_pUser->GetNick())) SaveBufferToDisk(); // need to force a save here to see this! } diff --git a/modules/schat.cpp b/modules/schat.cpp index c8bc63d9..f5e5861d 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -161,12 +161,12 @@ public: virtual EModRet OnUserRaw(CString & sLine) { - if (sLine.CaseCmp("schat ", 6) == 0) + if (sLine.Equals("schat ", false, 6)) { OnModCommand("chat " + sLine.substr(6)); return(HALT); - } else if (sLine.CaseCmp("schat") == 0) + } else if (sLine.Equals("schat")) { PutModule("SChat User Area ..."); OnModCommand("help"); @@ -184,7 +184,7 @@ public: sCom = sCommand.Token(0); sArgs = sCommand.Token(1, true); - if ((sCom.CaseCmp("chat") == 0) && (!sArgs.empty())) { + if (sCom.Equals("chat") && !sArgs.empty()) { CString sSockName = "SCHAT::" + m_pUser->GetUserName(); CString sNick = "(s)" + sArgs; for (u_int a= 0; a < m_pManager->size(); a++) @@ -193,7 +193,7 @@ public: continue; CSChatSock *pSock = (CSChatSock *)(*m_pManager)[a]; - if (pSock->GetChatNick().CaseCmp(sNick.c_str()) == 0) + if (pSock->GetChatNick().Equals(sNick)) { PutModule("Already Connected to [" + sArgs + "]"); return; @@ -223,7 +223,7 @@ public: PutIRC(s.str()); - } else if (sCom.CaseCmp("list") == 0) + } else if (sCom.Equals("list")) { CString sName = "SCHAT::" + m_pUser->GetUserName(); CTable Table; @@ -272,7 +272,7 @@ public: } else PutModule("No SDCCs currently in session"); - } else if (sCom.CaseCmp("close") == 0) + } else if (sCom.Equals("close")) { CString sName = "SCHAT::" + m_pUser->GetUserName(); for (u_int a = 0; a < m_pManager->size(); a++) @@ -281,17 +281,17 @@ public: continue; CSChatSock *pSock = (CSChatSock *)(*m_pManager)[a]; - if (sArgs.CaseCmp("(s)", 3) != 0) + if (!sArgs.Equals("(s)", false, 3)) sArgs = "(s)" + sArgs; - if (sArgs.CaseCmp(pSock->GetChatNick()) == 0) + if (sArgs.Equals(pSock->GetChatNick())) { pSock->Close(); return; } } PutModule("No Such Chat [" + sArgs + "]"); - } else if (sCom.CaseCmp("showsocks") == 0) + } else if (sCom.Equals("showsocks")) { CTable Table; Table.AddColumn("SockName"); @@ -344,7 +344,7 @@ public: else PutModule("Error Finding Sockets"); - } else if (sCom.CaseCmp("help") == 0) + } else if (sCom.Equals("help")) { PutModule("Commands are: "); PutModule(" help - This text."); @@ -353,7 +353,7 @@ public: PutModule(" close - Close a chat to a nick."); PutModule(" timers - Shows related timers."); PutModule(" showsocks - Shows all socket connections."); - } else if (sCom.CaseCmp("timers") == 0) + } else if (sCom.Equals("timers")) ListTimers(); else PutModule("Unknown command [" + sCom + "] [" + sArgs + "]"); @@ -361,7 +361,7 @@ public: virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) { - if (sMessage.CaseCmp("DCC SCHAT ", 10) == 0) + if (sMessage.Equals("DCC SCHAT ", false, 10)) { // chat ip port unsigned long iIP = sMessage.Token(3).ToULong(); @@ -413,7 +413,7 @@ public: if (it != m_siiWaitingChats.end()) { - if (sMessage.CaseCmp("yes") != 0) + if (!sMessage.Equals("yes")) SendToUser(sTarget + "!" + sTarget + "@" + CUtils::GetIP(it->second.first), "Refusing to accept DCC SCHAT!"); diff --git a/modules/shell.cpp b/modules/shell.cpp index 1ba68977..c7f1e759 100644 --- a/modules/shell.cpp +++ b/modules/shell.cpp @@ -60,9 +60,11 @@ public: return true; } - virtual void OnModCommand(const CString& sCommand) { - if ((strcasecmp(sCommand.c_str(), "cd") == 0) || (strncasecmp(sCommand.c_str(), "cd ", 3) == 0)) { - CString sPath = CDir::ChangeDir(m_sPath, ((sCommand.length() == 2) ? CString(CZNC::Get().GetHomePath()) : CString(sCommand.substr(3))), CZNC::Get().GetHomePath()); + virtual void OnModCommand(const CString& sLine) { + CString sCommand = sLine.Token(0); + if (sCommand.Equals("cd")) { + CString sArg = sCommand.Token(1, true); + CString sPath = CDir::ChangeDir(m_sPath, (sArg.empty() ? CString(CZNC::Get().GetHomePath()) : sArg), CZNC::Get().GetHomePath()); CFile Dir(sPath); if (Dir.IsDir()) { @@ -74,9 +76,9 @@ public: } PutShell("znc$"); - } else if (strcasecmp(sCommand.Token(0).c_str(), "SEND") == 0) { - CString sToNick = sCommand.Token(1); - CString sFile = sCommand.Token(2); + } else if (sCommand.Equals("SEND")) { + CString sToNick = sLine.Token(1); + CString sFile = sLine.Token(2); if ((sToNick.empty()) || (sFile.empty())) { PutShell("usage: Send "); @@ -91,8 +93,8 @@ public: m_pUser->SendFile(sToNick, sFile, GetModName()); } } - } else if (strcasecmp(sCommand.Token(0).c_str(), "GET") == 0) { - CString sFile = sCommand.Token(1); + } else if (sCommand.Equals("GET")) { + CString sFile = sLine.Token(1); if (sFile.empty()) { PutShell("usage: Get "); @@ -108,12 +110,12 @@ public: } } } else { - RunCommand(sCommand); + RunCommand(sLine); } } virtual EModRet OnStatusCommand(const CString& sCommand) { - if (strcasecmp(sCommand.c_str(), "SHELL") == 0) { + if (sCommand.Equals("SHELL")) { PutShell("-- ZNC Shell Service --"); return HALT; } @@ -122,7 +124,7 @@ public: } virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { - if (strcasecmp(RemoteNick.GetNick().c_str(), CString(GetModNick()).c_str()) == 0) { + if (RemoteNick.GetNick().Equals(GetModNick())) { CString sLocalFile = CDir::ChangeDir(m_sPath, sFile, CZNC::Get().GetHomePath()); m_pUser->GetFile(m_pUser->GetCurNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize, GetModName()); diff --git a/modules/simple_away.cpp b/modules/simple_away.cpp index 09c595e4..ae662c03 100644 --- a/modules/simple_away.cpp +++ b/modules/simple_away.cpp @@ -112,7 +112,7 @@ public: const CString sCmd = sLine.Token(0); const CString sArg = sLine.Token(1, true).Trim_n(" "); - if (sCmd.CaseCmp("AWAY") != 0) + if (!sCmd.Equals("AWAY")) return CONTINUE; // When a client sets us away, we don't touch that away message diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index d477ec86..754bd7fe 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -23,7 +23,7 @@ public: { for (MCString::iterator it = BeginNV(); it != EndNV(); it++) { - if (sChannel.CaseCmp(it->first) == 0) + if (sChannel.Equals(it->first)) { CChan* pChan = m_pUser->FindChan(sChannel); diff --git a/modules/watch.cpp b/modules/watch.cpp index db19ba8d..13385185 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -84,9 +84,9 @@ public: } bool operator ==(const CWatchEntry& WatchEntry) { - return (strcasecmp(GetHostMask().c_str(), WatchEntry.GetHostMask().c_str()) == 0 - && strcasecmp(GetTarget().c_str(), WatchEntry.GetTarget().c_str()) == 0 - && strcasecmp(GetPattern().c_str(), WatchEntry.GetPattern().c_str()) == 0 + return (GetHostMask().Equals(WatchEntry.GetHostMask()) + && GetTarget().Equals(WatchEntry.GetTarget()) + && GetPattern().Equals(WatchEntry.GetPattern()) ); } @@ -229,15 +229,15 @@ public: virtual void OnModCommand(const CString& sCommand) { CString sCmdName = sCommand.Token(0); - if (strcasecmp(sCmdName.c_str(), "ADD") == 0 || strcasecmp(sCmdName.c_str(), "WATCH") == 0) { + if (sCmdName.Equals("ADD") || sCmdName.Equals("WATCH")) { Watch(sCommand.Token(1), sCommand.Token(2), sCommand.Token(3, true)); - } else if (strcasecmp(sCmdName.c_str(), "HELP") == 0) { + } else if (sCmdName.Equals("HELP")) { Help(); - } else if (strcasecmp(sCmdName.c_str(), "LIST") == 0) { + } else if (sCmdName.Equals("LIST")) { List(); - } else if (strcasecmp(sCmdName.c_str(), "DUMP") == 0) { + } else if (sCmdName.Equals("DUMP")) { Dump(); - } else if (strcasecmp(sCmdName.c_str(), "ENABLE") == 0) { + } else if (sCmdName.Equals("ENABLE")) { CString sTok = sCommand.Token(1); if (sTok == "*") { @@ -245,7 +245,7 @@ public: } else { SetDisabled(atoi(sTok.c_str()), false); } - } else if (strcasecmp(sCmdName.c_str(), "DISABLE") == 0) { + } else if (sCmdName.Equals("DISABLE")) { CString sTok = sCommand.Token(1); if (sTok == "*") { @@ -253,12 +253,12 @@ public: } else { SetDisabled(atoi(sTok.c_str()), true); } - } else if (strcasecmp(sCmdName.c_str(), "SETSOURCES") == 0) { + } else if (sCmdName.Equals("SETSOURCES")) { SetSources(atoi(sCommand.Token(1).c_str()), sCommand.Token(2, true)); - } else if (strcasecmp(sCmdName.c_str(), "CLEAR") == 0) { + } else if (sCmdName.Equals("CLEAR")) { m_lsWatchers.clear(); PutModule("All entries cleared."); - } else if (strcasecmp(sCmdName.c_str(), "BUFFER") == 0) { + } else if (sCmdName.Equals("BUFFER")) { CString sCount = sCommand.Token(1); if (sCount.size()) { @@ -266,10 +266,10 @@ public: } PutModule("Buffer count is set to [" + CString(m_Buffer.GetLineCount()) + "]"); - } else if (strcasecmp(sCmdName.c_str(), "DEL") == 0) { + } else if (sCmdName.Equals("DEL")) { Remove(atoi(sCommand.Token(1).c_str())); } else { - PutModule("Unknown command: [" + sCommand.Token(0) + "]"); + PutModule("Unknown command: [" + sCmdName + "]"); } } diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index 11fce9ea..bc6e6bfd 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -136,9 +136,9 @@ public: sOpt = sArgs.Token(0); sArgs = sArgs.Token(1, true); - if (sOpt.CaseCmp("-IPV6") == 0) { + if (sOpt.Equals("-IPV6")) { bIPv6 = true; - } else if (sOpt.CaseCmp("-IPV4") == 0) { + } else if (sOpt.Equals("-IPV4")) { bIPv6 = false; } else { sMessage = "Unknown option [" + sOpt + "] valid options are -ipv4 or -ipv6"; @@ -362,15 +362,15 @@ bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) { m_Template["Title"] = "Main Page"; m_Template["Action"] = "home"; PrintPage(sPageRet, "Main.tmpl"); - } else if (sURI.Left(5).CaseCmp("/css/") == 0) { + } else if (sURI.Equals("/css/", false, 5)) { SetDocRoot(GetSkinDir() + "/css"); PrintFile(sURI.substr(5), "text/css"); return false; - } else if (sURI.Left(5).CaseCmp("/img/") == 0) { + } else if (sURI.Equals("/img/", false, 5)) { SetDocRoot(GetSkinDir() + "/img"); PrintFile(sURI.substr(5)); return false; - } else if (sURI.Left(4).CaseCmp("/js/") == 0) { + } else if (sURI.Equals("/js/", false, 4)) { SetDocRoot(GetSkinDir() + "/js"); PrintFile(sURI.substr(4), "application/x-javascript"); return false; diff --git a/znc.cpp b/znc.cpp index befaa30f..bf040010 100644 --- a/znc.cpp +++ b/znc.cpp @@ -624,7 +624,7 @@ bool CZNC::WriteNewConfig(CString& sConfigFile) { const CModInfo& Info = *it; CString sName = Info.GetName(); - if (sName.Right(3).CaseCmp(".so") == 0) { + if (sName.Right(3).Equals(".so")) { sName.RightChomp(3); } @@ -815,7 +815,7 @@ bool CZNC::WriteNewConfig(CString& sConfigFile) { } if (!bFileOK) { CUtils::GetInput("Please specify an alternate location (or \"stdout\" for displaying the config)", sConfigFile, sConfigFile); - if (sConfigFile.CaseCmp("stdout") == 0) + if (sConfigFile.Equals("stdout")) bFileOK = true; else sConfigFile = ExpandConfigPath(sConfigFile); @@ -1010,7 +1010,7 @@ bool CZNC::DoRehash(CString& sError) if (pUser) { if (pChan) { - if (sTag.CaseCmp("Chan") == 0) { + if (sTag.Equals("Chan")) { // Save the channel name, because AddChan // deletes the CChannel*, if adding fails sError = pChan->GetName(); @@ -1023,7 +1023,7 @@ bool CZNC::DoRehash(CString& sError) pChan = NULL; continue; } - } else if (sTag.CaseCmp("User") == 0) { + } else if (sTag.Equals("User")) { CString sErr; if (pRealUser) { @@ -1054,7 +1054,7 @@ bool CZNC::DoRehash(CString& sError) continue; } } - } else if (sTag.CaseCmp("User") == 0) { + } else if (sTag.Equals("User")) { if (pUser) { sError = "You may not nest tags inside of other tags."; CUtils::PrintError(sError); @@ -1095,7 +1095,7 @@ bool CZNC::DoRehash(CString& sError) } continue; - } else if (sTag.CaseCmp("Chan") == 0) { + } else if (sTag.Equals("Chan")) { if (!pUser) { sError = " tags must be nested inside of a tag."; CUtils::PrintError(sError); @@ -1122,55 +1122,55 @@ bool CZNC::DoRehash(CString& sError) if ((!sName.empty()) && (!sValue.empty())) { if (pUser) { if (pChan) { - if (sName.CaseCmp("Buffer") == 0) { + if (sName.Equals("Buffer")) { pChan->SetBufferCount(strtoul(sValue.c_str(), NULL, 10)); continue; - } else if (sName.CaseCmp("KeepBuffer") == 0) { - pChan->SetKeepBuffer((sValue.CaseCmp("true") == 0)); + } else if (sName.Equals("KeepBuffer")) { + pChan->SetKeepBuffer(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("Detached") == 0) { - pChan->SetDetached((sValue.CaseCmp("true") == 0)); + } else if (sName.Equals("Detached")) { + pChan->SetDetached(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("AutoCycle") == 0) { - if (sValue.CaseCmp("true") == 0) { + } else if (sName.Equals("AutoCycle")) { + if (sValue.Equals("true")) { CUtils::PrintError("WARNING: AutoCycle has been removed, instead try -> LoadModule = autocycle " + pChan->GetName()); } continue; - } else if (sName.CaseCmp("Key") == 0) { + } else if (sName.Equals("Key")) { pChan->SetKey(sValue); continue; - } else if (sName.CaseCmp("Modes") == 0) { + } else if (sName.Equals("Modes")) { pChan->SetDefaultModes(sValue); continue; } } else { - if (sName.CaseCmp("Buffer") == 0) { + if (sName.Equals("Buffer")) { pUser->SetBufferCount(strtoul(sValue.c_str(), NULL, 10)); continue; - } else if (sName.CaseCmp("KeepBuffer") == 0) { - pUser->SetKeepBuffer((sValue.CaseCmp("true") == 0)); + } else if (sName.Equals("KeepBuffer")) { + pUser->SetKeepBuffer(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("Nick") == 0) { + } else if (sName.Equals("Nick")) { pUser->SetNick(sValue); continue; - } else if (sName.CaseCmp("CTCPReply") == 0) { + } else if (sName.Equals("CTCPReply")) { pUser->AddCTCPReply(sValue.Token(0), sValue.Token(1, true)); continue; - } else if (sName.CaseCmp("QuitMsg") == 0) { + } else if (sName.Equals("QuitMsg")) { pUser->SetQuitMsg(sValue); continue; - } else if (sName.CaseCmp("AltNick") == 0) { + } else if (sName.Equals("AltNick")) { pUser->SetAltNick(sValue); continue; - } else if (sName.CaseCmp("AwaySuffix") == 0) { + } else if (sName.Equals("AwaySuffix")) { CUtils::PrintMessage("WARNING: AwaySuffix has been depricated, instead try -> LoadModule = awaynick %nick%_" + sValue); continue; - } else if (sName.CaseCmp("AutoCycle") == 0) { - if (sValue.CaseCmp("true") == 0) { + } else if (sName.Equals("AutoCycle")) { + if (sValue.Equals("true")) { CUtils::PrintError("WARNING: AutoCycle has been removed, instead try -> LoadModule = autocycle"); } continue; - } else if (sName.CaseCmp("Pass") == 0) { + } else if (sName.Equals("Pass")) { // There are different formats for this available: // Pass = // Pass = - @@ -1197,76 +1197,76 @@ bool CZNC::DoRehash(CString& sError) } continue; - } else if (sName.CaseCmp("MultiClients") == 0) { - pUser->SetMultiClients(sValue.CaseCmp("true") == 0); + } else if (sName.Equals("MultiClients")) { + pUser->SetMultiClients(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("BounceDCCs") == 0) { - pUser->SetBounceDCCs(sValue.CaseCmp("true") == 0); + } else if (sName.Equals("BounceDCCs")) { + pUser->SetBounceDCCs(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("Ident") == 0) { + } else if (sName.Equals("Ident")) { pUser->SetIdent(sValue); continue; - } else if (sName.CaseCmp("DenyLoadMod") == 0) { - pUser->SetDenyLoadMod((sValue.CaseCmp("TRUE") == 0)); + } else if (sName.Equals("DenyLoadMod")) { + pUser->SetDenyLoadMod(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("Admin") == 0) { - pUser->SetAdmin((sValue.CaseCmp("TRUE") == 0)); + } else if (sName.Equals("Admin")) { + pUser->SetAdmin(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("DenySetVHost") == 0) { - pUser->SetDenySetVHost((sValue.CaseCmp("TRUE") == 0)); + } else if (sName.Equals("DenySetVHost")) { + pUser->SetDenySetVHost(sValue.Equals("true")); continue; - } else if (sName.CaseCmp("StatusPrefix") == 0) { + } else if (sName.Equals("StatusPrefix")) { if (!pUser->SetStatusPrefix(sValue)) { sError = "Invalid StatusPrefix [" + sValue + "] Must be 1-5 chars, no spaces."; CUtils::PrintError(sError); return false; } continue; - } else if (sName.CaseCmp("DCCLookupMethod") == 0) { - pUser->SetUseClientIP((sValue.CaseCmp("Client") == 0)); + } else if (sName.Equals("DCCLookupMethod")) { + pUser->SetUseClientIP(sValue.Equals("Client")); continue; - } else if (sName.CaseCmp("RealName") == 0) { + } else if (sName.Equals("RealName")) { pUser->SetRealName(sValue); continue; - } else if (sName.CaseCmp("KeepNick") == 0) { - if (sValue.CaseCmp("true") == 0) { + } else if (sName.Equals("KeepNick")) { + if (sValue.Equals("true")) { CUtils::PrintError("WARNING: KeepNick has been deprecated, instead try -> LoadModule = keepnick"); } continue; - } else if (sName.CaseCmp("ChanModes") == 0) { + } else if (sName.Equals("ChanModes")) { pUser->SetDefaultChanModes(sValue); continue; - } else if (sName.CaseCmp("VHost") == 0) { + } else if (sName.Equals("VHost")) { pUser->SetVHost(sValue); continue; - } else if (sName.CaseCmp("Allow") == 0) { + } else if (sName.Equals("Allow")) { pUser->AddAllowedHost(sValue); continue; - } else if (sName.CaseCmp("Server") == 0) { + } else if (sName.Equals("Server")) { CUtils::PrintAction("Adding Server [" + sValue + "]"); CUtils::PrintStatus(pUser->AddServer(sValue)); continue; - } else if (sName.CaseCmp("Chan") == 0) { + } else if (sName.Equals("Chan")) { pUser->AddChan(sValue, true); continue; - } else if (sName.CaseCmp("TimestampFormat") == 0) { + } else if (sName.Equals("TimestampFormat")) { pUser->SetTimestampFormat(sValue); continue; - } else if (sName.CaseCmp("AppendTimestamp") == 0) { + } else if (sName.Equals("AppendTimestamp")) { pUser->SetTimestampAppend(sValue.ToBool()); continue; - } else if (sName.CaseCmp("PrependTimestamp") == 0) { + } else if (sName.Equals("PrependTimestamp")) { pUser->SetTimestampPrepend(sValue.ToBool()); continue; - } else if (sName.CaseCmp("Timestamp") == 0) { - if (sValue.Trim_n().CaseCmp("true") != 0) { - if (sValue.Trim_n().CaseCmp("append") == 0) { + } else if (sName.Equals("Timestamp")) { + if (!sValue.Trim_n().Equals("true")) { + if (sValue.Trim_n().Equals("append")) { pUser->SetTimestampAppend(true); pUser->SetTimestampPrepend(false); - } else if (sValue.Trim_n().CaseCmp("prepend") == 0) { + } else if (sValue.Trim_n().Equals("prepend")) { pUser->SetTimestampAppend(false); pUser->SetTimestampPrepend(true); - } else if (sValue.Trim_n().CaseCmp("false") == 0) { + } else if (sValue.Trim_n().Equals("false")) { pUser->SetTimestampAppend(false); pUser->SetTimestampPrepend(false); } else { @@ -1274,16 +1274,16 @@ bool CZNC::DoRehash(CString& sError) } } continue; - } else if (sName.CaseCmp("TimezoneOffset") == 0) { + } else if (sName.Equals("TimezoneOffset")) { pUser->SetTimezoneOffset(sValue.ToDouble()); // there is no ToFloat() continue; - } else if (sName.CaseCmp("JoinTries") == 0) { + } else if (sName.Equals("JoinTries")) { pUser->SetJoinTries(sValue.ToUInt()); continue; - } else if (sName.CaseCmp("MaxJoins") == 0) { + } else if (sName.Equals("MaxJoins")) { pUser->SetMaxJoins(sValue.ToUInt()); continue; - } else if (sName.CaseCmp("LoadModule") == 0) { + } else if (sName.Equals("LoadModule")) { CString sModName = sValue.Token(0); CUtils::PrintAction("Loading Module [" + sModName + "]"); #ifdef _MODULES @@ -1310,9 +1310,9 @@ bool CZNC::DoRehash(CString& sError) } } } else { - if (sName.CaseCmp("Listen") == 0 || sName.CaseCmp("ListenPort") == 0 || sName.CaseCmp("Listen6") == 0) { + if (sName.Equals("Listen") || sName.Equals("ListenPort") || sName.Equals("Listen6")) { bool bSSL = false; - bool bIPV6 = (sName.CaseCmp("Listen6") == 0); + bool bIPV6 = sName.Equals("Listen6"); CString sPort; CString sBindHost; @@ -1400,7 +1400,7 @@ bool CZNC::DoRehash(CString& sError) CUtils::PrintStatus(true); continue; - } else if (sName.CaseCmp("LoadModule") == 0) { + } else if (sName.Equals("LoadModule")) { #ifdef _MODULES CString sModName = sValue.Token(0); CString sArgs = sValue.Token(1, true); @@ -1416,29 +1416,29 @@ bool CZNC::DoRehash(CString& sError) CUtils::PrintError("Modules are not enabled."); #endif continue; - } else if (sName.CaseCmp("ISpoofFormat") == 0) { + } else if (sName.Equals("ISpoofFormat")) { m_sISpoofFormat = sValue; continue; - } else if (sName.CaseCmp("ISpoofFile") == 0) { + } else if (sName.Equals("ISpoofFile")) { if (sValue.Left(2) == "~/") { sValue.LeftChomp(2); sValue = GetHomePath() + "/" + sValue; } m_sISpoofFile = sValue; continue; - } else if (sName.CaseCmp("MOTD") == 0) { + } else if (sName.Equals("MOTD")) { AddMotd(sValue); continue; - } else if (sName.CaseCmp("VHost") == 0) { + } else if (sName.Equals("VHost")) { AddVHost(sValue); continue; - } else if (sName.CaseCmp("PidFile") == 0) { + } else if (sName.Equals("PidFile")) { m_sPidFile = sValue; continue; - } else if (sName.CaseCmp("StatusPrefix") == 0) { + } else if (sName.Equals("StatusPrefix")) { m_sStatusPrefix = sValue; continue; - } else if (sName.CaseCmp("ConnectDelay") == 0) { + } else if (sName.Equals("ConnectDelay")) { m_uiConnectDelay = sValue.ToUInt(); continue; } @@ -1446,7 +1446,7 @@ bool CZNC::DoRehash(CString& sError) } - if (sName.CaseCmp("GM:", 3) == 0) + if (sName.Equals("GM:", false, 3)) { // GM: prefix is a pass through to config lines for global modules CGlobalModuleConfigLine cTmp; cTmp.m_sName = sName.substr(3, CString::npos); @@ -1574,7 +1574,7 @@ bool CZNC::AddVHost(const CString& sHost) { } for (unsigned int a = 0; a < m_vsVHosts.size(); a++) { - if (m_vsVHosts[a].CaseCmp(sHost) == 0) { + if (m_vsVHosts[a].Equals(sHost)) { return false; } }