mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
Slight refactor of CBuffer & CBufLine.
This is in preparation of adding more attributes to a CBufLine. Going forward, at least savebuf will need access to all of these to properly serialize buffers. Basically, instead of relying on `GetLine()` to return `false`, the caller is now expected to check bounds himself using `Size()`.
This commit is contained in:
@@ -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(); }
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-4
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+6
-28
@@ -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) {
|
||||
|
||||
+3
-3
@@ -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);
|
||||
}
|
||||
|
||||
+11
-9
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user