mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
/version generates a 005 server reply. We used to cache this reply in the raw buffer and the next user who logs in then received the same 005 reply multiple times. We fix this by adding CBuffer::UpdateExactLine() which does nothing if the exact same line is already in the buffer. The only place where we (currently?) use this is the raw 005 reply. This should fix sf bug #2817124. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1579 726aef4b-f618-498e-8847-2d620e286838
95 lines
2.0 KiB
C++
95 lines
2.0 KiB
C++
/*
|
|
* Copyright (C) 2004-2009 See the AUTHORS file for details.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
* by the Free Software Foundation.
|
|
*/
|
|
|
|
#include "Buffer.h"
|
|
|
|
CBufLine::CBufLine(const CString& sPre, const CString& sPost, bool bIncNick=true) {
|
|
m_sPre = sPre;
|
|
m_sPost = sPost;
|
|
m_bIncNick = bIncNick;
|
|
}
|
|
|
|
CBufLine::~CBufLine() {}
|
|
|
|
void CBufLine::GetLine(const CString& sTarget, CString& sRet) const {
|
|
if (m_bIncNick)
|
|
sRet = m_sPre + sTarget + m_sPost;
|
|
else
|
|
sRet = m_sPre + m_sPost;
|
|
}
|
|
|
|
CBuffer::CBuffer(unsigned int uLineCount) {
|
|
m_uLineCount = uLineCount;
|
|
}
|
|
|
|
CBuffer::~CBuffer() {}
|
|
|
|
int CBuffer::AddLine(const CString& sPre, const CString& sPost, bool bIncNick) {
|
|
if (!m_uLineCount) {
|
|
return 0;
|
|
}
|
|
|
|
while (size() >= m_uLineCount) {
|
|
erase(begin());
|
|
}
|
|
|
|
push_back(CBufLine(sPre, sPost, bIncNick));
|
|
return size();
|
|
}
|
|
|
|
int CBuffer::UpdateLine(const CString& sPre, const CString& sPost, bool bIncNick) {
|
|
for (iterator it = begin(); it != end(); it++) {
|
|
if (it->GetPre() == sPre) {
|
|
it->SetPost(sPost);
|
|
it->SetIncNick(bIncNick);
|
|
return size();
|
|
}
|
|
}
|
|
|
|
return AddLine(sPre, sPost, bIncNick);
|
|
}
|
|
|
|
int CBuffer::UpdateExactLine(const CString& sPre, const CString& sPost, bool bIncNick) {
|
|
for (iterator it = begin(); it != end(); it++) {
|
|
if (it->GetPre() == sPre && it->GetPost() == sPost)
|
|
return size();
|
|
}
|
|
|
|
return AddLine(sPre, sPost, bIncNick);
|
|
}
|
|
|
|
bool CBuffer::GetLine(const CString& sTarget, CString& sRet, unsigned int uIdx) const {
|
|
if (uIdx >= size()) {
|
|
return false;
|
|
}
|
|
|
|
(*this)[uIdx].GetLine(sTarget, sRet);
|
|
return true;
|
|
}
|
|
|
|
bool CBuffer::GetNextLine(const CString& sTarget, CString& sRet) {
|
|
sRet = "";
|
|
|
|
if (!size()) {
|
|
return false;
|
|
}
|
|
|
|
begin()->GetLine(sTarget, sRet);
|
|
erase(begin());
|
|
return true;
|
|
}
|
|
|
|
void CBuffer::SetLineCount(unsigned int u) {
|
|
m_uLineCount = u;
|
|
|
|
// We may need to shrink the buffer if the allowed size got smaller
|
|
while (size() > m_uLineCount) {
|
|
erase(begin());
|
|
}
|
|
}
|