Full-fledged query buffers

Store query buffers per query the same way it's done for channels.

This allows clients to implement persistent query buffers. Queries
remain open across clients and sessions until a client explicitly
sends a command to clear a (closed) query buffer.

A new config option AutoClearQueryBuffer that default to false
ensures behavioral backwards compatibility, and another config
MaxQueries protects from OOM eg. due to PM attacks.
This commit is contained in:
J-P Nurmi
2014-07-20 20:08:16 +02:00
parent b1b3888231
commit 14a534c953
12 changed files with 360 additions and 81 deletions
+12 -4
View File
@@ -30,6 +30,7 @@ class CConfig;
class CClient;
class CConfig;
class CChan;
class CQuery;
class CServer;
class CIRCSock;
class CIRCNetworkPingTimer;
@@ -96,6 +97,12 @@ public:
void JoinChans();
void JoinChans(std::set<CChan*>& sChans);
const std::vector<CQuery*>& GetQueries() const;
CQuery* FindQuery(const CString& sName) const;
std::vector<CQuery*> FindQueries(const CString& sWild) const;
CQuery* AddQuery(const CString& sName);
bool DelQuery(const CString& sName);
const CString& GetChanPrefixes() const { return m_sChanPrefixes; };
void SetChanPrefixes(const CString& s) { m_sChanPrefixes = s; };
bool IsChan(const CString& sChan) const;
@@ -144,9 +151,9 @@ public:
void UpdateMotdBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_MotdBuffer.UpdateLine(sMatch, sFormat, sText); }
void ClearMotdBuffer() { m_MotdBuffer.Clear(); }
void AddQueryBuffer(const CString& sFormat, const CString& sText = "") { m_QueryBuffer.AddLine(sFormat, sText); }
void UpdateQueryBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_QueryBuffer.UpdateLine(sMatch, sFormat, sText); }
void ClearQueryBuffer() { m_QueryBuffer.Clear(); }
void AddNoticeBuffer(const CString& sFormat, const CString& sText = "") { m_NoticeBuffer.AddLine(sFormat, sText); }
void UpdateNoticeBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_NoticeBuffer.UpdateLine(sMatch, sFormat, sText); }
void ClearNoticeBuffer() { m_NoticeBuffer.Clear(); }
// !Buffers
// la
@@ -192,6 +199,7 @@ protected:
CIRCSock* m_pIRCSock;
std::vector<CChan*> m_vChans;
std::vector<CQuery*> m_vQueries;
CString m_sChanPrefixes;
@@ -208,7 +216,7 @@ protected:
CBuffer m_RawBuffer;
CBuffer m_MotdBuffer;
CBuffer m_QueryBuffer;
CBuffer m_NoticeBuffer;
CIRCNetworkPingTimer* m_pPingTimer;
CIRCNetworkJoinTimer* m_pJoinTimer;
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2004-2014 ZNC, see the NOTICE file for details.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _QUERY_H
#define _QUERY_H
#include <znc/zncconfig.h>
#include <znc/ZNCString.h>
#include <znc/Buffer.h>
// Forward Declarations
class CClient;
class CIRCNetwork;
// !Forward Declarations
class CQuery {
public:
CQuery(const CString& sName, CIRCNetwork* pNetwork);
~CQuery();
// Buffer
const CBuffer& GetBuffer() const { return m_Buffer; }
unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
bool SetBufferCount(unsigned int u, bool bForce = false) { return m_Buffer.SetLineCount(u, bForce); }
size_t AddBuffer(const CString& sFormat, const CString& sText = "", const timeval* ts = NULL) { return m_Buffer.AddLine(sFormat, sText, ts); }
void ClearBuffer() { m_Buffer.Clear(); }
void SendBuffer(CClient* pClient);
void SendBuffer(CClient* pClient, const CBuffer& Buffer);
// !Buffer
// Getters
const CString& GetName() const { return m_sName; }
// !Getters
private:
CString m_sName;
CIRCNetwork* m_pNetwork;
CBuffer m_Buffer;
};
#endif // !_QUERY_H
+6
View File
@@ -126,6 +126,7 @@ public:
bool DelCTCPReply(const CString& sCTCP);
bool SetBufferCount(unsigned int u, bool bForce = false);
void SetAutoClearChanBuffer(bool b);
void SetAutoClearQueryBuffer(bool b);
void SetBeingDeleted(bool b) { m_bBeingDeleted = b; }
void SetTimestampFormat(const CString& s) { m_sTimestampFormat = s; }
@@ -136,6 +137,7 @@ public:
void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
void SetSkinName(const CString& s) { m_sSkinName = s; }
void SetMaxNetworks(unsigned int i) { m_uMaxNetworks = i; }
void SetMaxQueryBuffers(unsigned int i) { m_uMaxQueryBuffers = i; }
// !Setters
// Getters
@@ -171,6 +173,7 @@ public:
const MCString& GetCTCPReplies() const;
unsigned int GetBufferCount() const;
bool AutoClearChanBuffer() const;
bool AutoClearQueryBuffer() const;
bool IsBeingDeleted() const { return m_bBeingDeleted; }
CString GetTimezone() const { return m_sTimezone; }
unsigned long long BytesRead() const { return m_uBytesRead; }
@@ -179,6 +182,7 @@ public:
unsigned int MaxJoins() const { return m_uMaxJoins; }
CString GetSkinName() const;
unsigned int MaxNetworks() const { return m_uMaxNetworks; }
unsigned int MaxQueryBuffers() const { return m_uMaxQueryBuffers; }
// !Getters
protected:
@@ -211,6 +215,7 @@ protected:
bool m_bAdmin;
bool m_bDenySetBindHost;
bool m_bAutoClearChanBuffer;
bool m_bAutoClearQueryBuffer;
bool m_bBeingDeleted;
bool m_bAppendTimestamp;
bool m_bPrependTimestamp;
@@ -225,6 +230,7 @@ protected:
unsigned long long m_uBytesWritten;
unsigned int m_uMaxJoinTries;
unsigned int m_uMaxNetworks;
unsigned int m_uMaxQueryBuffers;
unsigned int m_uMaxJoins;
CString m_sSkinName;