Coverage Report

Created: 2025-11-09 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/znc/include/znc/Buffer.h
Line
Count
Source
1
/*
2
 * Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ZNC_BUFFER_H
18
#define ZNC_BUFFER_H
19
20
#include <znc/zncconfig.h>
21
#include <znc/ZNCString.h>
22
#include <znc/Message.h>
23
#include <sys/time.h>
24
#include <deque>
25
26
// Forward Declarations
27
class CClient;
28
// !Forward Declarations
29
30
class CBufLine {
31
  public:
32
0
    CBufLine() : CBufLine("") {
33
0
        throw 0;
34
0
    }  // shouldn't be called, but is needed for compilation
35
    CBufLine(const CMessage& Format, const CString& sText = "");
36
    /// @deprecated
37
    CBufLine(const CString& sFormat, const CString& sText = "",
38
             const timeval* ts = nullptr,
39
             const MCString& mssTags = MCString::EmptyMap);
40
    ~CBufLine();
41
    CMessage ToMessage(const CClient& Client, const MCString& mssParams) const;
42
    /// @deprecated Use ToMessage() instead
43
    CString GetLine(const CClient& Client, const MCString& mssParams) const;
44
    /// @deprecated
45
    void UpdateTime();
46
47
0
    bool Equals(const CMessage& Format) const {
48
0
        return m_Message.Equals(Format);
49
0
    }
50
51
    // Setters
52
0
    void SetFormat(const CString& sFormat) { m_Message.Parse(sFormat); }
53
0
    void SetText(const CString& sText) { m_sText = sText; }
54
0
    void SetTime(const timeval& ts) { m_Message.SetTime(ts); }
55
0
    void SetTags(const MCString& mssTags) { m_Message.SetTags(mssTags); }
56
    // !Setters
57
58
    // Getters
59
0
    const CString& GetCommand() const { return m_Message.GetCommand(); }
60
0
    CString GetFormat() const {
61
0
        return m_Message.ToString(CMessage::ExcludeTags);
62
0
    }
63
0
    const CString& GetText() const { return m_sText; }
64
0
    timeval GetTime() const { return m_Message.GetTime(); }
65
0
    const MCString& GetTags() const { return m_Message.GetTags(); }
66
    // !Getters
67
68
  private:
69
  protected:
70
    CMessage m_Message;
71
    CString m_sText;
72
};
73
74
class CBuffer : private std::deque<CBufLine> {
75
  public:
76
    CBuffer(unsigned int uLineCount = 100);
77
    ~CBuffer();
78
79
    size_type AddLine(const CMessage& Format, const CString& sText = "");
80
    size_type UpdateLine(const CString& sCommand, const CMessage& Format,
81
                         const CString& sText = "");
82
    size_type UpdateExactLine(const CMessage& Format,
83
                              const CString& sText = "");
84
85
    size_type AddLine(const CString& sFormat, const CString& sText = "",
86
                      const timeval* ts = nullptr,
87
                      const MCString& mssTags = MCString::EmptyMap);
88
    /// Same as AddLine, but replaces a line whose format string starts with sMatch if there is one.
89
    size_type UpdateLine(const CString& sMatch, const CString& sFormat,
90
                         const CString& sText = "");
91
    /// Same as UpdateLine, but does nothing if this exact line already exists.
92
    /// We need this because "/version" sends us the 005 raws again
93
    size_type UpdateExactLine(const CString& sFormat,
94
                              const CString& sText = "");
95
    const CBufLine& GetBufLine(unsigned int uIdx) const;
96
    CString GetLine(size_type uIdx, const CClient& Client,
97
                    const MCString& msParams = MCString::EmptyMap) const;
98
0
    size_type Size() const { return size(); }
99
0
    bool IsEmpty() const { return empty(); }
100
0
    void Clear() { clear(); }
101
102
    // Setters
103
    bool SetLineCount(unsigned int u, bool bForce = false);
104
    // !Setters
105
106
    // Getters
107
0
    unsigned int GetLineCount() const { return m_uLineCount; }
108
    // !Getters
109
  private:
110
  protected:
111
    unsigned int m_uLineCount;
112
};
113
114
#endif  // !ZNC_BUFFER_H