diff --git a/include/znc/Buffer.h b/include/znc/Buffer.h index c0edea17..3a2fa150 100644 --- a/include/znc/Buffer.h +++ b/include/znc/Buffer.h @@ -21,7 +21,7 @@ public: ~CBufLine(); const CString& GetFormat() const { return m_sFormat; } void SetFormat(const CString& sFormat) { m_sFormat = sFormat; } - void GetLine(CString& sRet, const MCString& msParams) const; + CString GetLine(const MCString& msParams) const; private: protected: @@ -38,9 +38,9 @@ public: int UpdateLine(const CString& sMatch, const CString& sFormat); /// Same as UpdateLine, but does nothing if this exact line already exists. int UpdateExactLine(const CString& sFormat); - bool GetNextLine(CString& sRet, const MCString& msParams = MCString::EmptyMap); - bool GetLineFormat(unsigned int uIdx, CString& sRet) const; - bool GetLine(unsigned int uIdx, CString& sRet, const MCString& msParams = MCString::EmptyMap) const; + const CBufLine& GetBufLine(unsigned int uIdx) const; + CString GetLine(unsigned int uIdx, const MCString& msParams = MCString::EmptyMap) const; + unsigned int Size() const { return size(); } bool IsEmpty() const { return empty(); } void Clear() { clear(); } diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index cc7c6cdb..0d35b824 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -148,9 +148,10 @@ public: CString sFile = CRYPT_VERIFICATION_TOKEN; - unsigned int uIdx = 0; - while (Buffer.GetLineFormat(uIdx++, sLine)) { - sFile += sLine + "\n"; + unsigned int uSize = Buffer.Size(); + for (unsigned int uIdx = 0; uIdx < uSize; uIdx++) { + const CBufLine& Line = Buffer.GetBufLine(uIdx); + sFile += Line.GetFormat() + "\n"; } CBlowfish c(m_sPassword, BF_ENCRYPT); diff --git a/modules/watch.cpp b/modules/watch.cpp index bcea6535..bf7d9be5 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -170,11 +170,10 @@ public: MCString msParams; msParams["target"] = m_pNetwork->GetCurNick(); - CString sBufLine; - while (m_Buffer.GetNextLine(sBufLine, msParams)) { - PutUser(sBufLine); + unsigned int uSize = m_Buffer.Size(); + for (unsigned int uIdx = 0; uIdx < uSize; uIdx++) { + PutUser(m_Buffer.GetLine(uIdx, msParams)); } - m_Buffer.Clear(); } diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3de94edd..f205383b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -15,8 +15,8 @@ CBufLine::CBufLine(const CString& sFormat) { CBufLine::~CBufLine() {} -void CBufLine::GetLine(CString& sRet, const MCString& msParams) const { - sRet = CString::NamedFormat(m_sFormat, msParams); +CString CBufLine::GetLine(const MCString& msParams) const { + return CString::NamedFormat(m_sFormat, msParams); } CBuffer::CBuffer(unsigned int uLineCount) { @@ -59,34 +59,12 @@ int CBuffer::UpdateExactLine(const CString& sFormat) { return AddLine(sFormat); } -bool CBuffer::GetLineFormat(unsigned int uIdx, CString& sRet) const { - if (uIdx >= size()) { - return false; - } - - sRet = (*this)[uIdx].GetFormat(); - return true; +const CBufLine& CBuffer::GetBufLine(unsigned int uIdx) const { + return (*this)[uIdx]; } -bool CBuffer::GetLine(unsigned int uIdx, CString& sRet, const MCString& msParams) const { - if (uIdx >= size()) { - return false; - } - - (*this)[uIdx].GetLine(sRet, msParams); - return true; -} - -bool CBuffer::GetNextLine(CString& sRet, const MCString& msParams) { - sRet = ""; - - if (!size()) { - return false; - } - - begin()->GetLine(sRet, msParams); - erase(begin()); - return true; +CString CBuffer::GetLine(unsigned int uIdx, const MCString& msParams) const { + return (*this)[uIdx].GetLine(msParams); } bool CBuffer::SetLineCount(unsigned int u, bool bForce) { diff --git a/src/Chan.cpp b/src/Chan.cpp index 9065989b..96494052 100644 --- a/src/Chan.cpp +++ b/src/Chan.cpp @@ -536,9 +536,9 @@ void CChan::SendBuffer(CClient* pClient) { m_pNetwork->PutUser(":***!znc@znc.in PRIVMSG " + GetName() + " :Buffer Playback...", pUseClient); } - CString sLine; - unsigned int uIdx = 0; - while (m_Buffer.GetLine(uIdx++, sLine)) { + unsigned int uSize = m_Buffer.Size(); + for (unsigned int uIdx = 0; uIdx < uSize; uIdx++) { + CString sLine = m_Buffer.GetLine(uIdx); NETWORKMODULECALL(OnChanBufferPlayLine(*this, *pUseClient, sLine), m_pNetwork->GetUser(), m_pNetwork, NULL, continue); m_pNetwork->PutUser(sLine, pUseClient); } diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index 8bfdcfcf..c5ade057 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -344,17 +344,16 @@ void CIRCNetwork::ClientConnected(CClient *pClient) { m_vClients.push_back(pClient); - unsigned int uIdx; - CString sLine; + unsigned int uIdx, uSize; MCString msParams; msParams["target"] = GetIRCNick().GetNick(); if (m_RawBuffer.IsEmpty()) { pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() + " :- Welcome to ZNC -"); } else { - uIdx = 0; - while (m_RawBuffer.GetLine(uIdx++, sLine, msParams)) { - pClient->PutClient(sLine); + uSize = m_RawBuffer.Size(); + for (uIdx = 0; uIdx < uSize; uIdx++) { + pClient->PutClient(m_RawBuffer.GetLine(uIdx, msParams)); } // The assumption is that the client got this nick from the 001 reply @@ -362,9 +361,9 @@ void CIRCNetwork::ClientConnected(CClient *pClient) { } // Send the cached MOTD - uIdx = 0; - while (m_MotdBuffer.GetLine(uIdx++, sLine, msParams)) { - pClient->PutClient(sLine); + uSize = m_MotdBuffer.Size(); + for (uIdx = 0; uIdx < uSize; uIdx++) { + pClient->PutClient(m_MotdBuffer.GetLine(uIdx, msParams)); } if (GetIRCSock() != NULL) { @@ -392,10 +391,13 @@ void CIRCNetwork::ClientConnected(CClient *pClient) { } } - while (m_QueryBuffer.GetNextLine(sLine, msParams)) { + uSize = m_QueryBuffer.Size(); + for (uIdx = 0; uIdx < uSize; uIdx++) { + CString sLine = m_QueryBuffer.GetLine(uIdx, msParams); NETWORKMODULECALL(OnPrivBufferPlayLine(*pClient, sLine), m_pUser, this, NULL, continue); pClient->PutClient(sLine); } + m_QueryBuffer.Clear(); // Tell them why they won't connect if (!m_pUser->GetIRCConnectEnabled())