20 #include <znc/zncconfig.h> 21 #include <znc/Csocket.h> 33 int ConvertAddress(
const struct sockaddr_storage* pAddr, socklen_t iAddrLen,
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;
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
Ease of use templated socket manager.
Definition: Csocket.h:1654
EAddrType
Definition: Socket.h:77
Definition: Csocket.h:223
void IcuExtFromUCallback(UConverterFromUnicodeArgs *fromArgs, const UChar *codeUnits, int32_t length, UChar32 codePoint, UConverterCallbackReason reason, UErrorCode *err) override
void SetSSLTrustedPeerFingerprints(const SCString &ssFPs)
Definition: Socket.h:49
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 ...
A job is a task which should run without blocking the main thread.
Definition: Threads.h:67
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
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
CString GetSSLPeerFingerprint(X509 *pCert=nullptr) const
CModule * GetModule() const
unsigned int GetAnonConnectionCount(const CString &sIP) const
Base IRC socket for client<->ZNC, and ZNC<->server.
Definition: Socket.h:309
friend class CThreadMonitorFD
Definition: Socket.h:173
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)
void SetTrustPKI(bool bTrustPKI)
Definition: Socket.h:56
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...
std::set< CString > SCString
Definition: ZNCString.h:35
CSocket(CModule *pModule)
ctor
Base Csock implementation to be used by modules.
Definition: Socket.h:247
int ConvertAddress(const struct sockaddr_storage *pAddr, socklen_t iAddrLen, CString &sIP, u_short *piPort) const override
Definition: Csocket.h:225
virtual CString GetRemoteIP() const
Definition: Socket.h:61
void SockError(int iErrno, const CString &sDescription) override
Basic socket class.
Definition: Csocket.h:563
Definition: Translation.h:71
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1409
bool GetTrustAllCerts() const
Definition: Socket.h:54
void ReachedMaxBuffer() override
This defaults to closing the socket, feel free to override.
String class that is used inside ZNC.
Definition: ZNCString.h:68
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...
bool CheckSSLCert(X509 *pCert)
bool Listen(unsigned short uPort, bool bSSL, unsigned int uTimeout=0)
Ease of use Listen, assigned to the manager and is subsequently tracked.
void SetMaxConns(int i)
set max connections as called by accept()
Definition: Csocket.h:1405
The base class for your own ZNC modules.
Definition: Modules.h:421
virtual bool Listen(const CSListener &cListen, Csock *pcSock=NULL, uint16_t *piRandPort=NULL)
Sets up a listening socket.
options container to create a listener
Definition: Csocket.h:1354
virtual bool Listen(uint16_t iPort, int iMaxConns=SOMAXCONN, const CS_STRING &sBindHost="", uint32_t iTimeout=0, bool bDetach=false)
Listens for connections.
CSocket & operator=(const CSocket &)=delete
void SetSockName(const CS_STRING &sSockName)
sets the sock name for later reference (ie FindSockByName)
Definition: Csocket.h:1399
bool GetTrustPKI() const
Definition: Socket.h:57
CInlineFormatMessage t_p(const CString &sEnglish, const CString &sEnglishes, int iNum, const CString &sContext) 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...
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
CModule * m_pModule
pointer to the module that this sock instance belongs to
Definition: Socket.h:302
CS_STRING GetRemoteIP() const
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
CInlineFormatMessage t_f(const CString &sEnglish, const CString &sContext="") const
void SetEncoding(const CString &)
void SetHostToVerifySSL(const CString &sHost)
Definition: Socket.h:46
Definition: Csocket.h:227
bool SNIConfigureClient(CString &sHostname) override
CString t_s(const CString &sEnglish, const CString &sContext="") const
CDelayedTranslation t_d(const CString &sEnglish, const CString &sContext="") const
~CZNCSock()
Definition: Socket.h:31
virtual void SSLCertError(X509 *pCert)
Definition: Socket.h:40
virtual bool Connect()
Create the connection, this is used by the socket manager, and shouldn't be called directly by the us...
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1403
Definition: Translation.h:103