20 #include <znc/zncconfig.h>
21 #include <znc/Csocket.h>
34 CString& sIP, u_short* piPort)
const override;
37 X509_STORE_CTX* pStoreCTX)
override;
47 m_sHostToVerifySSL = sHost;
50 m_ssTrustedFingerprints = ssFPs;
73 bool m_bTrustAllCerts =
false;
74 bool m_bTrustPKI =
true;
86 const CString& sBindHost,
bool bSSL =
false,
87 int iMaxConns = SOMAXCONN,
CZNCSock* pcSock =
nullptr,
114 int iMaxConns = SOMAXCONN,
CZNCSock* pcSock =
nullptr,
116 return ListenHost(iPort, sSockName,
"", bSSL, iMaxConns, pcSock,
121 bool bSSL =
false,
int iMaxConns = SOMAXCONN,
122 CZNCSock* pcSock =
nullptr, u_int iTimeout = 0,
124 unsigned short uPort = 0;
146 Listen(L, pcSock, &uPort);
152 int iMaxConns = SOMAXCONN,
CZNCSock* pcSock =
nullptr,
154 return (
ListenRand(sSockName,
"", bSSL, iMaxConns, pcSock, iTimeout,
159 const CString& sSockName,
int iTimeout = 60,
bool bSSL =
false,
166 void FinishConnect(
const CString& sHostname, u_short iPort,
167 const CString& sSockName,
int iTimeout,
bool bSSL,
170 std::map<
Csock*,
bool > m_InFlightDnsSockets;
176 #ifdef HAVE_THREADED_DNS
191 TDNSTask(
const TDNSTask&) =
delete;
192 TDNSTask& operator=(
const TDNSTask&) =
delete;
207 class CDNSJob :
public CJob {
217 CDNSJob(
const CDNSJob&) =
delete;
218 CDNSJob& operator=(
const CDNSJob&) =
delete;
228 void runThread()
override;
229 void runMain()
override;
231 void StartTDNSThread(TDNSTask* task,
bool bBind);
232 void SetTDNSThreadFinished(TDNSTask* task,
bool bBind, addrinfo* aiResult);
233 static void* TDNSThread(
void* argument);
280 bool bSSL =
false,
unsigned int uTimeout = 60);
282 bool Listen(
unsigned short uPort,
bool bSSL,
unsigned int uTimeout = 0);
292 const CString& sContext =
"")
const;
294 int iNum,
const CString& sContext)
const;
296 const CString& sContext =
"")
const;
323 const char* codeUnits, int32_t length,
324 UConverterCallbackReason reason,
325 UErrorCode* err)
override;
327 const UChar* codeUnits, int32_t length,
328 UChar32 codePoint, UConverterCallbackReason reason,
329 UErrorCode* err)
override;
EAddrType
Definition: Socket.h:77
@ ADDR_IPV6ONLY
Definition: Socket.h:77
@ ADDR_ALL
Definition: Socket.h:77
@ ADDR_IPV4ONLY
Definition: Socket.h:77
std::set< CString > SCString
Definition: ZNCString.h:35
Definition: Translation.h:103
Definition: Translation.h:71
Base IRC socket for client<->ZNC, and ZNC<->server.
Definition: Socket.h:309
void IcuExtFromUCallback(UConverterFromUnicodeArgs *fromArgs, const UChar *codeUnits, int32_t length, UChar32 codePoint, UConverterCallbackReason reason, UErrorCode *err) override
void IcuExtToUCallback(UConverterToUnicodeArgs *toArgs, const char *codeUnits, int32_t length, UConverterCallbackReason reason, UErrorCode *err) override
Allow IRC control characters to appear even if protocol encoding explicitly disallows them.
A job is a task which should run without blocking the main thread.
Definition: Threads.h:67
The base class for your own ZNC modules.
Definition: Modules.h:420
options container to create a listener
Definition: Csocket.h:1355
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1409
void SetSockName(const CS_STRING &sSockName)
sets the sock name for later reference (ie FindSockByName)
Definition: Csocket.h:1399
void SetTimeout(uint32_t i)
sets the listen timeout. The listener class will close after timeout has been reached if not 0
Definition: Csocket.h:1407
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1403
void SetMaxConns(int i)
set max connections as called by accept()
Definition: Csocket.h:1405
@ RAF_INET6
Definition: Csocket.h:225
@ RAF_ANY
Definition: Csocket.h:223
@ RAF_INET
Definition: Csocket.h:227
unsigned int GetAnonConnectionCount(const CString &sIP) const
void DelSockByAddr(Csock *pcSock) override
Delete a sock by addr its position is looked up the socket is deleted, the appropriate call backs are...
friend class CThreadMonitorFD
Definition: Socket.h:173
bool ListenAll(u_short iPort, const CString &sSockName, bool bSSL=false, int iMaxConns=SOMAXCONN, CZNCSock *pcSock=nullptr, u_int iTimeout=0, EAddrType eAddr=ADDR_ALL)
Definition: Socket.h:113
u_short ListenAllRand(const CString &sSockName, bool bSSL=false, int iMaxConns=SOMAXCONN, CZNCSock *pcSock=nullptr, u_int iTimeout=0, EAddrType eAddr=ADDR_ALL)
Definition: Socket.h:151
void Connect(const CString &sHostname, u_short iPort, const CString &sSockName, int iTimeout=60, bool bSSL=false, const CString &sBindHost="", CZNCSock *pcSock=nullptr)
u_short ListenRand(const CString &sSockName, const CString &sBindHost, bool bSSL=false, int iMaxConns=SOMAXCONN, CZNCSock *pcSock=nullptr, u_int iTimeout=0, EAddrType eAddr=ADDR_ALL)
Definition: Socket.h:120
bool ListenHost(u_short iPort, const CString &sSockName, const CString &sBindHost, bool bSSL=false, int iMaxConns=SOMAXCONN, CZNCSock *pcSock=nullptr, u_int iTimeout=0, EAddrType eAddr=ADDR_ALL)
Definition: Socket.h:85
virtual bool Listen(const CSListener &cListen, Csock *pcSock=NULL, uint16_t *piRandPort=NULL)
Sets up a listening socket.
Base Csock implementation to be used by modules.
Definition: Socket.h:247
CDelayedTranslation t_d(const CString &sEnglish, const CString &sContext="") const
CModule * GetModule() const
CModule * m_pModule
pointer to the module that this sock instance belongs to
Definition: Socket.h:302
bool ConnectionFrom(const CString &sHost, unsigned short uPort) override
This limits the global connections from this IP to defeat DoS attacks, feel free to override....
CSocket(CModule *pModule, const CString &sHostname, unsigned short uPort, int iTimeout=60)
ctor
CInlineFormatMessage t_f(const CString &sEnglish, const CString &sContext="") const
CSocket(CModule *pModule)
ctor
CSocket & operator=(const CSocket &)=delete
CInlineFormatMessage t_p(const CString &sEnglish, const CString &sEnglishes, int iNum, const CString &sContext) const
bool Listen(unsigned short uPort, bool bSSL, unsigned int uTimeout=0)
Ease of use Listen, assigned to the manager and is subsequently tracked.
CSocket(const CSocket &)=delete
void ReachedMaxBuffer() override
This defaults to closing the socket, feel free to override.
CString t_s(const CString &sEnglish, const CString &sContext="") const
void SockError(int iErrno, const CString &sDescription) override
bool Connect(const CString &sHostname, unsigned short uPort, bool bSSL=false, unsigned int uTimeout=60)
Ease of use Connect, assigns to the manager and is subsequently tracked.
String class that is used inside ZNC.
Definition: ZNCString.h:68
void SetHostToVerifySSL(const CString &sHost)
Definition: Socket.h:46
void SetTrustPKI(bool bTrustPKI)
Definition: Socket.h:56
CZNCSock(const CString &sHost, u_short port, int timeout=60)
void SetSSLTrustedPeerFingerprints(const SCString &ssFPs)
Definition: Socket.h:49
int ConvertAddress(const struct sockaddr_storage *pAddr, socklen_t iAddrLen, CString &sIP, u_short *piPort) const override
void SSLHandShakeFinished() override
called once the SSL handshake is complete, this is triggered via SSL_CB_HANDSHAKE_DONE in SSL_set_inf...
void SetTrustAllCerts(bool bTrustAll)
Definition: Socket.h:53
~CZNCSock()
Definition: Socket.h:31
int VerifyPeerCertificate(int iPreVerify, X509_STORE_CTX *pStoreCTX) override
this is hooked in via SSL_set_verify, and be default it just returns 1 meaning success
virtual void SSLCertError(X509 *pCert)
Definition: Socket.h:40
bool GetTrustAllCerts() const
Definition: Socket.h:54
CString GetSSLPeerFingerprint(X509 *pCert=nullptr) const
virtual CString GetRemoteIP() const
Definition: Socket.h:61
void SetEncoding(const CString &)
bool SNIConfigureClient(CString &sHostname) override
bool GetTrustPKI() const
Definition: Socket.h:57
@ errnoBadSSLCert
Definition: Socket.h:66
bool CheckSSLCert(X509 *pCert)
Basic socket class.
Definition: Csocket.h:564
virtual bool Listen(uint16_t iPort, int iMaxConns=SOMAXCONN, const CS_STRING &sBindHost="", uint32_t iTimeout=0, bool bDetach=false)
Listens for connections.
virtual bool Connect()
Create the connection, this is used by the socket manager, and shouldn't be called directly by the us...
CS_STRING GetRemoteIP() const
Ease of use templated socket manager.
Definition: Csocket.h:1655