clang-format: switch tabs to spaces

I like tabs, but I have to admit that spaces make source code more
consistent, because every editor/viewer tends to render tabs differently :(
pull/1201/head
Alexey Sokolov 7 years ago
parent 3861b6a583
commit d185d6f22d

@ -2,7 +2,6 @@
BasedOnStyle: Google
Standard: Cpp11
UseTab: ForIndentation
IndentWidth: 4
TabWidth: 4
AccessModifierOffset: -2

@ -29,86 +29,86 @@ class CClient;
class CBufLine {
public:
CBufLine() : CBufLine("") {
throw 0;
} // shouldn't be called, but is needed for compilation
CBufLine(const CMessage& Format, const CString& sText = "");
/// @deprecated
CBufLine(const CString& sFormat, const CString& sText = "",
const timeval* ts = nullptr,
const MCString& mssTags = MCString::EmptyMap);
~CBufLine();
CMessage ToMessage(const CClient& Client, const MCString& mssParams) const;
/// @deprecated Use ToMessage() instead
CString GetLine(const CClient& Client, const MCString& mssParams) const;
/// @deprecated
void UpdateTime();
CBufLine() : CBufLine("") {
throw 0;
} // shouldn't be called, but is needed for compilation
CBufLine(const CMessage& Format, const CString& sText = "");
/// @deprecated
CBufLine(const CString& sFormat, const CString& sText = "",
const timeval* ts = nullptr,
const MCString& mssTags = MCString::EmptyMap);
~CBufLine();
CMessage ToMessage(const CClient& Client, const MCString& mssParams) const;
/// @deprecated Use ToMessage() instead
CString GetLine(const CClient& Client, const MCString& mssParams) const;
/// @deprecated
void UpdateTime();
bool Equals(const CMessage& Format) const {
return m_Message.Equals(Format);
}
bool Equals(const CMessage& Format) const {
return m_Message.Equals(Format);
}
// Setters
void SetFormat(const CString& sFormat) { m_Message.Parse(sFormat); }
void SetText(const CString& sText) { m_sText = sText; }
void SetTime(const timeval& ts) { m_Message.SetTime(ts); }
void SetTags(const MCString& mssTags) { m_Message.SetTags(mssTags); }
// !Setters
// Setters
void SetFormat(const CString& sFormat) { m_Message.Parse(sFormat); }
void SetText(const CString& sText) { m_sText = sText; }
void SetTime(const timeval& ts) { m_Message.SetTime(ts); }
void SetTags(const MCString& mssTags) { m_Message.SetTags(mssTags); }
// !Setters
// Getters
const CString& GetCommand() const { return m_Message.GetCommand(); }
CString GetFormat() const {
return m_Message.ToString(CMessage::ExcludeTags);
}
const CString& GetText() const { return m_sText; }
timeval GetTime() const { return m_Message.GetTime(); }
const MCString& GetTags() const { return m_Message.GetTags(); }
// !Getters
// Getters
const CString& GetCommand() const { return m_Message.GetCommand(); }
CString GetFormat() const {
return m_Message.ToString(CMessage::ExcludeTags);
}
const CString& GetText() const { return m_sText; }
timeval GetTime() const { return m_Message.GetTime(); }
const MCString& GetTags() const { return m_Message.GetTags(); }
// !Getters
private:
protected:
CMessage m_Message;
CString m_sText;
CMessage m_Message;
CString m_sText;
};
class CBuffer : private std::deque<CBufLine> {
public:
CBuffer(unsigned int uLineCount = 100);
~CBuffer();
CBuffer(unsigned int uLineCount = 100);
~CBuffer();
size_type AddLine(const CMessage& Format, const CString& sText = "");
size_type UpdateLine(const CString& sCommand, const CMessage& Format,
const CString& sText = "");
size_type UpdateExactLine(const CMessage& Format,
const CString& sText = "");
size_type AddLine(const CMessage& Format, const CString& sText = "");
size_type UpdateLine(const CString& sCommand, const CMessage& Format,
const CString& sText = "");
size_type UpdateExactLine(const CMessage& Format,
const CString& sText = "");
size_type AddLine(const CString& sFormat, const CString& sText = "",
const timeval* ts = nullptr,
const MCString& mssTags = MCString::EmptyMap);
/// Same as AddLine, but replaces a line whose format string starts with sMatch if there is one.
size_type UpdateLine(const CString& sMatch, const CString& sFormat,
const CString& sText = "");
/// Same as UpdateLine, but does nothing if this exact line already exists.
/// We need this because "/version" sends us the 005 raws again
size_type UpdateExactLine(const CString& sFormat,
const CString& sText = "");
const CBufLine& GetBufLine(unsigned int uIdx) const;
CString GetLine(size_type uIdx, const CClient& Client,
const MCString& msParams = MCString::EmptyMap) const;
size_type Size() const { return size(); }
bool IsEmpty() const { return empty(); }
void Clear() { clear(); }
size_type AddLine(const CString& sFormat, const CString& sText = "",
const timeval* ts = nullptr,
const MCString& mssTags = MCString::EmptyMap);
/// Same as AddLine, but replaces a line whose format string starts with sMatch if there is one.
size_type UpdateLine(const CString& sMatch, const CString& sFormat,
const CString& sText = "");
/// Same as UpdateLine, but does nothing if this exact line already exists.
/// We need this because "/version" sends us the 005 raws again
size_type UpdateExactLine(const CString& sFormat,
const CString& sText = "");
const CBufLine& GetBufLine(unsigned int uIdx) const;
CString GetLine(size_type uIdx, const CClient& Client,
const MCString& msParams = MCString::EmptyMap) const;
size_type Size() const { return size(); }
bool IsEmpty() const { return empty(); }
void Clear() { clear(); }
// Setters
bool SetLineCount(unsigned int u, bool bForce = false);
// !Setters
// Setters
bool SetLineCount(unsigned int u, bool bForce = false);
// !Setters
// Getters
unsigned int GetLineCount() const { return m_uLineCount; }
// !Getters
// Getters
unsigned int GetLineCount() const { return m_uLineCount; }
// !Getters
private:
protected:
unsigned int m_uLineCount;
unsigned int m_uLineCount;
};
#endif // !ZNC_BUFFER_H

@ -33,178 +33,178 @@ class CFile;
class CChan {
public:
typedef enum {
Voice = '+',
HalfOp = '%',
Op = '@',
Admin = '!',
Owner = '*'
} EUserPerms;
typedef enum {
M_Private = 'p',
M_Secret = 's',
M_Moderated = 'm',
M_InviteOnly = 'i',
M_NoMessages = 'n',
M_OpTopic = 't',
M_Limit = 'l',
M_Key = 'k',
M_Op = 'o',
M_Voice = 'v',
M_Ban = 'b',
M_Except = 'e'
} EModes;
CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig,
CConfig* pConfig = nullptr);
~CChan();
CChan(const CChan&) = delete;
CChan& operator=(const CChan&) = delete;
void Reset();
CConfig ToConfig() const;
void Clone(CChan& chan);
void Cycle() const;
void JoinUser(const CString& sKey = "");
void AttachUser(CClient* pClient = nullptr);
void DetachUser();
void OnWho(const CString& sNick, const CString& sIdent,
const CString& sHost);
// Modes
void SetModes(const CString& s);
void ModeChange(const CString& sModes, const CNick* OpNick = nullptr);
bool AddMode(unsigned char uMode, const CString& sArg);
bool RemMode(unsigned char uMode);
CString GetModeString() const;
CString GetModeArg(CString& sArgs) const;
CString GetModeForNames() const;
// !Modes
// Nicks
void ClearNicks();
const CNick* FindNick(const CString& sNick) const;
CNick* FindNick(const CString& sNick);
int AddNicks(const CString& sNicks);
bool AddNick(const CString& sNick);
bool RemNick(const CString& sNick);
bool ChangeNick(const CString& sOldNick, const CString& sNewNick);
// !Nicks
// Buffer
const CBuffer& GetBuffer() const { return m_Buffer; }
unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
bool SetBufferCount(unsigned int u, bool bForce = false) {
m_bHasBufferCountSet = true;
return m_Buffer.SetLineCount(u, bForce);
}
void InheritBufferCount(unsigned int u, bool bForce = false) {
if (!m_bHasBufferCountSet) m_Buffer.SetLineCount(u, bForce);
}
void ResetBufferCount();
size_t AddBuffer(const CMessage& Format, const CString& sText = "") {
return m_Buffer.AddLine(Format, sText);
}
/// @deprecated
size_t AddBuffer(const CString& sFormat, const CString& sText = "",
const timeval* ts = nullptr,
const MCString& mssTags = MCString::EmptyMap) {
return m_Buffer.AddLine(sFormat, sText, ts, mssTags);
}
void ClearBuffer() { m_Buffer.Clear(); }
void SendBuffer(CClient* pClient);
void SendBuffer(CClient* pClient, const CBuffer& Buffer);
// !Buffer
// m_Nick wrappers
CString GetPermStr() const { return m_Nick.GetPermStr(); }
bool HasPerm(unsigned char uPerm) const { return m_Nick.HasPerm(uPerm); }
bool AddPerm(unsigned char uPerm) { return m_Nick.AddPerm(uPerm); }
bool RemPerm(unsigned char uPerm) { return m_Nick.RemPerm(uPerm); }
// !wrappers
// Setters
void SetModeKnown(bool b) { m_bModeKnown = b; }
void SetIsOn(bool b) {
m_bIsOn = b;
if (!b) {
Reset();
}
}
void SetKey(const CString& s);
void SetTopic(const CString& s) { m_sTopic = s; }
void SetTopicOwner(const CString& s) { m_sTopicOwner = s; }
void SetTopicDate(unsigned long u) { m_ulTopicDate = u; }
void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
void SetAutoClearChanBuffer(bool b);
void InheritAutoClearChanBuffer(bool b);
void ResetAutoClearChanBuffer();
void SetDetached(bool b = true) { m_bDetached = b; }
void SetInConfig(bool b);
void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
void Disable() { m_bDisabled = true; }
void Enable();
void IncJoinTries() { m_uJoinTries++; }
void ResetJoinTries() { m_uJoinTries = 0; }
// !Setters
// Getters
CIRCNetwork* GetNetwork() const { return m_pNetwork; }
bool IsModeKnown() const { return m_bModeKnown; }
bool HasMode(unsigned char uMode) const;
CString GetOptions() const;
CString GetModeArg(unsigned char uMode) const;
std::map<char, unsigned int> GetPermCounts() const;
bool IsOn() const { return m_bIsOn; }
const CString& GetName() const { return m_sName; }
const std::map<unsigned char, CString>& GetModes() const {
return m_musModes;
}
const CString& GetKey() const { return m_sKey; }
const CString& GetTopic() const { return m_sTopic; }
const CString& GetTopicOwner() const { return m_sTopicOwner; }
unsigned long GetTopicDate() const { return m_ulTopicDate; }
const CString& GetDefaultModes() const { return m_sDefaultModes; }
const std::map<CString, CNick>& GetNicks() const { return m_msNicks; }
size_t GetNickCount() const { return m_msNicks.size(); }
bool AutoClearChanBuffer() const { return m_bAutoClearChanBuffer; }
bool IsDetached() const { return m_bDetached; }
bool InConfig() const { return m_bInConfig; }
unsigned long GetCreationDate() const { return m_ulCreationDate; }
bool IsDisabled() const { return m_bDisabled; }
unsigned int GetJoinTries() const { return m_uJoinTries; }
bool HasBufferCountSet() const { return m_bHasBufferCountSet; }
bool HasAutoClearChanBufferSet() const {
return m_bHasAutoClearChanBufferSet;
}
// !Getters
typedef enum {
Voice = '+',
HalfOp = '%',
Op = '@',
Admin = '!',
Owner = '*'
} EUserPerms;
typedef enum {
M_Private = 'p',
M_Secret = 's',
M_Moderated = 'm',
M_InviteOnly = 'i',
M_NoMessages = 'n',
M_OpTopic = 't',
M_Limit = 'l',
M_Key = 'k',
M_Op = 'o',
M_Voice = 'v',
M_Ban = 'b',
M_Except = 'e'
} EModes;
CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig,
CConfig* pConfig = nullptr);
~CChan();
CChan(const CChan&) = delete;
CChan& operator=(const CChan&) = delete;
void Reset();
CConfig ToConfig() const;
void Clone(CChan& chan);
void Cycle() const;
void JoinUser(const CString& sKey = "");
void AttachUser(CClient* pClient = nullptr);
void DetachUser();
void OnWho(const CString& sNick, const CString& sIdent,
const CString& sHost);
// Modes
void SetModes(const CString& s);
void ModeChange(const CString& sModes, const CNick* OpNick = nullptr);
bool AddMode(unsigned char uMode, const CString& sArg);
bool RemMode(unsigned char uMode);
CString GetModeString() const;
CString GetModeArg(CString& sArgs) const;
CString GetModeForNames() const;
// !Modes
// Nicks
void ClearNicks();
const CNick* FindNick(const CString& sNick) const;
CNick* FindNick(const CString& sNick);
int AddNicks(const CString& sNicks);
bool AddNick(const CString& sNick);
bool RemNick(const CString& sNick);
bool ChangeNick(const CString& sOldNick, const CString& sNewNick);
// !Nicks
// Buffer
const CBuffer& GetBuffer() const { return m_Buffer; }
unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
bool SetBufferCount(unsigned int u, bool bForce = false) {
m_bHasBufferCountSet = true;
return m_Buffer.SetLineCount(u, bForce);
}
void InheritBufferCount(unsigned int u, bool bForce = false) {
if (!m_bHasBufferCountSet) m_Buffer.SetLineCount(u, bForce);
}
void ResetBufferCount();
size_t AddBuffer(const CMessage& Format, const CString& sText = "") {
return m_Buffer.AddLine(Format, sText);
}
/// @deprecated
size_t AddBuffer(const CString& sFormat, const CString& sText = "",
const timeval* ts = nullptr,
const MCString& mssTags = MCString::EmptyMap) {
return m_Buffer.AddLine(sFormat, sText, ts, mssTags);
}
void ClearBuffer() { m_Buffer.Clear(); }
void SendBuffer(CClient* pClient);
void SendBuffer(CClient* pClient, const CBuffer& Buffer);
// !Buffer
// m_Nick wrappers
CString GetPermStr() const { return m_Nick.GetPermStr(); }
bool HasPerm(unsigned char uPerm) const { return m_Nick.HasPerm(uPerm); }
bool AddPerm(unsigned char uPerm) { return m_Nick.AddPerm(uPerm); }
bool RemPerm(unsigned char uPerm) { return m_Nick.RemPerm(uPerm); }
// !wrappers
// Setters
void SetModeKnown(bool b) { m_bModeKnown = b; }
void SetIsOn(bool b) {
m_bIsOn = b;
if (!b) {
Reset();
}
}
void SetKey(const CString& s);
void SetTopic(const CString& s) { m_sTopic = s; }
void SetTopicOwner(const CString& s) { m_sTopicOwner = s; }
void SetTopicDate(unsigned long u) { m_ulTopicDate = u; }
void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
void SetAutoClearChanBuffer(bool b);
void InheritAutoClearChanBuffer(bool b);
void ResetAutoClearChanBuffer();
void SetDetached(bool b = true) { m_bDetached = b; }
void SetInConfig(bool b);
void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
void Disable() { m_bDisabled = true; }
void Enable();
void IncJoinTries() { m_uJoinTries++; }
void ResetJoinTries() { m_uJoinTries = 0; }
// !Setters
// Getters
CIRCNetwork* GetNetwork() const { return m_pNetwork; }
bool IsModeKnown() const { return m_bModeKnown; }
bool HasMode(unsigned char uMode) const;
CString GetOptions() const;
CString GetModeArg(unsigned char uMode) const;
std::map<char, unsigned int> GetPermCounts() const;
bool IsOn() const { return m_bIsOn; }
const CString& GetName() const { return m_sName; }
const std::map<unsigned char, CString>& GetModes() const {
return m_musModes;
}
const CString& GetKey() const { return m_sKey; }
const CString& GetTopic() const { return m_sTopic; }
const CString& GetTopicOwner() const { return m_sTopicOwner; }
unsigned long GetTopicDate() const { return m_ulTopicDate; }
const CString& GetDefaultModes() const { return m_sDefaultModes; }
const std::map<CString, CNick>& GetNicks() const { return m_msNicks; }
size_t GetNickCount() const { return m_msNicks.size(); }
bool AutoClearChanBuffer() const { return m_bAutoClearChanBuffer; }
bool IsDetached() const { return m_bDetached; }
bool InConfig() const { return m_bInConfig; }
unsigned long GetCreationDate() const { return m_ulCreationDate; }
bool IsDisabled() const { return m_bDisabled; }
unsigned int GetJoinTries() const { return m_uJoinTries; }
bool HasBufferCountSet() const { return m_bHasBufferCountSet; }
bool HasAutoClearChanBufferSet() const {
return m_bHasAutoClearChanBufferSet;
}
// !Getters
private:
protected:
bool m_bDetached;
bool m_bIsOn;
bool m_bAutoClearChanBuffer;
bool m_bInConfig;
bool m_bDisabled;
bool m_bHasBufferCountSet;
bool m_bHasAutoClearChanBufferSet;
CString m_sName;
CString m_sKey;
CString m_sTopic;
CString m_sTopicOwner;
unsigned long m_ulTopicDate;
unsigned long m_ulCreationDate;
CIRCNetwork* m_pNetwork;
CNick m_Nick;
unsigned int m_uJoinTries;
CString m_sDefaultModes;
std::map<CString, CNick> m_msNicks; // Todo: make this caseless (irc style)
CBuffer m_Buffer;
bool m_bModeKnown;
std::map<unsigned char, CString> m_musModes;
bool m_bDetached;
bool m_bIsOn;
bool m_bAutoClearChanBuffer;
bool m_bInConfig;
bool m_bDisabled;
bool m_bHasBufferCountSet;
bool m_bHasAutoClearChanBufferSet;
CString m_sName;
CString m_sKey;
CString m_sTopic;
CString m_sTopicOwner;
unsigned long m_ulTopicDate;
unsigned long m_ulCreationDate;
CIRCNetwork* m_pNetwork;
CNick m_Nick;
unsigned int m_uJoinTries;
CString m_sDefaultModes;
std::map<CString, CNick> m_msNicks; // Todo: make this caseless (irc style)
CBuffer m_Buffer;
bool m_bModeKnown;
std::map<unsigned char, CString> m_musModes;
};
#endif // !ZNC_CHAN_H

