ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IRCNetwork.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2018 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_IRCNETWORK_H
18 #define ZNC_IRCNETWORK_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/ZNCString.h>
22 #include <znc/Buffer.h>
23 #include <znc/Nick.h>
24 #include <znc/znc.h>
25 
26 class CModules;
27 class CUser;
28 class CFile;
29 class CConfig;
30 class CClient;
31 class CConfig;
32 class CChan;
33 class CQuery;
34 class CServer;
35 class CIRCSock;
36 class CIRCNetworkPingTimer;
37 class CIRCNetworkJoinTimer;
38 class CMessage;
39 
41  public:
42  static bool IsValidNetwork(const CString& sNetwork);
43 
44  CIRCNetwork(CUser* pUser, const CString& sName);
45  CIRCNetwork(CUser* pUser, const CIRCNetwork& Network);
46  ~CIRCNetwork();
47 
48  CIRCNetwork(const CIRCNetwork&) = delete;
49  CIRCNetwork& operator=(const CIRCNetwork&) = delete;
50 
51  void Clone(const CIRCNetwork& Network, bool bCloneName = true);
52 
53  CString GetNetworkPath() const;
54 
55  void DelServers();
56 
57  bool ParseConfig(CConfig* pConfig, CString& sError, bool bUpgrade = false);
58  CConfig ToConfig() const;
59 
60  void BounceAllClients();
61 
62  bool IsUserAttached() const { return !m_vClients.empty(); }
63  bool IsUserOnline() const;
64  void ClientConnected(CClient* pClient);
65  void ClientDisconnected(CClient* pClient);
66 
67  CUser* GetUser() const;
68  const CString& GetName() const;
69  bool IsNetworkAttached() const { return !m_vClients.empty(); }
70  const std::vector<CClient*>& GetClients() const { return m_vClients; }
71  std::vector<CClient*> FindClients(const CString& sIdentifier) const;
72 
73  void SetUser(CUser* pUser);
74  bool SetName(const CString& sName);
75 
76  // Modules
77  CModules& GetModules() { return *m_pModules; }
78  const CModules& GetModules() const { return *m_pModules; }
79  // !Modules
80 
81  bool PutUser(const CString& sLine, CClient* pClient = nullptr,
82  CClient* pSkipClient = nullptr);
83  bool PutUser(const CMessage& Message, CClient* pClient = nullptr,
84  CClient* pSkipClient = nullptr);
85  bool PutStatus(const CString& sLine, CClient* pClient = nullptr,
86  CClient* pSkipClient = nullptr);
87  bool PutModule(const CString& sModule, const CString& sLine,
88  CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
89 
90  const std::vector<CChan*>& GetChans() const;
91  CChan* FindChan(CString sName) const;
92  std::vector<CChan*> FindChans(const CString& sWild) const;
93  bool AddChan(CChan* pChan);
94  bool AddChan(const CString& sName, bool bInConfig);
95  bool DelChan(const CString& sName);
96  void JoinChans();
97  void JoinChans(std::set<CChan*>& sChans);
98 
99  const std::vector<CQuery*>& GetQueries() const;
100  CQuery* FindQuery(const CString& sName) const;
101  std::vector<CQuery*> FindQueries(const CString& sWild) const;
102  CQuery* AddQuery(const CString& sName);
103  bool DelQuery(const CString& sName);
104 
105  const CString& GetChanPrefixes() const { return m_sChanPrefixes; }
106  void SetChanPrefixes(const CString& s) { m_sChanPrefixes = s; }
107  bool IsChan(const CString& sChan) const;
108 
109  const std::vector<CServer*>& GetServers() const;
110  bool HasServers() const { return !m_vServers.empty(); }
111  CServer* FindServer(const CString& sName) const;
112  bool DelServer(const CString& sName, unsigned short uPort,
113  const CString& sPass);
114  bool AddServer(const CString& sName);
115  bool AddServer(const CString& sName, unsigned short uPort,
116  const CString& sPass = "", bool bSSL = false);
117  CServer* GetNextServer(bool bAdvance = true);
118  CServer* GetCurrentServer() const;
119  void SetIRCServer(const CString& s);
120  bool SetNextServer(const CServer* pServer);
121  bool IsLastServer() const;
122 
125  }
126  void AddTrustedFingerprint(const CString& sFP) {
129  }
130  void DelTrustedFingerprint(const CString& sFP) {
131  m_ssTrustedFingerprints.erase(sFP);
132  }
134 
135  void SetIRCConnectEnabled(bool b);
137 
139  const CIRCSock* GetIRCSock() const { return m_pIRCSock; }
140  const CString& GetIRCServer() const;
141  const CNick& GetIRCNick() const;
142  void SetIRCNick(const CNick& n);
143  CString GetCurNick() const;
144  bool IsIRCAway() const { return m_bIRCAway; }
145  void SetIRCAway(bool b) { m_bIRCAway = b; }
146 
147  bool Connect();
151  bool IsIRCConnected() const;
152  void SetIRCSocket(CIRCSock* pIRCSock);
153  void IRCConnected();
154  void IRCDisconnected();
155  void CheckIRCConnect();
156 
157  bool PutIRC(const CString& sLine);
158  bool PutIRC(const CMessage& Message);
159 
160  // Buffers
161  void AddRawBuffer(const CMessage& Format, const CString& sText = "") {
162  m_RawBuffer.AddLine(Format, sText);
163  }
164  void UpdateRawBuffer(const CString& sCommand, const CMessage& Format,
165  const CString& sText = "") {
166  m_RawBuffer.UpdateLine(sCommand, Format, sText);
167  }
168  void UpdateExactRawBuffer(const CMessage& Format,
169  const CString& sText = "") {
170  m_RawBuffer.UpdateExactLine(Format, sText);
171  }
173 
175  void AddRawBuffer(const CString& sFormat, const CString& sText = "") {
176  m_RawBuffer.AddLine(sFormat, sText);
177  }
179  void UpdateRawBuffer(const CString& sMatch, const CString& sFormat,
180  const CString& sText = "") {
181  m_RawBuffer.UpdateLine(sMatch, sFormat, sText);
182  }
184  void UpdateExactRawBuffer(const CString& sFormat,
185  const CString& sText = "") {
186  m_RawBuffer.UpdateExactLine(sFormat, sText);
187  }
188 
189  void AddMotdBuffer(const CMessage& Format, const CString& sText = "") {
190  m_MotdBuffer.AddLine(Format, sText);
191  }
192  void UpdateMotdBuffer(const CString& sCommand, const CMessage& Format,
193  const CString& sText = "") {
194  m_MotdBuffer.UpdateLine(sCommand, Format, sText);
195  }
197 
199  void AddMotdBuffer(const CString& sFormat, const CString& sText = "") {
200  m_MotdBuffer.AddLine(sFormat, sText);
201  }
203  void UpdateMotdBuffer(const CString& sMatch, const CString& sFormat,
204  const CString& sText = "") {
205  m_MotdBuffer.UpdateLine(sMatch, sFormat, sText);
206  }
207 
208  void AddNoticeBuffer(const CMessage& Format, const CString& sText = "") {
209  m_NoticeBuffer.AddLine(Format, sText);
210  }
211  void UpdateNoticeBuffer(const CString& sCommand, const CMessage& Format,
212  const CString& sText = "") {
213  m_NoticeBuffer.UpdateLine(sCommand, Format, sText);
214  }
216 
218  void AddNoticeBuffer(const CString& sFormat, const CString& sText = "") {
219  m_NoticeBuffer.AddLine(sFormat, sText);
220  }
222  void UpdateNoticeBuffer(const CString& sMatch, const CString& sFormat,
223  const CString& sText = "") {
224  m_NoticeBuffer.UpdateLine(sMatch, sFormat, sText);
225  }
226 
227  void ClearQueryBuffer();
228  // !Buffers
229 
230  // la
231  const CString& GetNick(const bool bAllowDefault = true) const;
232  const CString& GetAltNick(const bool bAllowDefault = true) const;
233  const CString& GetIdent(const bool bAllowDefault = true) const;
234  CString GetRealName() const;
235  const CString& GetBindHost() const;
236  const CString& GetEncoding() const;
237  CString GetQuitMsg() const;
238 
239  void SetNick(const CString& s);
240  void SetAltNick(const CString& s);
241  void SetIdent(const CString& s);
242  void SetRealName(const CString& s);
243  void SetBindHost(const CString& s);
244  void SetEncoding(const CString& s);
245  void SetQuitMsg(const CString& s);
246 
247  double GetFloodRate() const { return m_fFloodRate; }
248  unsigned short int GetFloodBurst() const { return m_uFloodBurst; }
249  void SetFloodRate(double fFloodRate) { m_fFloodRate = fFloodRate; }
250  void SetFloodBurst(unsigned short int uFloodBurst) {
251  m_uFloodBurst = uFloodBurst;
252  }
253 
254  unsigned short int GetJoinDelay() const { return m_uJoinDelay; }
255  void SetJoinDelay(unsigned short int uJoinDelay) {
256  m_uJoinDelay = uJoinDelay;
257  }
258 
259  void SetTrustAllCerts(const bool bTrustAll = false) {
260  m_bTrustAllCerts = bTrustAll;
261  }
262  bool GetTrustAllCerts() const { return m_bTrustAllCerts; }
263 
264  void SetTrustPKI(const bool bTrustPKI = true) { m_bTrustPKI = bTrustPKI; }
265  bool GetTrustPKI() const { return m_bTrustPKI; }
266 
267  unsigned long long BytesRead() const { return m_uBytesRead; }
268  unsigned long long BytesWritten() const { return m_uBytesWritten; }
269 
270  void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
271  void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
272 
273  CString ExpandString(const CString& sStr) const;
274  CString& ExpandString(const CString& sStr, CString& sRet) const;
275 
276  private:
277  bool JoinChan(CChan* pChan);
278  bool LoadModule(const CString& sModName, const CString& sArgs,
279  const CString& sNotice, CString& sError);
280 
281  protected:
284 
293 
295 
296  std::vector<CClient*> m_vClients;
297 
299 
300  std::vector<CChan*> m_vChans;
301  std::vector<CQuery*> m_vQueries;
302 
304 
309  std::vector<CServer*> m_vServers;
310  size_t m_uServerIdx;
311 
314 
315  double m_fFloodRate;
316  unsigned short int m_uFloodBurst;
317 
321 
322  CIRCNetworkPingTimer* m_pPingTimer;
323  CIRCNetworkJoinTimer* m_pJoinTimer;
324 
325  unsigned short int m_uJoinDelay;
326  unsigned long long m_uBytesRead;
327  unsigned long long m_uBytesWritten;
328 };
329 
330 #endif // !ZNC_IRCNETWORK_H
CString m_sNick
Definition: IRCNetwork.h:285
void SetIRCAway(bool b)
Definition: IRCNetwork.h:145
Definition: User.h:38
const CString & GetIRCServer() const
std::vector< CClient * > FindClients(const CString &sIdentifier) const
CString m_sRealName
Definition: IRCNetwork.h:288
const SCString & GetTrustedFingerprints() const
Definition: IRCNetwork.h:123
void ClearNoticeBuffer()
Definition: IRCNetwork.h:215
void SetBindHost(const CString &s)
size_type UpdateExactLine(const CMessage &Format, const CString &sText="")
bool DelQuery(const CString &sName)
void IRCConnected()
double GetFloodRate() const
Definition: IRCNetwork.h:247
void SetFloodBurst(unsigned short int uFloodBurst)
Definition: IRCNetwork.h:250
bool SetNextServer(const CServer *pServer)
CBuffer m_MotdBuffer
Definition: IRCNetwork.h:319
bool IsIRCConnected() const
This method will return whether the user is connected and authenticated to an IRC server...
void ClientDisconnected(CClient *pClient)
const CIRCSock * GetIRCSock() const
Definition: IRCNetwork.h:139
bool IsIRCAway() const
Definition: IRCNetwork.h:144
const CString & GetAltNick(const bool bAllowDefault=true) const
unsigned long long m_uBytesRead
Definition: IRCNetwork.h:326
CString m_sEncoding
Definition: IRCNetwork.h:290
CModules * m_pModules
Definition: IRCNetwork.h:294
unsigned long long BytesWritten() const
Definition: IRCNetwork.h:268
Definition: Client.h:99
void AddRawBuffer(const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:161
void SetFloodRate(double fFloodRate)
Definition: IRCNetwork.h:249
bool PutUser(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
unsigned short int m_uFloodBurst
Definition: IRCNetwork.h:316
void DelTrustedFingerprint(const CString &sFP)
Definition: IRCNetwork.h:130
void AddTrustedFingerprint(const CString &sFP)
Definition: IRCNetwork.h:126
void Clear()
Definition: Buffer.h:100
size_t m_uServerIdx
Index in m_vServers of our current server + 1.
Definition: IRCNetwork.h:310
CString GetQuitMsg() const
CBuffer m_RawBuffer
Definition: IRCNetwork.h:318
const CString & GetIdent(const bool bAllowDefault=true) const
const CString & GetChanPrefixes() const
Definition: IRCNetwork.h:105
CString m_sBindHost
Definition: IRCNetwork.h:289
double m_fFloodRate
Set to -1 to disable protection.
Definition: IRCNetwork.h:315
void SetTrustAllCerts(const bool bTrustAll=false)
Definition: IRCNetwork.h:259
std::vector< CChan * > m_vChans
Definition: IRCNetwork.h:300
void DelServers()
Definition: Modules.h:1389
CIRCNetworkJoinTimer * m_pJoinTimer
Definition: IRCNetwork.h:323
void BounceAllClients()
Definition: Nick.h:29
CNick m_IRCNick
Definition: IRCNetwork.h:312
void AddMotdBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:199
SCString m_ssTrustedFingerprints
Definition: IRCNetwork.h:292
const CModules & GetModules() const
Definition: IRCNetwork.h:78
void UpdateExactRawBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:184
CString m_sIdent
Definition: IRCNetwork.h:287
void AddNoticeBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:218
std::vector< CChan * > FindChans(const CString &sWild) const
std::set< CString > SCString
Definition: ZNCString.h:35
void IRCDisconnected()
CConfig ToConfig() const
bool SetName(const CString &sName)
bool IsLastServer() const
void UpdateMotdBuffer(const CString &sCommand, const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:192
bool m_bTrustAllCerts
Definition: IRCNetwork.h:306
CIRCSock * m_pIRCSock
Definition: IRCNetwork.h:298
const std::vector< CClient * > & GetClients() const
Definition: IRCNetwork.h:70
void UpdateMotdBuffer(const CString &sMatch, const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:203
CQuery * FindQuery(const CString &sName) const
void SetEncoding(const CString &s)
void ClearQueryBuffer()
void UpdateRawBuffer(const CString &sCommand, const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:164
unsigned long long m_uBytesWritten
Definition: IRCNetwork.h:327
CString m_sIRCServer
Definition: IRCNetwork.h:308
CIRCSock * GetIRCSock()
Definition: IRCNetwork.h:138
void AddNoticeBuffer(const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:208
unsigned long long BytesRead() const
Definition: IRCNetwork.h:267
CString m_sName
Definition: IRCNetwork.h:282
std::vector< CServer * > m_vServers
Definition: IRCNetwork.h:309
bool HasServers() const
Definition: IRCNetwork.h:110
Definition: FileUtils.h:30
Definition: IRCNetwork.h:40
bool PutIRC(const CString &sLine)
const CString & GetEncoding() const
unsigned short int m_uJoinDelay
Definition: IRCNetwork.h:325
bool IsNetworkAttached() const
Definition: IRCNetwork.h:69
bool GetIRCConnectEnabled() const
Definition: IRCNetwork.h:136
String class that is used inside ZNC.
Definition: ZNCString.h:68
void UpdateExactRawBuffer(const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:168
CString m_sAltNick
Definition: IRCNetwork.h:286
void SetNick(const CString &s)
void AddBytesWritten(unsigned long long u)
Definition: IRCNetwork.h:271
void SetQuitMsg(const CString &s)
bool m_bIRCAway
Definition: IRCNetwork.h:313
bool GetTrustPKI() const
Definition: IRCNetwork.h:265
CServer * FindServer(const CString &sName) const
CChan * FindChan(CString sName) const
void SetUser(CUser *pUser)
void ClearTrustedFingerprints()
Definition: IRCNetwork.h:133
CIRCNetwork & operator=(const CIRCNetwork &)=delete
std::vector< CQuery * > FindQueries(const CString &sWild) const
bool PutModule(const CString &sModule, const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
void SetChanPrefixes(const CString &s)
Definition: IRCNetwork.h:106
void SetIRCSocket(CIRCSock *pIRCSock)
bool IsUserOnline() const
CServer * GetCurrentServer() const
CUser * GetUser() const
void ClearRawBuffer()
Definition: IRCNetwork.h:172
void SetTrustPKI(const bool bTrustPKI=true)
Definition: IRCNetwork.h:264
unsigned short int GetFloodBurst() const
Definition: IRCNetwork.h:248
bool IsChan(const CString &sChan) const
CModules & GetModules()
Definition: IRCNetwork.h:77
CIRCNetworkPingTimer * m_pPingTimer
Definition: IRCNetwork.h:322
CString m_sChanPrefixes
Definition: IRCNetwork.h:303
const std::vector< CChan * > & GetChans() const
void SetAltNick(const CString &s)
CString m_sQuitMsg
Definition: IRCNetwork.h:291
Definition: Buffer.h:74
const CNick & GetIRCNick() const
std::vector< CQuery * > m_vQueries
Definition: IRCNetwork.h:301
const CString & GetName() const
bool DelServer(const CString &sName, unsigned short uPort, const CString &sPass)
unsigned short int GetJoinDelay() const
Definition: IRCNetwork.h:254
void ClientConnected(CClient *pClient)
bool Connect()
CBuffer m_NoticeBuffer
Definition: IRCNetwork.h:320
CString GetNetworkPath() const
void UpdateNoticeBuffer(const CString &sMatch, const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:222
CString ExpandString(const CString &sStr) const
bool IsUserAttached() const
Definition: IRCNetwork.h:62
void UpdateRawBuffer(const CString &sMatch, const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:179
void CheckIRCConnect()
void SetRealName(const CString &s)
void SetIRCNick(const CNick &n)
CIRCNetwork(CUser *pUser, const CString &sName)
CString Escape_n(EEscape eFrom, EEscape eTo) const
bool AddServer(const CString &sName)
CQuery * AddQuery(const CString &sName)
const std::vector< CServer * > & GetServers() const
void Clone(const CIRCNetwork &Network, bool bCloneName=true)
const std::vector< CQuery * > & GetQueries() const
bool m_bTrustPKI
Definition: IRCNetwork.h:307
void AddBytesRead(unsigned long long u)
Definition: IRCNetwork.h:270
void AddMotdBuffer(const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:189
std::vector< CClient * > m_vClients
Definition: IRCNetwork.h:296
CString GetCurNick() const
void SetIdent(const CString &s)
bool AddChan(CChan *pChan)
bool PutStatus(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
void ClearMotdBuffer()
Definition: IRCNetwork.h:196
Definition: Server.h:23
bool ParseConfig(CConfig *pConfig, CString &sError, bool bUpgrade=false)
bool GetTrustAllCerts() const
Definition: IRCNetwork.h:262
void SetIRCConnectEnabled(bool b)
void SetJoinDelay(unsigned short int uJoinDelay)
Definition: IRCNetwork.h:255
void AddRawBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:175
const CString & GetNick(const bool bAllowDefault=true) const
bool m_bIRCConnectEnabled
Definition: IRCNetwork.h:305
void SetIRCServer(const CString &s)
Definition: IRCSock.h:35
bool DelChan(const CString &sName)
const CString & GetBindHost() const
size_type AddLine(const CMessage &Format, const CString &sText="")
void UpdateNoticeBuffer(const CString &sCommand, const CMessage &Format, const CString &sText="")
Definition: IRCNetwork.h:211
CServer * GetNextServer(bool bAdvance=true)
Definition: Chan.h:35
CString GetRealName() const
Definition: Query.h:29
Definition: Config.h:36
Here is a small explanation of how messages on IRC work, and how you can use this class to get useful...
Definition: Message.h:63
Definition: ZNCString.h:78
void JoinChans()
size_type UpdateLine(const CString &sCommand, const CMessage &Format, const CString &sText="")
CUser * m_pUser
Definition: IRCNetwork.h:283
static bool IsValidNetwork(const CString &sNetwork)
Definition: Translation.h:104