2
* Copyright (C) 2004-2012 See the AUTHORS file for details.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 2 as published
6
* by the Free Software Foundation.
9
#include <znc/Buffer.h>
11
#include <znc/Client.h>
14
CBufLine::CBufLine(const CString& sFormat, const CString& sText, const timeval* ts) {
23
CBufLine::~CBufLine() {}
25
void CBufLine::UpdateTime() {
26
if (0 == gettimeofday(&m_time, NULL)) {
29
m_time.tv_sec = time(NULL);
33
CString CBufLine::GetLine(const CClient& Client, const MCString& msParams) const {
34
MCString msThisParams = msParams;
36
if (Client.HasServerTime()) {
37
msThisParams["text"] = m_sText;
38
CString sStr = CString::NamedFormat(m_sFormat, msThisParams);
39
CString s_msec(m_time.tv_usec / 1000);
40
while (s_msec.length() < 3) {
41
s_msec = "0" + s_msec;
43
// TODO support message-tags properly
44
return "@time=" + CString(m_time.tv_sec) + "." + s_msec + " " + sStr;
46
msThisParams["text"] = Client.GetUser()->AddTimestamp(m_time.tv_sec, m_sText);
47
return CString::NamedFormat(m_sFormat, msThisParams);
51
CBuffer::CBuffer(unsigned int uLineCount) {
52
m_uLineCount = uLineCount;
55
CBuffer::~CBuffer() {}
57
CBuffer::size_type CBuffer::AddLine(const CString& sFormat, const CString& sText, const timeval* ts) {
62
while (size() >= m_uLineCount) {
66
push_back(CBufLine(sFormat, sText, ts));
70
CBuffer::size_type CBuffer::UpdateLine(const CString& sMatch, const CString& sFormat, const CString& sText) {
71
for (iterator it = begin(); it != end(); ++it) {
72
if (it->GetFormat().compare(0, sMatch.length(), sMatch) == 0) {
73
it->SetFormat(sFormat);
80
return AddLine(sFormat, sText);
83
CBuffer::size_type CBuffer::UpdateExactLine(const CString& sFormat, const CString& sText) {
84
for (iterator it = begin(); it != end(); ++it) {
85
if (it->GetFormat() == sFormat && it->GetText() == sText) {
90
return AddLine(sFormat, sText);
93
const CBufLine& CBuffer::GetBufLine(unsigned int uIdx) const {
97
CString CBuffer::GetLine(size_type uIdx, const CClient& Client, const MCString& msParams) const {
98
return (*this)[uIdx].GetLine(Client, msParams);
101
bool CBuffer::SetLineCount(unsigned int u, bool bForce) {
102
if (!bForce && u > CZNC::Get().GetMaxBufferSize()) {
108
// We may need to shrink the buffer if the allowed size got smaller
109
while (size() > m_uLineCount) {