@ -36,162 +36,162 @@ class CChan;
class CAuthBase {
public:
CAuthBase(const CString& sUsername, const CString& sPassword,
CZNCSock* pSock)
: m_sUsername(sUsername), m_sPassword(sPassword), m_pSock(pSock) {}
CAuthBase(const CString& sUsername, const CString& sPassword,
CZNCSock* pSock)
: m_sUsername(sUsername), m_sPassword(sPassword), m_pSock(pSock) {}
virtual ~CAuthBase() {}
virtual ~CAuthBase() {}
CAuthBase(const CAuthBase&) = delete;
CAuthBase& operator=(const CAuthBase&) = delete;
CAuthBase(const CAuthBase&) = delete;
CAuthBase& operator=(const CAuthBase&) = delete;
virtual void SetLoginInfo(const CString& sUsername,
const CString& sPassword, CZNCSock* pSock) {
m_sUsername = sUsername;
m_sPassword = sPassword;
m_pSock = pSock;
}
virtual void SetLoginInfo(const CString& sUsername,
const CString& sPassword, CZNCSock* pSock) {
m_sUsername = sUsername;
m_sPassword = sPassword;
m_pSock = pSock;
}
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
const CString& GetUsername() const { return m_sUsername; }
const CString& GetPassword() const { return m_sPassword; }
Csock* GetSocket() const { return m_pSock; }
CString GetRemoteIP() const;
const CString& GetUsername() const { return m_sUsername; }
const CString& GetPassword() const { return m_sPassword; }
Csock* GetSocket() const { return m_pSock; }
CString GetRemoteIP() const;
// Invalidate this CAuthBase instance which means it will no longer use
// m_pSock and AcceptLogin() or RefusedLogin() will have no effect.
virtual void Invalidate();
// Invalidate this CAuthBase instance which means it will no longer use
// m_pSock and AcceptLogin() or RefusedLogin() will have no effect.
virtual void Invalidate();
protected:
virtual void AcceptedLogin(CUser& User) = 0;
virtual void RefusedLogin(const CString& sReason) = 0;
virtual void AcceptedLogin(CUser& User) = 0;
virtual void RefusedLogin(const CString& sReason) = 0;
private:
CString m_sUsername;
CString m_sPassword;
CZNCSock* m_pSock;
CString m_sUsername;
CString m_sPassword;
CZNCSock* m_pSock;
};
class CClientAuth : public CAuthBase {
public:
CClientAuth(CClient* pClient, const CString& sUsername,
const CString& sPassword);
virtual ~CClientAuth() {}
CClientAuth(CClient* pClient, const CString& sUsername,
const CString& sPassword);
virtual ~CClientAuth() {}
CClientAuth(const CClientAuth&) = delete;
CClientAuth& operator=(const CClientAuth&) = delete;
CClientAuth(const CClientAuth&) = delete;
CClientAuth& operator=(const CClientAuth&) = delete;
void Invalidate() override {
m_pClient = nullptr;
CAuthBase::Invalidate();
}
void AcceptedLogin(CUser& User) override;
void RefusedLogin(const CString& sReason) override;
void Invalidate() override {
m_pClient = nullptr;
CAuthBase::Invalidate();
}
void AcceptedLogin(CUser& User) override;
void RefusedLogin(const CString& sReason) override;
private:
protected:
CClient* m_pClient;
CClient* m_pClient;
};
class CClient : public CIRCSocket {
public:
CClient()
: CIRCSocket(),
m_bGotPass(false),
m_bGotNick(false),
m_bGotUser(false),
m_bInCap(false),
m_bCapNotify(false),
m_bAwayNotify(false),
m_bAccountNotify(false),
m_bExtendedJoin(false),
m_bNamesx(false),
m_bUHNames(false),
m_bAway(false),
m_bServerTime(false),
m_bBatch(false),
m_bEchoMessage(false),
m_bSelfMessage(false),
m_bPlaybackActive(false),
m_pUser(nullptr),
m_pNetwork(nullptr),
m_sNick("unknown-nick"),
m_sPass(""),
m_sUser(""),
m_sNetwork(""),
m_sIdentifier(""),
m_spAuth(),
m_ssAcceptedCaps(),
m_mCoreCaps({
{"multi-prefix",
{false, [this](bool bVal) { m_bNamesx = bVal; }}},
{"userhost-in-names",
{false, [this](bool bVal) { m_bUHNames = bVal; }}},
{"echo-message",
{false, [this](bool bVal) { m_bEchoMessage = bVal; }}},
{"server-time",
{false, [this](bool bVal) { m_bServerTime = bVal; }}},
{"batch", {false, [this](bool bVal) { m_bBatch = bVal; }}},
{"cap-notify",
{false, [this](bool bVal) { m_bCapNotify = bVal; }}},
{"away-notify",
{true, [this](bool bVal) { m_bAwayNotify = bVal; }}},
{"account-notify",
{true, [this](bool bVal) { m_bAccountNotify = bVal; }}},
{"extended-join",
{true, [this](bool bVal) { m_bExtendedJoin = bVal; }}},
}) {
EnableReadLine();
// RFC says a line can have 512 chars max, but we are
// a little more gentle ;)
SetMaxBufferThreshold(1024);
// For compatibility with older clients
m_mCoreCaps["znc.in/server-time-iso"] = m_mCoreCaps["server-time"];
m_mCoreCaps["znc.in/batch"] = m_mCoreCaps["batch"];
m_mCoreCaps["znc.in/self-message"] = {
false, [this](bool bVal) { m_bSelfMessage = bVal; }};
}
virtual ~CClient();
CClient(const CClient&) = delete;
CClient& operator=(const CClient&) = delete;
void SendRequiredPasswordNotice();
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
CString GetNick(bool bAllowIRCNick = true) const;
CString GetNickMask() const;
CString GetIdentifier() const { return m_sIdentifier; }
bool HasCapNotify() const { return m_bCapNotify; }
bool HasAwayNotify() const { return m_bAwayNotify; }
bool HasAccountNotify() const { return m_bAccountNotify; }
bool HasExtendedJoin() const { return m_bExtendedJoin; }
bool HasNamesx() const { return m_bNamesx; }
bool HasUHNames() const { return m_bUHNames; }
bool IsAway() const { return m_bAway; }
bool HasServerTime() const { return m_bServerTime; }
bool HasBatch() const { return m_bBatch; }
bool HasEchoMessage() const { return m_bEchoMessage; }
bool HasSelfMessage() const { return m_bSelfMessage; }
static bool IsValidIdentifier(const CString& sIdentifier);
void UserCommand(CString& sLine);
void UserPortCommand(CString& sLine);
void StatusCTCP(const CString& sCommand);
void BouncedOff();
bool IsAttached() const { return m_pUser != nullptr; }
bool IsPlaybackActive() const { return m_bPlaybackActive; }
void SetPlaybackActive(bool bActive) { m_bPlaybackActive = bActive; }
void PutIRC(const CString& sLine);
/** Sends a raw data line to the client.
CClient()
: CIRCSocket(),
m_bGotPass(false),
m_bGotNick(false),
m_bGotUser(false),
m_bInCap(false),
m_bCapNotify(false),
m_bAwayNotify(false),
m_bAccountNotify(false),
m_bExtendedJoin(false),
m_bNamesx(false),
m_bUHNames(false),
m_bAway(false),
m_bServerTime(false),
m_bBatch(false),
m_bEchoMessage(false),
m_bSelfMessage(false),
m_bPlaybackActive(false),
m_pUser(nullptr),
m_pNetwork(nullptr),
m_sNick("unknown-nick"),
m_sPass(""),
m_sUser(""),
m_sNetwork(""),
m_sIdentifier(""),
m_spAuth(),
m_ssAcceptedCaps(),
m_mCoreCaps({
{"multi-prefix",
{false, [this](bool bVal) { m_bNamesx = bVal; }}},
{"userhost-in-names",
{false, [this](bool bVal) { m_bUHNames = bVal; }}},
{"echo-message",
{false, [this](bool bVal) { m_bEchoMessage = bVal; }}},
{"server-time",
{false, [this](bool bVal) { m_bServerTime = bVal; }}},
{"batch", {false, [this](bool bVal) { m_bBatch = bVal; }}},
{"cap-notify",
{false, [this](bool bVal) { m_bCapNotify = bVal; }}},
{"away-notify",
{true, [this](bool bVal) { m_bAwayNotify = bVal; }}},
{"account-notify",
{true, [this](bool bVal) { m_bAccountNotify = bVal; }}},
{"extended-join",
{true, [this](bool bVal) { m_bExtendedJoin = bVal; }}},
}) {
EnableReadLine();
// RFC says a line can have 512 chars max, but we are
// a little more gentle ;)
SetMaxBufferThreshold(1024);
// For compatibility with older clients
m_mCoreCaps["znc.in/server-time-iso"] = m_mCoreCaps["server-time"];
m_mCoreCaps["znc.in/batch"] = m_mCoreCaps["batch"];
m_mCoreCaps["znc.in/self-message"] = {
false, [this](bool bVal) { m_bSelfMessage = bVal; }};
}
virtual ~CClient();
CClient(const CClient&) = delete;
CClient& operator=(const CClient&) = delete;
void SendRequiredPasswordNotice();
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
CString GetNick(bool bAllowIRCNick = true) const;
CString GetNickMask() const;
CString GetIdentifier() const { return m_sIdentifier; }
bool HasCapNotify() const { return m_bCapNotify; }
bool HasAwayNotify() const { return m_bAwayNotify; }
bool HasAccountNotify() const { return m_bAccountNotify; }
bool HasExtendedJoin() const { return m_bExtendedJoin; }
bool HasNamesx() const { return m_bNamesx; }
bool HasUHNames() const { return m_bUHNames; }
bool IsAway() const { return m_bAway; }
bool HasServerTime() const { return m_bServerTime; }
bool HasBatch() const { return m_bBatch; }
bool HasEchoMessage() const { return m_bEchoMessage; }
bool HasSelfMessage() const { return m_bSelfMessage; }
static bool IsValidIdentifier(const CString& sIdentifier);
void UserCommand(CString& sLine);
void UserPortCommand(CString& sLine);
void StatusCTCP(const CString& sCommand);
void BouncedOff();
bool IsAttached() const { return m_pUser != nullptr; }
bool IsPlaybackActive() const { return m_bPlaybackActive; }
void SetPlaybackActive(bool bActive) { m_bPlaybackActive = bActive; }
void PutIRC(const CString& sLine);
/** Sends a raw data line to the client.
* @param sLine The line to be sent.
*
* The line is first passed \e unmodified to the \ref CModule::OnSendToClient()
@ -200,8 +200,8 @@ class CClient : public CIRCSocket {
* These lines appear in the debug output in the following syntax:
* \code [time] (user/network) ZNC -> CLI [line] \endcode
*/
void PutClient(const CString& sLine);
/** Sends a message to the client.
void PutClient(const CString& sLine);
/** Sends a message to the client.
* @param Message The message to be sent.
* @note Only known and compatible messages and tags are sent.
* @return \c true if the message was sent, or \c false if it was ignored.
@ -247,105 +247,105 @@ class CClient : public CIRCSocket {
* pClient->PutClient(Message.ToString());
* \endcode
*/
bool PutClient(const CMessage& Message);
unsigned int PutStatus(const CTable& table);
void PutStatus(const CString& sLine);
void PutStatusNotice(const CString& sLine);
void PutModule(const CString& sModule, const CString& sLine);
void PutModNotice(const CString& sModule, const CString& sLine);
bool IsCapEnabled(const CString& sCap) const {
return 1 == m_ssAcceptedCaps.count(sCap);
}
void NotifyServerDependentCaps(const SCString& ssCaps);
void ClearServerDependentCaps();
void ReadLine(const CString& sData) override;
bool SendMotd();
void HelpUser(const CString& sFilter = "");
void AuthUser();
void Connected() override;
void Timeout() override;
void Disconnected() override;
void ConnectionRefused() override;
void ReachedMaxBuffer() override;
void SetNick(const CString& s);
void SetAway(bool bAway) { m_bAway = bAway; }
CUser* GetUser() const { return m_pUser; }
void SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect = true,
bool bReconnect = true);
CIRCNetwork* GetNetwork() const { return m_pNetwork; }
const std::vector<CClient*>& GetClients() const;
const CIRCSock* GetIRCSock() const;
CIRCSock* GetIRCSock();
CString GetFullName() const;
bool PutClient(const CMessage& Message);
unsigned int PutStatus(const CTable& table);
void PutStatus(const CString& sLine);
void PutStatusNotice(const CString& sLine);
void PutModule(const CString& sModule, const CString& sLine);
void PutModNotice(const CString& sModule, const CString& sLine);
bool IsCapEnabled(const CString& sCap) const {
return 1 == m_ssAcceptedCaps.count(sCap);
}
void NotifyServerDependentCaps(const SCString& ssCaps);
void ClearServerDependentCaps();
void ReadLine(const CString& sData) override;
bool SendMotd();
void HelpUser(const CString& sFilter = "");
void AuthUser();
void Connected() override;
void Timeout() override;
void Disconnected() override;
void ConnectionRefused() override;
void ReachedMaxBuffer() override;
void SetNick(const CString& s);
void SetAway(bool bAway) { m_bAway = bAway; }
CUser* GetUser() const { return m_pUser; }
void SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect = true,
bool bReconnect = true);
CIRCNetwork* GetNetwork() const { return m_pNetwork; }
const std::vector<CClient*>& GetClients() const;
const CIRCSock* GetIRCSock() const;
CIRCSock* GetIRCSock();
CString GetFullName() const;
private:
void HandleCap(const CMessage& Message);
void RespondCap(const CString& sResponse);
void ParsePass(const CString& sAuthLine);
void ParseUser(const CString& sAuthLine);
void ParseIdentifier(const CString& sAuthLine);
template <typename T>
void AddBuffer(const T& Message);
void EchoMessage(const CMessage& Message);
std::set<CChan*> MatchChans(const CString& sPatterns) const;
unsigned int AttachChans(const std::set<CChan*>& sChans);
unsigned int DetachChans(const std::set<CChan*>& sChans);
bool OnActionMessage(CActionMessage& Message);
bool OnCTCPMessage(CCTCPMessage& Message);
bool OnJoinMessage(CJoinMessage& Message);
bool OnModeMessage(CModeMessage& Message);
bool OnNoticeMessage(CNoticeMessage& Message);
bool OnPartMessage(CPartMessage& Message);
bool OnPingMessage(CMessage& Message);
bool OnPongMessage(CMessage& Message);
bool OnQuitMessage(CQuitMessage& Message);
bool OnTextMessage(CTextMessage& Message);
bool OnTopicMessage(CTopicMessage& Message);
bool OnOtherMessage(CMessage& Message);
void HandleCap(const CMessage& Message);
void RespondCap(const CString& sResponse);
void ParsePass(const CString& sAuthLine);
void ParseUser(const CString& sAuthLine);
void ParseIdentifier(const CString& sAuthLine);
template <typename T>
void AddBuffer(const T& Message);
void EchoMessage(const CMessage& Message);
std::set<CChan*> MatchChans(const CString& sPatterns) const;
unsigned int AttachChans(const std::set<CChan*>& sChans);
unsigned int DetachChans(const std::set<CChan*>& sChans);
bool OnActionMessage(CActionMessage& Message);
bool OnCTCPMessage(CCTCPMessage& Message);
bool OnJoinMessage(CJoinMessage& Message);
bool OnModeMessage(CModeMessage& Message);
bool OnNoticeMessage(CNoticeMessage& Message);
bool OnPartMessage(CPartMessage& Message);
bool OnPingMessage(CMessage& Message);
bool OnPongMessage(CMessage& Message);
bool OnQuitMessage(CQuitMessage& Message);
bool OnTextMessage(CTextMessage& Message);
bool OnTopicMessage(CTopicMessage& Message);
bool OnOtherMessage(CMessage& Message);
protected:
bool m_bGotPass;
bool m_bGotNick;
bool m_bGotUser;
bool m_bInCap;
bool m_bCapNotify;
bool m_bAwayNotify;
bool m_bAccountNotify;
bool m_bExtendedJoin;
bool m_bNamesx;
bool m_bUHNames;
bool m_bAway;
bool m_bServerTime;
bool m_bBatch;
bool m_bEchoMessage;
bool m_bSelfMessage;
bool m_bPlaybackActive;
CUser* m_pUser;
CIRCNetwork* m_pNetwork;
CString m_sNick;
CString m_sPass;
CString m_sUser;
CString m_sNetwork;
CString m_sIdentifier;
std::shared_ptr<CAuthBase> m_spAuth;
SCString m_ssAcceptedCaps;
// The capabilities supported by the ZNC core - capability names mapped
// to a pair which contains a bool describing whether the capability is
// server-dependent, and a capability value change handler.
std::map<CString, std::pair<bool, std::function<void(bool bVal)>>>
m_mCoreCaps;
// A subset of CIRCSock::GetAcceptedCaps(), the caps that can be listed
// in CAP LS and may be notified to the client with CAP NEW (cap-notify).
SCString m_ssServerDependentCaps;
friend class ClientTest;
bool m_bGotPass;
bool m_bGotNick;
bool m_bGotUser;
bool m_bInCap;
bool m_bCapNotify;
bool m_bAwayNotify;
bool m_bAccountNotify;
bool m_bExtendedJoin;
bool m_bNamesx;
bool m_bUHNames;
bool m_bAway;
bool m_bServerTime;
bool m_bBatch;
bool m_bEchoMessage;
bool m_bSelfMessage;
bool m_bPlaybackActive;
CUser* m_pUser;
CIRCNetwork* m_pNetwork;
CString m_sNick;
CString m_sPass;
CString m_sUser;
CString m_sNetwork;
CString m_sIdentifier;
std::shared_ptr<CAuthBase> m_spAuth;
SCString m_ssAcceptedCaps;
// The capabilities supported by the ZNC core - capability names mapped
// to a pair which contains a bool describing whether the capability is
// server-dependent, and a capability value change handler.
std::map<CString, std::pair<bool, std::function<void(bool bVal)>>>
m_mCoreCaps;
// A subset of CIRCSock::GetAcceptedCaps(), the caps that can be listed
// in CAP LS and may be notified to the client with CAP NEW (cap-notify).
SCString m_ssServerDependentCaps;
friend class ClientTest;
};
#endif // !ZNC_CLIENT_H

