Get rid of most strtoul() and atoi() calls and use CString's features instead

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1320 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2009-01-04 10:48:02 +00:00
parent cae48ab256
commit 607a7f1c16
11 changed files with 29 additions and 27 deletions
+6 -6
View File
@@ -388,9 +388,9 @@ void CClient::ReadLine(const CString& sData) {
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);
unsigned short uPort = strtoul(sCTCP.Token(4).c_str(), NULL, 10);
unsigned long uFileSize = strtoul(sCTCP.Token(5).c_str(), NULL, 10);
unsigned long uLongIP = sCTCP.Token(3).ToULong();
unsigned short uPort = sCTCP.Token(4).ToUShort();
unsigned long uFileSize = sCTCP.Token(5).ToULong();
CString sIP = (m_pIRCSock) ? m_pIRCSock->GetLocalIP() : GetLocalIP();
if (!m_pUser->UseClientIP()) {
@@ -432,8 +432,8 @@ void CClient::ReadLine(const CString& sData) {
}
} 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);
unsigned short uResumePort = sCTCP.Token(3).ToUShort();
unsigned long uResumeSize = sCTCP.Token(4).ToULong();
// Need to lookup the connection by port, filter the port, and forward to the user
CString sStatusPrefix = m_pUser->GetStatusPrefix();
@@ -459,7 +459,7 @@ void CClient::ReadLine(const CString& sData) {
CDCCBounce* pSock = (CDCCBounce*) Manager[a];
if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) {
if (pSock->GetUserPort() == atoi(sCTCP.Token(3).c_str())) {
if (pSock->GetUserPort() == sCTCP.Token(3).ToUShort()) {
PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sCTCP.Token(4) + "\001");
}
}
+1 -1
View File
@@ -901,7 +901,7 @@ void CClient::UserCommand(const CString& sLine) {
return;
}
unsigned int uLineCount = strtoul(sLine.Token(2).c_str(), NULL, 10);
unsigned int uLineCount = sLine.Token(2).ToUInt();
if (uLineCount > 500) {
PutStatus("Max linecount is 500.");
+7 -7
View File
@@ -98,7 +98,7 @@ void CIRCSock::ReadLine(const CString& sData) {
if ((sCmd.length() == 3) && (isdigit(sCmd[0])) && (isdigit(sCmd[1])) && (isdigit(sCmd[2]))) {
CString sServer = sLine.Token(0); sServer.LeftChomp();
unsigned int uRaw = strtoul(sCmd.c_str(), NULL, 10);
unsigned int uRaw = sCmd.ToUInt();
CString sNick = sLine.Token(2);
CString sRest = sLine.Token(3, true);
@@ -202,7 +202,7 @@ void CIRCSock::ReadLine(const CString& sData) {
if (pChan) {
sNick = sLine.Token(4);
unsigned long ulDate = strtoul(sLine.Token(5).c_str(), NULL, 10);
unsigned long ulDate = sLine.Token(5).ToULong();
pChan->SetTopicOwner(sNick);
pChan->SetTopicDate(ulDate);
@@ -249,7 +249,7 @@ void CIRCSock::ReadLine(const CString& sData) {
CChan* pChan = m_pUser->FindChan(sRest.Token(0));
if (pChan) {
unsigned long ulDate = strtoul(sLine.Token(4).c_str(), NULL, 10);
unsigned long ulDate = sLine.Token(4).ToULong();
pChan->SetCreationDate(ulDate);
}
}
@@ -624,9 +624,9 @@ bool CIRCSock::OnPrivCTCP(CNick& Nick, CString& sMessage) {
// DCC CHAT chat 2453612361 44592
CString sType = sMessage.Token(1);
CString sFile = sMessage.Token(2);
unsigned long uLongIP = strtoul(sMessage.Token(3).c_str(), NULL, 10);
unsigned short uPort = strtoul(sMessage.Token(4).c_str(), NULL, 10);
unsigned long uFileSize = strtoul(sMessage.Token(5).c_str(), NULL, 10);
unsigned long uLongIP = sMessage.Token(3).ToULong();
unsigned short uPort = sMessage.Token(4).ToUShort();
unsigned long uFileSize = sMessage.Token(5).ToULong();
if (sType.Equals("CHAT")) {
CNick FromNick(Nick.GetNickMask());
@@ -655,7 +655,7 @@ bool CIRCSock::OnPrivCTCP(CNick& Nick, CString& sMessage) {
CDCCBounce* pSock = (CDCCBounce*) Manager[a];
if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) {
if (pSock->GetUserPort() == atoi(sMessage.Token(3).c_str())) {
if (pSock->GetUserPort() == sMessage.Token(3).ToUShort()) {
m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + GetNick() + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sMessage.Token(4) + "\001");
}
}
+1 -1
View File
@@ -747,7 +747,7 @@ bool CUser::AddServer(const CString& sName) {
sPort.LeftChomp();
}
unsigned short uPort = strtoul(sPort.c_str(), NULL, 10);
unsigned short uPort = sPort.ToUShort();
CString sPass = sLine.Token(2, true);
return AddServer(sHost, uPort, sPass, bSSL);
+1 -1
View File
@@ -289,7 +289,7 @@ bool CUtils::GetNumInput(const CString& sPrompt, unsigned int& uRet, unsigned in
return false;
}
uRet = atoi(sNum.c_str());
uRet = sNum.ToUInt();
if ((uRet >= uMin && uRet <= uMax)) {
break;
+1
View File
@@ -924,6 +924,7 @@ 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); }
int CString::ToInt() const { return strtoul(this->c_str(), (char**) NULL, 10); }
long CString::ToLong() const { return strtoul(this->c_str(), (char**) NULL, 10); }
unsigned long CString::ToULong() const { return strtoul(c_str(), NULL, 10); }
unsigned long long CString::ToULongLong() const { return strtoull(c_str(), NULL, 10); }
long long CString::ToLongLong() const { return strtoll(c_str(), NULL, 10); }
+1
View File
@@ -135,6 +135,7 @@ public:
short ToShort() const;
unsigned short ToUShort() const;
int ToInt() const;
long ToLong() const;
unsigned int ToUInt() const;
unsigned long ToULong() const;
unsigned long long ToULongLong() const;
+2 -2
View File
@@ -195,7 +195,7 @@ public:
return;
} else
{
u_int iNum = atoi(sWhich.c_str());
u_int iNum = sWhich.ToUInt();
if (iNum >= m_vMessages.size())
{
PutModNotice("Illegal Message # Requested", "away");
@@ -241,7 +241,7 @@ public:
m_vMessages.erase(m_vMessages.begin() + a--);
continue;
}
time_t iTime = strtol(sTime.c_str(), NULL, 10);
time_t iTime = sTime.ToULong();
char szFormat[64];
struct tm t;
localtime_r(&iTime, &t);
+1 -1
View File
@@ -47,7 +47,7 @@ public:
PutModule("Added!");
Save();
} else if (sCmdName == "del") {
u_int iNum = atoi(sCommand.Token(1, true).c_str());
u_int iNum = sCommand.Token(1, true).ToUInt();
if (iNum > m_vPerform.size() || iNum <= 0) {
PutModule("Illegal # Requested");
return;
+5 -5
View File
@@ -245,7 +245,7 @@ public:
if (sTok == "*") {
SetDisabled(~0, false);
} else {
SetDisabled(atoi(sTok.c_str()), false);
SetDisabled(sTok.ToUInt(), false);
}
} else if (sCmdName.Equals("DISABLE")) {
CString sTok = sCommand.Token(1);
@@ -253,10 +253,10 @@ public:
if (sTok == "*") {
SetDisabled(~0, true);
} else {
SetDisabled(atoi(sTok.c_str()), true);
SetDisabled(sTok.ToUInt(), true);
}
} else if (sCmdName.Equals("SETSOURCES")) {
SetSources(atoi(sCommand.Token(1).c_str()), sCommand.Token(2, true));
SetSources(sCommand.Token(1).ToUInt(), sCommand.Token(2, true));
} else if (sCmdName.Equals("CLEAR")) {
m_lsWatchers.clear();
PutModule("All entries cleared.");
@@ -264,12 +264,12 @@ public:
CString sCount = sCommand.Token(1);
if (sCount.size()) {
m_Buffer.SetLineCount(atoi(sCount.c_str()));
m_Buffer.SetLineCount(sCount.ToUInt());
}
PutModule("Buffer count is set to [" + CString(m_Buffer.GetLineCount()) + "]");
} else if (sCmdName.Equals("DEL")) {
Remove(atoi(sCommand.Token(1).c_str()));
Remove(sCommand.Token(1).ToUInt());
} else {
PutModule("Unknown command: [" + sCmdName + "]");
}
+3 -3
View File
@@ -1158,7 +1158,7 @@ bool CZNC::DoRehash(CString& sError)
if (pUser) {
if (pChan) {
if (sName.Equals("Buffer")) {
pChan->SetBufferCount(strtoul(sValue.c_str(), NULL, 10));
pChan->SetBufferCount(sValue.ToUInt());
continue;
} else if (sName.Equals("KeepBuffer")) {
pChan->SetKeepBuffer(sValue.Equals("true"));
@@ -1180,7 +1180,7 @@ bool CZNC::DoRehash(CString& sError)
}
} else {
if (sName.Equals("Buffer")) {
pUser->SetBufferCount(strtoul(sValue.c_str(), NULL, 10));
pUser->SetBufferCount(sValue.ToUInt());
continue;
} else if (sName.Equals("KeepBuffer")) {
pUser->SetKeepBuffer(sValue.Equals("true"));
@@ -1380,7 +1380,7 @@ bool CZNC::DoRehash(CString& sError)
sIPV6Comment = " using ipv6";
}
unsigned short uPort = strtol(sPort.c_str(), NULL, 10);
unsigned short uPort = sPort.ToUShort();
CUtils::PrintAction("Binding to port [" + CString((bSSL) ? "+" : "") + CString(uPort) + "]" + sHostComment + sIPV6Comment);
#ifndef HAVE_IPV6