Browse Source

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 :(
master
Alexey Sokolov 5 years ago
parent
commit
d185d6f22d
131 changed files with 39975 additions and 39976 deletions
  1. +0
    -1
      .clang-format
  2. +64
    -64
      include/znc/Buffer.h
  3. +170
    -170
      include/znc/Chan.h
  4. +230
    -230
      include/znc/Client.h
  5. +137
    -137
      include/znc/Config.h
  6. +21
    -21
      include/znc/ExecSock.h
  7. +217
    -217
      include/znc/FileUtils.h
  8. +115
    -115
      include/znc/HTTPSock.h
  9. +267
    -267
      include/znc/IRCNetwork.h
  10. +139
    -139
      include/znc/IRCSock.h
  11. +55
    -55
      include/znc/Listener.h
  12. +15
    -15
      include/znc/MD5.h
  13. +155
    -155
      include/znc/Message.h
  14. +826
    -826
      include/znc/Modules.h
  15. +34
    -34
      include/znc/Nick.h
  16. +29
    -29
      include/znc/Query.h
  17. +4
    -4
      include/znc/SHA256.h
  18. +13
    -13
      include/znc/Server.h
  19. +186
    -186
      include/znc/Socket.h
  20. +159
    -159
      include/znc/Template.h
  21. +61
    -61
      include/znc/Threads.h
  22. +222
    -222
      include/znc/User.h
  23. +166
    -166
      include/znc/Utils.h
  24. +107
    -107
      include/znc/WebModules.h
  25. +13
    -13
      include/znc/ZNCDebug.h
  26. +269
    -269
      include/znc/ZNCString.h
  27. +2
    -2
      include/znc/defines.h
  28. +90
    -90
      include/znc/main.h
  29. +223
    -223
      include/znc/znc.h
  30. +190
    -190
      modules/adminlog.cpp
  31. +352
    -352
      modules/alias.cpp
  32. +246
    -246
      modules/autoattach.cpp
  33. +199
    -199
      modules/autocycle.cpp
  34. +590
    -590
      modules/autoop.cpp
  35. +68
    -68
      modules/autoreply.cpp
  36. +306
    -306
      modules/autovoice.cpp
  37. +6
    -6
      modules/awaynick.cpp
  38. +455
    -455
      modules/awaystore.cpp
  39. +36
    -36
      modules/block_motd.cpp
  40. +180
    -180
      modules/blockuser.cpp
  41. +429
    -429
      modules/bouncedcc.cpp
  42. +83
    -83
      modules/buffextras.cpp
  43. +75
    -75
      modules/cert.cpp
  44. +253
    -253
      modules/certauth.cpp
  45. +54
    -54
      modules/chansaver.cpp
  46. +123
    -123
      modules/clearbufferonmsg.cpp
  47. +123
    -123
      modules/clientnotify.cpp
  48. +1509
    -1509
      modules/controlpanel.cpp
  49. +282
    -282
      modules/crypt.cpp
  50. +121
    -121
      modules/ctcpflood.cpp
  51. +194
    -194
      modules/cyrusauth.cpp
  52. +469
    -469
      modules/dcc.cpp
  53. +198
    -198
      modules/fail2ban.cpp
  54. +220
    -220
      modules/flooddetach.cpp
  55. +192
    -192
      modules/identfile.cpp
  56. +113
    -113
      modules/imapauth.cpp
  57. +163
    -163
      modules/keepnick.cpp
  58. +90
    -90
      modules/kickrejoin.cpp
  59. +115
    -115
      modules/lastseen.cpp
  60. +209
    -209
      modules/listsockets.cpp
  61. +333
    -333
      modules/log.cpp
  62. +6
    -6
      modules/missingmotd.cpp
  63. +280
    -280
      modules/modperl.cpp
  64. +163
    -163
      modules/modperl/module.h
  65. +48
    -48
      modules/modperl/pstring.h
  66. +431
    -431
      modules/modpython.cpp
  67. +235
    -235
      modules/modpython/module.h
  68. +14
    -14
      modules/modpython/ret.h
  69. +480
    -480
      modules/modtcl.cpp
  70. +86
    -86
      modules/modules_online.cpp
  71. +114
    -114
      modules/nickserv.cpp
  72. +200
    -200
      modules/notes.cpp
  73. +18
    -18
      modules/notify_connect.cpp
  74. +688
    -688
      modules/partyline.cpp
  75. +158
    -158
      modules/perform.cpp
  76. +637
    -637
      modules/q.cpp
  77. +13
    -13
      modules/raw.cpp
  78. +248
    -248
      modules/route_replies.cpp
  79. +259
    -259
      modules/sample.cpp
  80. +251
    -251
      modules/sasl.cpp
  81. +298
    -298
      modules/savebuff.cpp
  82. +375
    -375
      modules/schat.cpp
  83. +127
    -127
      modules/send_raw.cpp
  84. +94
    -94
      modules/shell.cpp
  85. +210
    -210
      modules/simple_away.cpp
  86. +212
    -212
      modules/stickychan.cpp
  87. +29
    -29
      modules/stripcontrols.cpp
  88. +709
    -709
      modules/watch.cpp
  89. +1951
    -1951
      modules/webadmin.cpp
  90. +90
    -90
      src/Buffer.cpp
  91. +521
    -521
      src/Chan.cpp
  92. +1087
    -1087
      src/Client.cpp
  93. +1836
    -1836
      src/ClientCommand.cpp
  94. +145
    -145
      src/Config.cpp
  95. +394
    -394
      src/FileUtils.cpp
  96. +530
    -530
      src/HTTPSock.cpp
  97. +1061
    -1061
      src/IRCNetwork.cpp
  98. +1221
    -1221
      src/IRCSock.cpp
  99. +108
    -108
      src/Listener.cpp
  100. +156
    -156
      src/MD5.cpp

+ 0
- 1
.clang-format View File

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

+ 64
- 64
include/znc/Buffer.h View File

@ -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

+ 170
- 170
include/znc/Chan.h View File

@ -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

+ 230
- 230
include/znc/Client.h View File

@ -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

+ 137
- 137
include/znc/Config.h View File

@ -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

+ 21
- 21
include/znc/ExecSock.h View File

@ -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);
}
void Kill(int iSignal) {
kill(m_iPid, iSignal);
Close();
}
virtual ~CExecSock() {
close2(m_iPid, GetRSock(), GetWSock());
SetRSock(-1);
SetWSock(-1);
}
int popen2(int& iReadFD, int& iWriteFD, const CString& sCommand);
void close2(int iPid, int iReadFD, int iWriteFD);
int popen2(int& iReadFD, int& iWriteFD, const CString& sCommand);
void close2(int iPid, int iReadFD, int iWriteFD);
private:
int m_iPid;
int m_iPid;
};
#endif // !ZNC_EXECSOCK_H

+ 217
- 217
include/znc/FileUtils.h View File

@ -29,235 +29,235 @@
class CFile {
public:
CFile();
CFile(const CString& sLongName);
~CFile();
enum EFileTypes {
FT_REGULAR,
FT_DIRECTORY,
FT_CHARACTER,
FT_BLOCK,
FT_FIFO,
FT_LINK,
FT_SOCK
};
void SetFileName(const CString& sLongName);
static bool IsReg(const CString& sLongName, bool bUseLstat = false);
static bool IsDir(const CString& sLongName, bool bUseLstat = false);
static bool IsChr(const CString& sLongName, bool bUseLstat = false);
static bool IsBlk(const CString& sLongName, bool bUseLstat = false);
static bool IsFifo(const CString& sLongName, bool bUseLstat = false);
static bool IsLnk(const CString& sLongName, bool bUseLstat = true);
static bool IsSock(const CString& sLongName, bool bUseLstat = false);
bool IsReg(bool bUseLstat = false) const;
bool IsDir(bool bUseLstat = false) const;
bool IsChr(bool bUseLstat = false) const;
bool IsBlk(bool bUseLstat = false) const;