@ -24,150 +24,150 @@ class CFile;
class CConfig;
struct CConfigEntry {
CConfigEntry();
CConfigEntry(const CConfig& Config);
CConfigEntry(const CConfigEntry& other);
~CConfigEntry();
CConfigEntry& operator=(const CConfigEntry& other);
CConfigEntry();
CConfigEntry(const CConfig& Config);
CConfigEntry(const CConfigEntry& other);
~CConfigEntry();
CConfigEntry& operator=(const CConfigEntry& other);
CConfig* m_pSubConfig;
CConfig* m_pSubConfig;
};
class CConfig {
public:
CConfig() : m_ConfigEntries(), m_SubConfigs() {}
typedef std::map<CString, VCString> EntryMap;
typedef std::map<CString, CConfigEntry> SubConfig;
typedef std::map<CString, SubConfig> SubConfigMap;
typedef EntryMap::const_iterator EntryMapIterator;
typedef SubConfigMap::const_iterator SubConfigMapIterator;
EntryMapIterator BeginEntries() const { return m_ConfigEntries.begin(); }
EntryMapIterator EndEntries() const { return m_ConfigEntries.end(); }
SubConfigMapIterator BeginSubConfigs() const {
return m_SubConfigs.begin();
}
SubConfigMapIterator EndSubConfigs() const { return m_SubConfigs.end(); }
void AddKeyValuePair(const CString& sName, const CString& sValue) {
if (sName.empty() || sValue.empty()) {
return;
}
m_ConfigEntries[sName].push_back(sValue);
}
bool AddSubConfig(const CString& sTag, const CString& sName,
CConfig Config) {
SubConfig& conf = m_SubConfigs[sTag];
SubConfig::const_iterator it = conf.find(sName);
if (it != conf.end()) {
return false;
}
conf[sName] = Config;
return true;
}
bool FindStringVector(const CString& sName, VCString& vsList,
bool bErase = true) {
EntryMap::iterator it = m_ConfigEntries.find(sName);
vsList.clear();
if (it == m_ConfigEntries.end()) return false;
vsList = it->second;
if (bErase) {
m_ConfigEntries.erase(it);
}
return true;
}
bool FindStringEntry(const CString& sName, CString& sRes,
const CString& sDefault = "") {
EntryMap::iterator it = m_ConfigEntries.find(sName);
sRes = sDefault;
if (it == m_ConfigEntries.end() || it->second.empty()) return false;
sRes = it->second.front();
it->second.erase(it->second.begin());
if (it->second.empty()) m_ConfigEntries.erase(it);
return true;
}
bool FindBoolEntry(const CString& sName, bool& bRes,
bool bDefault = false) {
CString s;
if (FindStringEntry(sName, s)) {
bRes = s.ToBool();
return true;
}
bRes = bDefault;
return false;
}
bool FindUIntEntry(const CString& sName, unsigned int& uRes,
unsigned int uDefault = 0) {
CString s;
if (FindStringEntry(sName, s)) {
uRes = s.ToUInt();
return true;
}
uRes = uDefault;
return false;
}
bool FindUShortEntry(const CString& sName, unsigned short& uRes,
unsigned short uDefault = 0) {
CString s;
if (FindStringEntry(sName, s)) {
uRes = s.ToUShort();
return true;
}
uRes = uDefault;
return false;
}
bool FindDoubleEntry(const CString& sName, double& fRes,
double fDefault = 0) {
CString s;
if (FindStringEntry(sName, s)) {
fRes = s.ToDouble();
return true;
}
fRes = fDefault;
return false;
}
bool FindSubConfig(const CString& sName, SubConfig& Config,
bool bErase = true) {
SubConfigMap::iterator it = m_SubConfigs.find(sName);
if (it == m_SubConfigs.end()) {
Config.clear();
return false;
}
Config = it->second;
if (bErase) {
m_SubConfigs.erase(it);
}
return true;
}
bool empty() const {
return m_ConfigEntries.empty() && m_SubConfigs.empty();
}
bool Parse(CFile& file, CString& sErrorMsg);
void Write(CFile& file, unsigned int iIndentation = 0);
CConfig() : m_ConfigEntries(), m_SubConfigs() {}
typedef std::map<CString, VCString> EntryMap;
typedef std::map<CString, CConfigEntry> SubConfig;
typedef std::map<CString, SubConfig> SubConfigMap;
typedef EntryMap::const_iterator EntryMapIterator;
typedef SubConfigMap::const_iterator SubConfigMapIterator;
EntryMapIterator BeginEntries() const { return m_ConfigEntries.begin(); }
EntryMapIterator EndEntries() const { return m_ConfigEntries.end(); }
SubConfigMapIterator BeginSubConfigs() const {
return m_SubConfigs.begin();
}
SubConfigMapIterator EndSubConfigs() const { return m_SubConfigs.end(); }
void AddKeyValuePair(const CString& sName, const CString& sValue) {
if (sName.empty() || sValue.empty()) {
return;
}
m_ConfigEntries[sName].push_back(sValue);
}
bool AddSubConfig(const CString& sTag, const CString& sName,
CConfig Config) {
SubConfig& conf = m_SubConfigs[sTag];
SubConfig::const_iterator it = conf.find(sName);
if (it != conf.end()) {
return false;
}
conf[sName] = Config;
return true;
}
bool FindStringVector(const CString& sName, VCString& vsList,
bool bErase = true) {
EntryMap::iterator it = m_ConfigEntries.find(sName);
vsList.clear();
if (it == m_ConfigEntries.end()) return false;
vsList = it->second;
if (bErase) {
m_ConfigEntries.erase(it);
}
return true;
}
bool FindStringEntry(const CString& sName, CString& sRes,
const CString& sDefault = "") {
EntryMap::iterator it = m_ConfigEntries.find(sName);
sRes = sDefault;
if (it == m_ConfigEntries.end() || it->second.empty()) return false;
sRes = it->second.front();
it->second.erase(it->second.begin());
if (it->second.empty()) m_ConfigEntries.erase(it);
return true;
}
bool FindBoolEntry(const CString& sName, bool& bRes,
bool bDefault = false) {
CString s;
if (FindStringEntry(sName, s)) {
bRes = s.ToBool();
return true;
}
bRes = bDefault;
return false;
}
bool FindUIntEntry(const CString& sName, unsigned int& uRes,
unsigned int uDefault = 0) {
CString s;
if (FindStringEntry(sName, s)) {
uRes = s.ToUInt();
return true;
}
uRes = uDefault;
return false;
}
bool FindUShortEntry(const CString& sName, unsigned short& uRes,
unsigned short uDefault = 0) {
CString s;
if (FindStringEntry(sName, s)) {
uRes = s.ToUShort();
return true;
}
uRes = uDefault;
return false;
}
bool FindDoubleEntry(const CString& sName, double& fRes,
double fDefault = 0) {
CString s;
if (FindStringEntry(sName, s)) {
fRes = s.ToDouble();
return true;
}
fRes = fDefault;
return false;
}
bool FindSubConfig(const CString& sName, SubConfig& Config,
bool bErase = true) {
SubConfigMap::iterator it = m_SubConfigs.find(sName);
if (it == m_SubConfigs.end()) {
Config.clear();
return false;
}
Config = it->second;
if (bErase) {
m_SubConfigs.erase(it);
}
return true;
}
bool empty() const {
return m_ConfigEntries.empty() && m_SubConfigs.empty();
}
bool Parse(CFile& file, CString& sErrorMsg);
void Write(CFile& file, unsigned int iIndentation = 0);
private:
EntryMap m_ConfigEntries;
SubConfigMap m_SubConfigs;
EntryMap m_ConfigEntries;
SubConfigMap m_SubConfigs;
};
#endif // !ZNC_CONFIG_H

@ -24,31 +24,31 @@
//! @author imaginos@imaginos.net
class CExecSock : public CZNCSock {
public:
CExecSock() : CZNCSock(0), m_iPid(-1) {}
CExecSock() : CZNCSock(0), m_iPid(-1) {}
int Execute(const CString& sExec) {
int iReadFD, iWriteFD;
m_iPid = popen2(iReadFD, iWriteFD, sExec);
if (m_iPid != -1) {
ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0");
}
return (m_iPid);
}
void Kill(int iSignal) {
kill(m_iPid, iSignal);
Close();
}
virtual ~CExecSock() {
close2(m_iPid, GetRSock(), GetWSock());
SetRSock(-1);
SetWSock(-1);
}
int Execute(const CString& sExec) {
int iReadFD, iWriteFD;
m_iPid = popen2(iReadFD, iWriteFD, sExec);
if (m_iPid != -1) {
ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0");
}
return (m_iPid);
</