ZNC trunk
Loading...
Searching...
No Matches
IRCSock.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2024 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_IRCSOCK_H
18#define ZNC_IRCSOCK_H
19
20#include <znc/zncconfig.h>
21#include <znc/Socket.h>
22#include <znc/Nick.h>
23#include <znc/Message.h>
24
25#include <deque>
26
27// Forward Declarations
28class CChan;
29class CUser;
30class CIRCNetwork;
31class CClient;
32// !Forward Declarations
33
34// TODO: This class needs new name
35class CIRCSock : public CIRCSocket {
36 public:
38 virtual ~CIRCSock();
39
40 CIRCSock(const CIRCSock&) = delete;
41 CIRCSock& operator=(const CIRCSock&) = delete;
42
43 typedef enum {
44 // These values must line up with their position in the CHANMODE
45 // argument to raw 005
47 HasArg = 1,
49 NoArg = 3
51
52 void ReadLine(const CString& sData) override;
53 void Connected() override;
54 void Disconnected() override;
55 void ConnectionRefused() override;
56 void SockError(int iErrno, const CString& sDescription) override;
57 void Timeout() override;
58 void ReachedMaxBuffer() override;
59#ifdef HAVE_LIBSSL
60 void SSLCertError(X509* pCert) override;
61#endif
71 void PutIRCRaw(const CString& sLine);
75 void PutIRC(const CString& sLine);
101 void PutIRC(const CMessage& Message);
102 void PutIRCQuick(const CString& sLine);
104 void Quit(const CString& sQuitMsg = "");
105
110 void PauseCap();
114 void ResumeCap();
115
116 bool IsTagEnabled(const CString& sTag) const {
117 return 1 == m_ssSupportedTags.count(sTag);
118 }
124 void SetTagSupport(const CString& sTag, bool bState);
125
126 // Setters
127 void SetPass(const CString& s) { m_sPass = s; }
128 // !Setters
129
130 // Getters
131 unsigned int GetMaxNickLen() const { return m_uMaxNickLen; }
132 EChanModeArgs GetModeType(char cMode) const;
133 char GetPermFromMode(char cMode) const;
134 char GetModeFromPerm(char cPerm) const;
135 const std::map<char, EChanModeArgs>& GetChanModes() const {
136 return m_mceChanModes;
137 }
138 bool IsPermChar(const char c) const {
139 return (c != '\0' && GetPerms().find(c) != CString::npos);
140 }
141 bool IsPermMode(const char c) const {
142 return (c != '\0' && GetPermModes().find(c) != CString::npos);
143 }
144 const CString& GetPerms() const { return m_sPerms; }
145 const CString& GetPermModes() const { return m_sPermModes; }
146 CString GetNickMask() const { return m_Nick.GetNickMask(); }
147 const CString& GetNick() const { return m_Nick.GetNick(); }
148 const CString& GetPass() const { return m_sPass; }
149 CIRCNetwork* GetNetwork() const { return m_pNetwork; }
150 bool HasNamesx() const { return m_bNamesx; }
151 bool HasUHNames() const { return m_bUHNames; }
152 bool HasAwayNotify() const { return m_bAwayNotify; }
153 bool HasAccountNotify() const { return m_bAccountNotify; }
154 bool HasExtendedJoin() const { return m_bExtendedJoin; }
155 bool HasServerTime() const { return m_bServerTime; }
156 const std::set<char>& GetUserModes() const {
157 return m_scUserModes;
158 }
159 // This is true if we are past raw 001
160 bool IsAuthed() const { return m_bAuthed; }
161 const SCString& GetAcceptedCaps() const { return m_ssAcceptedCaps; }
162 bool IsCapAccepted(const CString& sCap) {
163 return 1 == m_ssAcceptedCaps.count(sCap);
164 }
166 const CString& sDefault = "") const;
167 const MCString& GetISupport() const { return m_mISupport; }
169 const CString& sDefault = "") const;
170 // !Getters
171
172 // TODO move this function to CIRCNetwork and make it non-static?
173 static bool IsFloodProtected(double fRate);
174
175 private:
176 // Message Handlers
177 bool OnAccountMessage(CMessage& Message);
178 bool OnActionMessage(CActionMessage& Message);
179 bool OnAwayMessage(CMessage& Message);
180 bool OnCapabilityMessage(CMessage& Message);
181 bool OnChgHostMessage(CChgHostMessage& Message);
182 bool OnCTCPMessage(CCTCPMessage& Message);
183 bool OnErrorMessage(CMessage& Message);
184 bool OnInviteMessage(CMessage& Message);
185 bool OnJoinMessage(CJoinMessage& Message);
186 bool OnKickMessage(CKickMessage& Message);
187 bool OnModeMessage(CModeMessage& Message);
188 bool OnNickMessage(CNickMessage& Message);
189 bool OnNoticeMessage(CNoticeMessage& Message);
190 bool OnNumericMessage(CNumericMessage& Message);
191 bool OnPartMessage(CPartMessage& Message);
192 bool OnPingMessage(CMessage& Message);
193 bool OnPongMessage(CMessage& Message);
194 bool OnQuitMessage(CQuitMessage& Message);
195 bool OnTextMessage(CTextMessage& Message);
196 bool OnTopicMessage(CTopicMessage& Message);
197 bool OnWallopsMessage(CMessage& Message);
198 bool OnServerCapAvailable(const CString& sCap, const CString& sValue);
199 // !Message Handlers
200
201 void SetNick(const CString& sNick);
202 void ParseISupport(const CMessage& Message);
203 // This is called when we connect and the nick we want is already taken
204 void SendAltNick(const CString& sBadNick);
205 void SendNextCap();
206 void TrySend();
207
208 protected:
218 std::set<char> m_scUserModes;
219 std::map<char, EChanModeArgs> m_mceChanModes;
223 std::map<CString, CChan*> m_msChans;
224 unsigned int m_uMaxNickLen;
225 unsigned int m_uCapPaused;
230 unsigned int m_uNumCTCP;
231 static const time_t m_uCTCPFloodTime;
232 static const unsigned int m_uCTCPFloodCount;
234 std::deque<CMessage> m_vSendQueue;
236 unsigned short int m_uFloodBurst;
241
242 friend class CIRCFloodTimer;
243 friend class CCoreCaps;
244};
245
246#endif // !ZNC_IRCSOCK_H
std::set< CString > SCString
Definition ZNCString.h:37
std::vector< CString > VCString
Definition ZNCString.h:38
Definition Message.h:231
Definition Message.h:242
Definition Chan.h:35
Definition Message.h:338
Definition Client.h:99
Definition IRCNetwork.h:40
Definition IRCSock.h:35
VCString m_vsSSLError
Definition IRCSock.h:240
void ReachedMaxBuffer() override
This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers...
const CString & GetPerms() const
Definition IRCSock.h:144
CString m_sPermModes
Definition IRCSock.h:217
SCString m_ssPendingCaps
Definition IRCSock.h:227
std::set< char > m_scUserModes
Definition IRCSock.h:218
CIRCSock(const CIRCSock &)=delete
void PutIRCRaw(const CString &sLine)
Sends a raw data line to the server.
bool m_bExtendedJoin
Definition IRCSock.h:214
EChanModeArgs GetModeType(char cMode) const
CString m_sPerms
Definition IRCSock.h:216
static const time_t m_uCTCPFloodTime
Definition IRCSock.h:231
void SetTagSupport(const CString &sTag, bool bState)
Registers a tag as being supported or unsupported by the server.
void SetPass(const CString &s)
Definition IRCSock.h:127
bool IsPermMode(const char c) const
Definition IRCSock.h:141
short int m_iSendsAllowed
Definition IRCSock.h:235
bool m_bUHNames
Definition IRCSock.h:211
bool IsAuthed() const
Definition IRCSock.h:160
const std::map< char, EChanModeArgs > & GetChanModes() const
Definition IRCSock.h:135
bool IsCapAccepted(const CString &sCap)
Definition IRCSock.h:162
char GetPermFromMode(char cMode) const
bool m_bAuthed
Definition IRCSock.h:209
void Quit(const CString &sQuitMsg="")
const std::set< char > & GetUserModes() const
Definition IRCSock.h:156
CNick m_Nick
Definition IRCSock.h:221
void SSLCertError(X509 *pCert) override
bool IsTagEnabled(const CString &sTag) const
Definition IRCSock.h:116
void PutIRCQuick(const CString &sLine)
Should be used for PONG only.
void Timeout() override
Sock Timed out event.
unsigned int m_uNumCTCP
Definition IRCSock.h:230
bool m_bNamesx
Definition IRCSock.h:210
unsigned int m_uMaxNickLen
Definition IRCSock.h:224
CIRCNetwork * m_pNetwork
Definition IRCSock.h:220
void Connected() override
Connected event.
void ResetChans()
bool m_bFloodProtection
Definition IRCSock.h:238
MCString m_msCapLsValues
Definition IRCSock.h:228
void PauseCap()
You can call this from CModule::OnServerCapResult to suspend sending other CAP requests and CAP END f...
const SCString & GetAcceptedCaps() const
Definition IRCSock.h:161
time_t m_lastCTCP
Definition IRCSock.h:229
bool m_bServerTime
Definition IRCSock.h:215
char GetModeFromPerm(char cPerm) const
CIRCSock & operator=(const CIRCSock &)=delete
SCString m_ssAcceptedCaps
Definition IRCSock.h:226
static const unsigned int m_uCTCPFloodCount
Definition IRCSock.h:232
CString GetCapLsValue(const CString &sKey, const CString &sDefault="") const
EChanModeArgs
Definition IRCSock.h:43
@ HasArg
Definition IRCSock.h:47
@ ListArg
Definition IRCSock.h:46
@ ArgWhenSet
Definition IRCSock.h:48
@ NoArg
Definition IRCSock.h:49
void ReadLine(const CString &sData) override
void SockError(int iErrno, const CString &sDescription) override
bool HasAccountNotify() const
Definition IRCSock.h:153
SCString m_ssSupportedTags
Definition IRCSock.h:239
CIRCSock(CIRCNetwork *pNetwork)
bool m_bAccountNotify
Definition IRCSock.h:213
std::map< char, EChanModeArgs > m_mceChanModes
Definition IRCSock.h:219
friend class CCoreCaps
Definition IRCSock.h:243
CString GetNickMask() const
Definition IRCSock.h:146
bool HasExtendedJoin() const
Definition IRCSock.h:154
const CString & GetPermModes() const
Definition IRCSock.h:145
unsigned int GetMaxNickLen() const
Definition IRCSock.h:131
friend class CIRCFloodTimer
Definition IRCSock.h:242
CString GetISupport(const CString &sKey, const CString &sDefault="") const
bool IsPermChar(const char c) const
Definition IRCSock.h:138
MCString m_mISupport
Definition IRCSock.h:233
void ResumeCap()
If you used PauseCap, call this when CAP negotiation and logging in should be resumed again.
bool HasUHNames() const
Definition IRCSock.h:151
const MCString & GetISupport() const
Definition IRCSock.h:167
bool HasServerTime() const
Definition IRCSock.h:155
std::deque< CMessage > m_vSendQueue
Definition IRCSock.h:234
unsigned int m_uCapPaused
Definition IRCSock.h:225
std::map< CString, CChan * > m_msChans
Definition IRCSock.h:223
double m_fFloodRate
Definition IRCSock.h:237
bool HasNamesx() const
Definition IRCSock.h:150
const CString & GetNick() const
Definition IRCSock.h:147
void Disconnected() override
Disconnected event.
void PutIRC(const CMessage &Message)
Sends a message to the server.
virtual ~CIRCSock()
const CString & GetPass() const
Definition IRCSock.h:148
static bool IsFloodProtected(double fRate)
bool HasAwayNotify() const
Definition IRCSock.h:152
unsigned short int m_uFloodBurst
Definition IRCSock.h:236
CIRCNetwork * GetNetwork() const
Definition IRCSock.h:149
void ConnectionRefused() override
Connection Refused Event.
void PutIRC(const CString &sLine)
Sends a message to the server.
bool m_bAwayNotify
Definition IRCSock.h:212
CString m_sPass
Definition IRCSock.h:222
Base IRC socket for client<->ZNC, and ZNC<->server.
Definition Socket.h:309
Definition Message.h:252
Definition Message.h:293
Here is a small explanation of how messages on IRC work, and how you can use this class to get useful...
Definition Message.h:57
Definition Message.h:259
Definition Message.h:272
Definition Nick.h:29
const CString & GetNick() const
CString GetNickMask() const
Definition Message.h:280
Definition Message.h:287
Definition Message.h:304
Definition Message.h:313
String class that is used inside ZNC.
Definition ZNCString.h:68
Definition Message.h:322
Definition Message.h:329
Definition User.h:38
A dictionary for strings.
Definition ZNCString.h:595