ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Csocket.h
Go to the documentation of this file.
1 
33 /*
34  * NOTES ...
35  * - You should always compile with -Woverloaded-virtual to detect callbacks that may have been redefined since your last update
36  * - If you want to use gethostbyname instead of getaddrinfo, the use -DUSE_GETHOSTBYNAME when compiling
37  * - To compile with win32 need to link to winsock2, using gcc its -lws2_32
38  * - Code is formated with 'astyle --style=ansi -t4 --unpad-paren --pad-paren-in --keep-one-line-blocks'
39  */
40 #ifndef _HAS_CSOCKET_
41 #define _HAS_CSOCKET_
42 
43 #include <znc/defines.h> // require this as a general rule, most projects have a defines.h or the like
44 
45 #include <stdio.h>
46 #include <unistd.h>
47 #include <sys/time.h>
48 #include <sys/fcntl.h>
49 #include <sys/file.h>
50 
51 #ifndef _WIN32
52 
53 #include <netinet/in.h>
54 #include <arpa/inet.h>
55 #include <sys/socket.h>
56 #include <sys/ioctl.h>
57 #include <netdb.h>
58 
59 #else
60 
61 #include <winsock2.h>
62 #include <ws2tcpip.h>
63 #include <sys/timeb.h>
64 
65 #ifndef ECONNREFUSED
66 // these aliases might or might not be defined in errno.h
67 // already, depending on the WinSDK version.
68 #define ECONNREFUSED WSAECONNREFUSED
69 #define EINPROGRESS WSAEINPROGRESS
70 #define ETIMEDOUT WSAETIMEDOUT
71 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
72 #define ECONNABORTED WSAECONNABORTED
73 #define ENETUNREACH WSAENETUNREACH
74 #endif /* ECONNREFUSED */
75 
76 #endif /* _WIN32 */
77 
78 #ifdef HAVE_C_ARES
79 #include <ares.h>
80 #endif /* HAVE_C_ARES */
81 
82 #ifdef HAVE_ICU
83 # include <unicode/ucnv.h>
84 #endif
85 
86 #include <stdlib.h>
87 #include <errno.h>
88 #include <string.h>
89 #include <ctype.h>
90 #include <assert.h>
91 
92 #ifdef HAVE_LIBSSL
93 #include <openssl/ssl.h>
94 #include <openssl/err.h>
95 #include <openssl/rand.h>
96 #endif /* HAVE_LIBSSL */
97 
98 #ifdef __sun
99 #include <strings.h>
100 #include <fcntl.h>
101 #endif /* __sun */
102 
103 #include <vector>
104 #include <list>
105 #include <iostream>
106 #include <sstream>
107 #include <string>
108 #include <set>
109 #include <map>
110 
111 #ifndef CS_STRING
112 # ifdef _HAS_CSTRING_
113 # define CS_STRING Cstring
114 # else
115 # define CS_STRING std::string
116 # endif /* _HAS_CSTRING_ */
117 #endif /* CS_STRING */
118 
119 #ifndef CS_DEBUG
120 #ifdef __DEBUG__
121 # define CS_DEBUG( f ) std::cerr << __FILE__ << ":" << __LINE__ << " " << f << std::endl
122 #else
123 # define CS_DEBUG(f) (void)0
124 #endif /* __DEBUG__ */
125 #endif /* CS_DEBUG */
126 
127 #ifndef PERROR
128 #ifdef __DEBUG__
129 # define PERROR( f ) __Perror( f, __FILE__, __LINE__ )
130 #else
131 # define PERROR( f ) (void)0
132 #endif /* __DEBUG__ */
133 #endif /* PERROR */
134 
135 #ifdef _WIN32
136 typedef SOCKET cs_sock_t;
137 #ifdef _WIN64
138 typedef signed __int64 cs_ssize_t;
139 #else
140 typedef signed int cs_ssize_t;
141 #endif /* _WIN64 */
142 #define CS_INVALID_SOCK INVALID_SOCKET
143 #else
144 typedef int cs_sock_t;
145 typedef ssize_t cs_ssize_t;
146 #define CS_INVALID_SOCK -1
147 #endif /* _WIN32 */
148 
149 #ifdef CSOCK_USE_POLL
150 #include <poll.h>
151 #endif /* CSOCK_USE_POLL */
152 
153 #ifndef _NO_CSOCKET_NS // some people may not want to use a namespace
154 namespace Csocket
155 {
156 #endif /* _NO_CSOCKET_NS */
157 
158 
164 {
165 public:
166  CSCharBuffer( size_t iSize )
167  {
168  m_pBuffer = ( char * )malloc( iSize );
169  }
171  {
172  free( m_pBuffer );
173  }
174  char * operator()() { return( m_pBuffer ); }
175 
176 private:
177  char * m_pBuffer;
178 };
179 
180 
186 {
187 public:
189  {
190  m_bIsIPv6 = false;
191  memset( ( struct sockaddr_in * ) &m_saddr, '\0', sizeof( m_saddr ) );
192 #ifdef HAVE_IPV6
193  memset( ( struct sockaddr_in6 * ) &m_saddr6, '\0', sizeof( m_saddr6 ) );
194 #endif /* HAVE_IPV6 */
195  m_iAFRequire = RAF_ANY;
196  }
197  virtual ~CSSockAddr() {}
198 
199 
201  {
202  RAF_ANY = PF_UNSPEC,
203 #ifdef HAVE_IPV6
204  RAF_INET6 = AF_INET6,
205 #endif /* HAVE_IPV6 */
206  RAF_INET = AF_INET
207  };
208 
209  void SinFamily();
210  void SinPort( uint16_t iPort );
211  void SetIPv6( bool b );
212  bool GetIPv6() const { return( m_bIsIPv6 ); }
213 
214  socklen_t GetSockAddrLen() { return( sizeof( m_saddr ) ); }
215  sockaddr_in * GetSockAddr() { return( &m_saddr ); }
216  in_addr * GetAddr() { return( &( m_saddr.sin_addr ) ); }
217 #ifdef HAVE_IPV6
218  socklen_t GetSockAddrLen6() { return( sizeof( m_saddr6 ) ); }
219  sockaddr_in6 * GetSockAddr6() { return( &m_saddr6 ); }
220  in6_addr * GetAddr6() { return( &( m_saddr6.sin6_addr ) ); }
221 #endif /* HAVE_IPV6 */
222 
223  void SetAFRequire( EAFRequire iWhich ) { m_iAFRequire = iWhich; }
224  EAFRequire GetAFRequire() const { return( m_iAFRequire ); }
225 
226 private:
227  bool m_bIsIPv6;
228  sockaddr_in m_saddr;
229 #ifdef HAVE_IPV6
230  sockaddr_in6 m_saddr6;
231 #endif /* HAVE_IPV6 */
232  EAFRequire m_iAFRequire;
233 };
234 
235 
236 class Csock;
237 
238 
254 {
255 public:
262  CGetAddrInfo( const CS_STRING & sHostname, Csock * pSock, CSSockAddr & csSockAddr );
263  ~CGetAddrInfo();
264 
266  void Init();
268  int Process();
270  int Finish();
271 
272 private:
273  CS_STRING m_sHostname;
274  Csock * m_pSock;
275  CSSockAddr & m_csSockAddr;
276  struct addrinfo * m_pAddrRes;
277  struct addrinfo m_cHints;
278  int m_iRet;
279 };
280 
282 int GetAddrInfo( const CS_STRING & sHostname, Csock * pSock, CSSockAddr & csSockAddr );
283 
285 int GetCsockClassIdx();
286 
287 #ifdef HAVE_LIBSSL
288 Csock * GetCsockFromCTX( X509_STORE_CTX * pCTX );
290 #endif /* HAVE_LIBSSL */
291 
292 
293 const uint32_t CS_BLOCKSIZE = 4096;
294 template <class T> inline void CS_Delete( T * & p ) { if( p ) { delete p; p = NULL; } }
295 
296 #ifdef HAVE_LIBSSL
298 {
299  CT_NONE = 0,
300  CT_ZLIB = 1,
301  CT_RLE = 2
302 };
303 
305 void CSAdjustTVTimeout( struct timeval & tv, long iTimeoutMS );
306 
307 void SSLErrors( const char *filename, uint32_t iLineNum );
308 
314 bool InitSSL( ECompType eCompressionType = CT_NONE );
315 
316 #endif /* HAVE_LIBSSL */
317 
321 bool InitCsocket();
325 void ShutdownCsocket();
326 
328 inline int GetSockError()
329 {
330 #ifdef _WIN32
331  return( WSAGetLastError() );
332 #else
333  return( errno );
334 #endif /* _WIN32 */
335 }
336 
338 inline void TFD_ZERO( fd_set *set )
339 {
340  FD_ZERO( set );
341 }
342 
343 inline void TFD_SET( cs_sock_t iSock, fd_set *set )
344 {
345  FD_SET( iSock, set );
346 }
347 
348 inline bool TFD_ISSET( cs_sock_t iSock, fd_set *set )
349 {
350  return( FD_ISSET( iSock, set ) != 0 );
351 }
352 
353 inline void TFD_CLR( cs_sock_t iSock, fd_set *set )
354 {
355  FD_CLR( iSock, set );
356 }
357 
358 void __Perror( const CS_STRING & s, const char * pszFile, uint32_t iLineNo );
359 uint64_t millitime();
360 
361 
369 class CCron
370 {
371 public:
372  CCron();
373  virtual ~CCron() {}
374 
376  void run( timeval & tNow );
377 
382  void StartMaxCycles( double dTimeSequence, uint32_t iMaxCycles );
383  void StartMaxCycles( const timeval& tTimeSequence, uint32_t iMaxCycles );
384 
386  void Start( double dTimeSequence );
387  void Start( const timeval& TimeSequence );
388 
390  void Stop();
391 
393  void Pause();
394 
396  void UnPause();
397 
398  timeval GetInterval() const;
399  uint32_t GetMaxCycles() const;
400  uint32_t GetCyclesLeft() const;
401 
403  bool isValid();
404 
405  const CS_STRING & GetName() const;
406  void SetName( const CS_STRING & sName );
407 
409  timeval GetNextRun() const { return( m_tTime ); }
410 
411 public:
412 
414  virtual void RunJob();
415 
416 protected:
418 
419 private:
420  timeval m_tTime;
421  bool m_bActive, m_bPause;
422  timeval m_tTimeSequence;
423  uint32_t m_iMaxCycles, m_iCycles;
424  CS_STRING m_sName;
425 };
426 
432 {
433 public:
434  CSMonitorFD() { m_bEnabled = true; }
435  virtual ~CSMonitorFD() {}
436 
443  virtual bool GatherFDsForSelect( std::map< cs_sock_t, short > & miiReadyFds, long & iTimeoutMS );
444 
450  virtual bool FDsThatTriggered( const std::map< cs_sock_t, short > & miiReadyFds ) { return( true ); }
451 
457  virtual bool CheckFDs( const std::map< cs_sock_t, short > & miiReadyFds );
458 
464  void Add( cs_sock_t iFD, short iMonitorEvents ) { m_miiMonitorFDs[iFD] = iMonitorEvents; }
466  void Remove( cs_sock_t iFD ) { m_miiMonitorFDs.erase( iFD ); }
468  void DisableMonitor() { m_bEnabled = false; }
469 
470  bool IsEnabled() const { return( m_bEnabled ); }
471 
472 protected:
473  std::map< cs_sock_t, short > m_miiMonitorFDs;
475 };
476 
477 
483 {
484 public:
486  virtual ~CSockCommon();
487 
488  void CleanupCrons();
489  void CleanupFDMonitors();
490 
492  const std::vector<CCron *> & GetCrons() const { return( m_vcCrons ); }
494  virtual void Cron();
495 
497  virtual void AddCron( CCron * pcCron );
504  virtual void DelCron( const CS_STRING & sName, bool bDeleteAll = true, bool bCaseSensitive = true );
506  virtual void DelCron( uint32_t iPos );
508  virtual void DelCronByAddr( CCron * pcCron );
509 
510  void CheckFDs( const std::map< cs_sock_t, short > & miiReadyFds );
511  void AssignFDs( std::map< cs_sock_t, short > & miiReadyFds, struct timeval * tvtimeout );
512 
514  void MonitorFD( CSMonitorFD * pMonitorFD ) { m_vcMonitorFD.push_back( pMonitorFD ); }
515 
516 protected:
517  std::vector<CCron *> m_vcCrons;
518  std::vector<CSMonitorFD *> m_vcMonitorFD;
519 };
520 
521 
522 #ifdef HAVE_LIBSSL
523 typedef int ( *FPCertVerifyCB )( int, X509_STORE_CTX * );
524 #endif /* HAVE_LIBSSL */
525 
526 
537 class Csock : public CSockCommon
538 {
539 public:
541  Csock( int iTimeout = 60 );
548  Csock( const CS_STRING & sHostname, uint16_t uPort, int itimeout = 60 );
549 
551  virtual Csock *GetSockObj( const CS_STRING & sHostname, uint16_t iPort );
552 
553  virtual ~Csock();
554 
561  virtual void Dereference();
563  virtual void Copy( const Csock & cCopy );
564 
565  enum ETConn
566  {
567  OUTBOUND = 0,
568  LISTENER = 1,
569  INBOUND = 2
570  };
571 
572  enum EFRead
573  {
574  READ_EOF = 0,
575  READ_ERR = -1,
576  READ_EAGAIN = -2,
577  READ_CONNREFUSED = -3,
578  READ_TIMEDOUT = -4
579  };
580 
581  enum EFSelect
582  {
583  SEL_OK = 0,
584  SEL_TIMEOUT = -1,
585  SEL_EAGAIN = -2,
586  SEL_ERR = -3
587  };
588 
590  {
591  SSL23 = 0,
592  SSL2 = 2,
593  SSL3 = 3,
594  TLS1 = 4
595  };
596 
598  {
599  CST_START = 0,
600  CST_DNS = CST_START,
601  CST_BINDVHOST = 1,
602  CST_DESTDNS = 2,
603  CST_CONNECT = 3,
604  CST_CONNECTSSL = 4,
605  CST_OK = 5
606  };
607 
609  {
610  CLT_DONT = 0,
611  CLT_NOW = 1,
612  CLT_AFTERWRITE = 2,
613  CLT_DEREFERENCE = 3
614  };
615 
616  Csock & operator<<( const CS_STRING & s );
617  Csock & operator<<( std::ostream & ( *io )( std::ostream & ) );
618  Csock & operator<<( int32_t i );
619  Csock & operator<<( uint32_t i );
620  Csock & operator<<( int64_t i );
621  Csock & operator<<( uint64_t i );
622  Csock & operator<<( float i );
623  Csock & operator<<( double i );
624 
629  virtual bool Connect();
630 
639  virtual bool Listen( uint16_t iPort, int iMaxConns = SOMAXCONN, const CS_STRING & sBindHost = "", uint32_t iTimeout = 0, bool bDetach = false );
640 
642  virtual cs_sock_t Accept( CS_STRING & sHost, uint16_t & iRPort );
643 
645  virtual bool AcceptSSL();
646 
648  virtual bool SSLClientSetup();
649 
651  virtual bool SSLServerSetup();
652 
659  virtual bool ConnectSSL();
660 
662  bool StartTLS();
663 
674  virtual bool Write( const char *data, size_t len );
675 
684  virtual bool Write( const CS_STRING & sData );
685 
701  virtual cs_ssize_t Read( char *data, size_t len );
702  CS_STRING GetLocalIP();
703  CS_STRING GetRemoteIP();
704 
706  virtual bool IsConnected() const;
708  virtual void SetIsConnected( bool b );
709 
711  cs_sock_t & GetRSock();
712  void SetRSock( cs_sock_t iSock );
713  cs_sock_t & GetWSock();
714  void SetWSock( cs_sock_t iSock );
715 
716  void SetSock( cs_sock_t iSock );
717  cs_sock_t & GetSock();
718 
724  void CallSockError( int iErrno, const CS_STRING & sDescription = "" );
726  virtual void ResetTimer();
727 
729  void PauseRead();
730  void UnPauseRead();
731  bool IsReadPaused();
738  enum
739  {
740  TMO_READ = 1,
741  TMO_WRITE = 2,
742  TMO_ACCEPT = 4,
743  TMO_ALL = TMO_READ|TMO_WRITE|TMO_ACCEPT
744  };
745 
748  void SetTimeout( int iTimeout, uint32_t iTimeoutType = TMO_ALL );
749  void SetTimeoutType( uint32_t iTimeoutType );
750  int GetTimeout() const;
751  uint32_t GetTimeoutType() const;
752 
754  virtual bool CheckTimeout( time_t iNow );
755 
760  virtual void PushBuff( const char *data, size_t len, bool bStartAtZero = false );
761 
765  CS_STRING & GetInternalReadBuffer();
766 
769  CS_STRING & GetInternalWriteBuffer();
770 
772  void SetMaxBufferThreshold( uint32_t iThreshold );
773  uint32_t GetMaxBufferThreshold() const;
774 
776  int GetType() const;
777  void SetType( int iType );
778 
780  const CS_STRING & GetSockName() const;
781  void SetSockName( const CS_STRING & sName );
782 
784  const CS_STRING & GetHostName() const;
785  void SetHostName( const CS_STRING & sHostname );
786 
787 
789  uint64_t GetStartTime() const;
791  void ResetStartTime();
792 
794  uint64_t GetBytesRead() const;
795  void ResetBytesRead();
796 
798  uint64_t GetBytesWritten() const;
799  void ResetBytesWritten();
800 
802  double GetAvgRead( uint64_t iSample = 1000 );
803 
805  double GetAvgWrite( uint64_t iSample = 1000 );
806 
808  uint16_t GetRemotePort();
809 
811  uint16_t GetLocalPort();
812 
814  uint16_t GetPort();
815  void SetPort( uint16_t iPort );
816 
818  void Close( ECloseType eCloseType = CLT_NOW );
820  ECloseType GetCloseType() { return( m_eCloseType ); }
821  bool IsClosed() { return( GetCloseType() != CLT_DONT ); }
822 
824  void NonBlockingIO();
825 
827  bool GetSSL();
828  void SetSSL( bool b );
829 
830 #ifdef HAVE_LIBSSL
831  void SetCipher( const CS_STRING & sCipher );
833  const CS_STRING & GetCipher();
834 
836  void SetPemLocation( const CS_STRING & sPemFile );
837  const CS_STRING & GetPemLocation();
838  void SetPemPass( const CS_STRING & sPassword );
839  const CS_STRING & GetPemPass() const;
840 
842  void SetSSLMethod( int iMethod );
843  int GetSSLMethod();
844 
845  void SetSSLObject( SSL *ssl );
846  void SetCTXObject( SSL_CTX *sslCtx );
847  SSL_SESSION * GetSSLSession();
848 
849  void SetCertVerifyCB( FPCertVerifyCB pFP ) { m_pCerVerifyCB = pFP; }
850 #endif /* HAVE_LIBSSL */
851 
853  bool HasWriteBuffer() const;
854  void ClearWriteBuffer();
855 
858  bool SslIsEstablished();
859 
861  bool ConnectInetd( bool bIsSSL = false, const CS_STRING & sHostname = "" );
862 
864  bool ConnectFD( int iReadFD, int iWriteFD, const CS_STRING & sName, bool bIsSSL = false, ETConn eDirection = INBOUND );
865 
867 #ifdef HAVE_LIBSSL
868  X509 *GetX509();
869 
871  CS_STRING GetPeerPubKey();
873  long GetPeerFingerprint( CS_STRING & sFP );
874 
875  uint32_t GetRequireClientCertFlags();
877  void SetRequiresClientCert( bool bRequiresCert );
879  void SetRequireClientCertFlags( uint32_t iRequireClientCertFlags ) { m_iRequireClientCertFlags = iRequireClientCertFlags; }
880 #endif /* HAVE_LIBSSL */
881 
883  virtual void SetParentSockName( const CS_STRING & sParentName );
884  const CS_STRING & GetParentSockName();
885 
891  virtual void SetRate( uint32_t iBytes, uint64_t iMilliseconds );
892 
893  uint32_t GetRateBytes();
894  uint64_t GetRateTime();
895 
903  virtual void Connected() {}
911  virtual void Disconnected() {}
919  virtual void Timeout() {}
927  virtual void ReadData( const char *data, size_t len ) {}
936  virtual void ReadLine( const CS_STRING & sLine ) {}
938  void EnableReadLine();
939  void DisableReadLine();
941  bool HasReadLine() const { return( m_bEnableReadLine ); }
942 
951  virtual void ReachedMaxBuffer();
959  virtual void SockError( int iErrno, const CS_STRING & sDescription ) {}
970  virtual bool ConnectionFrom( const CS_STRING & sHost, uint16_t iPort ) { return( true ); }
971 
977  virtual void Listening( const CS_STRING & sBindIP, uint16_t uPort ) {}
978 
987  virtual void ConnectionRefused() {}
991  virtual void ReadPaused() {}
992 
993 #ifdef HAVE_LIBSSL
994 
998  virtual void SSLFinishSetup( SSL * pSSL ) {}
999 #endif /* HAVE_LIBSSL */
1000 
1001 
1003  time_t GetTimeSinceLastDataTransaction( time_t iNow = 0 );
1004 
1005  time_t GetLastCheckTimeout() { return( m_iLastCheckTimeoutTime ); }
1006 
1008  time_t GetNextCheckTimeout( time_t iNow = 0 );
1009 
1011  virtual int GetPending();
1012 
1014  // Connection State Stuff
1016  ECONState GetConState() const { return( m_eConState ); }
1018  void SetConState( ECONState eState ) { m_eConState = eState; }
1019 
1021  bool CreateSocksFD();
1022 
1024  void CloseSocksFD();
1025 
1026  const CS_STRING & GetBindHost() const { return( m_sBindHost ); }
1027  void SetBindHost( const CS_STRING & sBindHost ) { m_sBindHost = sBindHost; }
1028 
1030  {
1032  DNS_DEST
1033  };
1034 
1039  int DNSLookup( EDNSLType eDNSLType );
1040 
1042  bool SetupVHost();
1043 
1044  bool GetIPv6() const { return( m_bIsIPv6 ); }
1045  void SetIPv6( bool b )
1046  {
1047  m_bIsIPv6 = b;
1048  m_address.SetIPv6( b );
1049  m_bindhost.SetIPv6( b );
1050  }
1051 
1053  {
1054  m_address.SetAFRequire( iAFRequire );
1055  m_bindhost.SetAFRequire( iAFRequire );
1056  }
1057 
1059  bool AllowWrite( uint64_t & iNOW ) const;
1060 
1061 
1062  void SetSkipConnect( bool b ) { m_bSkipConnect = b; }
1063 
1070  virtual int GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr );
1071 
1084  virtual int ConvertAddress( const struct sockaddr_storage * pAddr, socklen_t iAddrLen, CS_STRING & sIP, uint16_t * piPort );
1085 
1086 #ifdef HAVE_C_ARES
1087  CSSockAddr * GetCurrentAddr() const { return( m_pCurrAddr ); }
1088  void SetAresFinished( int status ) { m_pCurrAddr = NULL; m_iARESStatus = status; }
1089  ares_channel GetAresChannel() { return( m_pARESChannel ); }
1090 #endif /* HAVE_C_ARES */
1091 
1093  int GetMaxConns() const { return( m_iMaxConns ); }
1094 
1095 #ifdef HAVE_ICU
1096  void SetEncoding( const CString& sEncoding );
1097 #endif /* HAVE_ICU */
1098 
1099 private:
1101  Csock( const Csock & cCopy ) : CSockCommon() {}
1103  void ShrinkSendBuff();
1104  void IncBuffPos( size_t uBytes );
1105 
1106  // NOTE! if you add any new members, be sure to add them to Copy()
1107  uint16_t m_uPort, m_iRemotePort, m_iLocalPort;
1108  cs_sock_t m_iReadSock, m_iWriteSock;
1109  int m_iTimeout, m_iConnType, m_iMethod, m_iTcount, m_iMaxConns;
1110  bool m_bUseSSL, m_bIsConnected, m_bBLOCK;
1111  bool m_bsslEstablished, m_bEnableReadLine, m_bPauseRead;
1112  CS_STRING m_shostname, m_sbuffer, m_sSockName, m_sPemFile, m_sCipherType, m_sParentName;
1113  CS_STRING m_sSend, m_sPemPass, m_sLocalIP, m_sRemoteIP;
1114  ECloseType m_eCloseType;
1115 
1116  uint64_t m_iMaxMilliSeconds, m_iLastSendTime, m_iBytesRead, m_iBytesWritten, m_iStartTime;
1117  uint32_t m_iMaxBytes, m_iMaxStoredBufferLength, m_iTimeoutType;
1118  size_t m_iLastSend, m_uSendBufferPos;
1119 
1120  CSSockAddr m_address, m_bindhost;
1121  bool m_bIsIPv6, m_bSkipConnect;
1122  time_t m_iLastCheckTimeoutTime;
1123 
1124 #ifdef HAVE_LIBSSL
1125  CS_STRING m_sSSLBuffer;
1126  SSL * m_ssl;
1127  SSL_CTX * m_ssl_ctx;
1128  uint32_t m_iRequireClientCertFlags;
1129 
1130  FPCertVerifyCB m_pCerVerifyCB;
1131 
1132  void FREE_SSL();
1133  void FREE_CTX();
1134 
1135 #endif /* HAVE_LIBSSL */
1136 
1138  cs_sock_t CreateSocket( bool bListen = false );
1139  void Init( const CS_STRING & sHostname, uint16_t uPort, int iTimeout = 60 );
1140 
1141  // Connection State Info
1142  ECONState m_eConState;
1143  CS_STRING m_sBindHost;
1144  uint32_t m_iCurBindCount, m_iDNSTryCount;
1145 #ifdef HAVE_C_ARES
1146  void FreeAres();
1147  ares_channel m_pARESChannel;
1148  CSSockAddr * m_pCurrAddr;
1149  int m_iARESStatus;
1150 #endif /* HAVE_C_ARES */
1151 
1152 #ifdef HAVE_ICU
1153  icu::LocalUConverterPointer m_cnvInt, m_cnvIntStrict, m_cnvExt;
1154  bool m_cnvTryUTF8;
1155 #endif
1156 };
1157 
1163 {
1164 public:
1170  CSConnection( const CS_STRING & sHostname, uint16_t iPort, int iTimeout = 60 )
1171  {
1172  m_sHostname = sHostname;
1173  m_iPort = iPort;
1174  m_iTimeout = iTimeout;
1175  m_bIsSSL = false;
1176 #ifdef HAVE_LIBSSL
1177  m_sCipher = "HIGH";
1178 #endif /* HAVE_LIBSSL */
1179  m_iAFrequire = CSSockAddr::RAF_ANY;
1180  }
1181  virtual ~CSConnection() {}
1182 
1183  const CS_STRING & GetHostname() const { return( m_sHostname ); }
1184  const CS_STRING & GetSockName() const { return( m_sSockName ); }
1185  const CS_STRING & GetBindHost() const { return( m_sBindHost ); }
1186  uint16_t GetPort() const { return( m_iPort ); }
1187  int GetTimeout() const { return( m_iTimeout ); }
1188  bool GetIsSSL() const { return( m_bIsSSL ); }
1189  CSSockAddr::EAFRequire GetAFRequire() const { return( m_iAFrequire ); }
1190 
1191 #ifdef HAVE_LIBSSL
1192  const CS_STRING & GetCipher() const { return( m_sCipher ); }
1193  const CS_STRING & GetPemLocation() const { return( m_sPemLocation ); }
1194  const CS_STRING & GetPemPass() const { return( m_sPemPass ); }
1195 #endif /* HAVE_LIBSSL */
1196 
1198  void SetHostname( const CS_STRING & s ) { m_sHostname = s; }
1200  void SetSockName( const CS_STRING & s ) { m_sSockName = s; }
1202  void SetBindHost( const CS_STRING & s ) { m_sBindHost = s; }
1204  void SetPort( uint16_t i ) { m_iPort = i; }
1206  void SetTimeout( int i ) { m_iTimeout = i; }
1208  void SetIsSSL( bool b ) { m_bIsSSL = b; }
1210  void SetAFRequire( CSSockAddr::EAFRequire iAFRequire ) { m_iAFrequire = iAFRequire; }
1211 
1212 #ifdef HAVE_LIBSSL
1213  void SetCipher( const CS_STRING & s ) { m_sCipher = s; }
1216  void SetPemLocation( const CS_STRING & s ) { m_sPemLocation = s; }
1218  void SetPemPass( const CS_STRING & s ) { m_sPemPass = s; }
1219 #endif /* HAVE_LIBSSL */
1220 
1221 protected:
1222  CS_STRING m_sHostname, m_sSockName, m_sBindHost;
1223  uint16_t m_iPort;
1225  bool m_bIsSSL;
1227 #ifdef HAVE_LIBSSL
1228  CS_STRING m_sPemLocation, m_sPemPass, m_sCipher;
1229 #endif /* HAVE_LIBSSL */
1230 };
1231 
1233 {
1234 public:
1235  CSSSLConnection( const CS_STRING & sHostname, uint16_t iPort, int iTimeout = 60 ) :
1236  CSConnection( sHostname, iPort, iTimeout )
1237  {
1238  SetIsSSL( true );
1239  }
1240 };
1241 
1242 
1248 {
1249 public:
1255  CSListener( uint16_t iPort, const CS_STRING & sBindHost = "", bool bDetach = false )
1256  {
1257  m_iPort = iPort;
1258  m_sBindHost = sBindHost;
1259  m_bIsSSL = false;
1260  m_iMaxConns = SOMAXCONN;
1261  m_iTimeout = 0;
1262  m_iAFrequire = CSSockAddr::RAF_ANY;
1263  m_bDetach = bDetach;
1264 #ifdef HAVE_LIBSSL
1265  m_sCipher = "HIGH";
1266  m_iRequireCertFlags = 0;
1267 #endif /* HAVE_LIBSSL */
1268  }
1269  virtual ~CSListener() {}
1270 
1271  void SetDetach( bool b ) { m_bDetach = b; }
1272  bool GetDetach() const { return( m_bDetach ); }
1273  uint16_t GetPort() const { return( m_iPort ); }
1274  const CS_STRING & GetSockName() const { return( m_sSockName ); }
1275  const CS_STRING & GetBindHost() const { return( m_sBindHost ); }
1276  bool GetIsSSL() const { return( m_bIsSSL ); }
1277  int GetMaxConns() const { return( m_iMaxConns ); }
1278  uint32_t GetTimeout() const { return( m_iTimeout ); }
1279  CSSockAddr::EAFRequire GetAFRequire() const { return( m_iAFrequire ); }
1280 #ifdef HAVE_LIBSSL
1281  const CS_STRING & GetCipher() const { return( m_sCipher ); }
1282  const CS_STRING & GetPemLocation() const { return( m_sPemLocation ); }
1283  const CS_STRING & GetPemPass() const { return( m_sPemPass ); }
1284  uint32_t GetRequireClientCertFlags() const { return( m_iRequireCertFlags ); }
1285 #endif /* HAVE_LIBSSL */
1286 
1288  void SetPort( uint16_t iPort ) { m_iPort = iPort; }
1290  void SetSockName( const CS_STRING & sSockName ) { m_sSockName = sSockName; }
1292  void SetBindHost( const CS_STRING & sBindHost ) { m_sBindHost = sBindHost; }
1294  void SetIsSSL( bool b ) { m_bIsSSL = b; }
1296  void SetMaxConns( int i ) { m_iMaxConns = i; }
1298  void SetTimeout( uint32_t i ) { m_iTimeout = i; }
1300  void SetAFRequire( CSSockAddr::EAFRequire iAFRequire ) { m_iAFrequire = iAFRequire; }
1301 
1302 #ifdef HAVE_LIBSSL
1303  void SetCipher( const CS_STRING & s ) { m_sCipher = s; }
1306  void SetPemLocation( const CS_STRING & s ) { m_sPemLocation = s; }
1308  void SetPemPass( const CS_STRING & s ) { m_sPemPass = s; }
1310  void SetRequiresClientCert( bool b ) { m_iRequireCertFlags = ( b ? SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0 ); }
1312  void SetRequireClientCertFlags( unsigned int iRequireCertFlags ) { m_iRequireCertFlags = iRequireCertFlags; }
1313 #endif /* HAVE_LIBSSL */
1314 private:
1315  uint16_t m_iPort;
1316  CS_STRING m_sSockName, m_sBindHost;
1317  bool m_bIsSSL;
1318  bool m_bDetach;
1319  int m_iMaxConns;
1320  uint32_t m_iTimeout;
1321  CSSockAddr::EAFRequire m_iAFrequire;
1322 
1323 #ifdef HAVE_LIBSSL
1324  CS_STRING m_sPemLocation, m_sPemPass, m_sCipher;
1325  uint32_t m_iRequireCertFlags;
1326 #endif /* HAVE_LIBSSL */
1327 };
1328 
1329 #ifdef HAVE_LIBSSL
1330 class CSSSListener : public CSListener
1331 {
1332 public:
1333  CSSSListener( uint16_t iPort, const CS_STRING & sBindHost = "" ) :
1334  CSListener( iPort, sBindHost )
1335  {
1336  SetIsSSL( true );
1337  }
1338 };
1339 #endif /* HAVE_LIBSSL */
1340 
1362 class CSocketManager : public std::vector<Csock *>, public CSockCommon
1363 {
1364 public:
1365  CSocketManager();
1366  virtual ~CSocketManager();
1367  virtual void clear();
1368  virtual void Cleanup();
1369 
1370  virtual Csock * GetSockObj( const CS_STRING & sHostname, uint16_t uPort, int iTimeout = 60 );
1371 
1373  {
1374  SUCCESS = 0,
1375  SELECT_ERROR = -1,
1376  SELECT_TIMEOUT = -2,
1377  SELECT_TRYAGAIN = -3
1378  };
1379 
1385  void Connect( const CSConnection & cCon, Csock * pcSock = NULL );
1386 
1396  virtual bool Listen( const CSListener & cListen, Csock * pcSock = NULL, uint16_t * piRandPort = NULL );
1397 
1398 
1400  bool HasFDs() const;
1401 
1407  virtual void Loop();
1408 
1424  void DynamicSelectLoop( uint64_t iLowerBounds, uint64_t iUpperBounds, time_t iMaxResolution = 3600 );
1425 
1430  virtual void AddSock( Csock * pcSock, const CS_STRING & sSockName );
1431 
1433  virtual Csock * FindSockByRemotePort( uint16_t iPort );
1434 
1436  virtual Csock * FindSockByLocalPort( uint16_t iPort );
1437 
1439  virtual Csock * FindSockByName( const CS_STRING & sName );
1440 
1442  virtual Csock * FindSockByFD( cs_sock_t iFD );
1443 
1444  virtual std::vector<Csock *> FindSocksByName( const CS_STRING & sName );
1445 
1447  virtual std::vector<Csock *> FindSocksByRemoteHost( const CS_STRING & sHostname );
1448 
1450  int GetErrno() { return( m_errno ); }
1451 
1453  uint64_t GetSelectTimeout() { return( m_iSelectWait ); }
1456  void SetSelectTimeout( uint64_t iTimeout ) { m_iSelectWait = iTimeout; }
1457 
1462  virtual void DelSockByAddr( Csock * pcSock );
1463 
1469  virtual void DelSock( size_t iPos );
1470 
1477  virtual bool SwapSockByIdx( Csock * pNewSock, size_t iOrginalSockIdx );
1478 
1485  virtual bool SwapSockByAddr( Csock * pNewSock, Csock * pOrigSock );
1486 
1488  uint64_t GetBytesRead() const;
1489 
1491  uint64_t GetBytesWritten() const;
1492 
1495  {
1496  ECT_Read = 1,
1497  ECT_Write = 2
1498  };
1499 
1500  void FDSetCheck( cs_sock_t iFd, std::map< cs_sock_t, short > & miiReadyFds, ECheckType eType );
1501  bool FDHasCheck( cs_sock_t iFd, std::map< cs_sock_t, short > & miiReadyFds, ECheckType eType );
1502 
1503 protected:
1504 
1505  virtual int Select( std::map< cs_sock_t, short > & miiReadyFds, struct timeval *tvtimeout );
1506 
1507 private:
1514  void Select( std::map<Csock *, EMessages> & mpeSocks );
1515 
1516  timeval GetDynamicSleepTime( const timeval& tNow, const timeval& tMaxResolution ) const;
1517 
1519  virtual void SelectSock( std::map<Csock *, EMessages> & mpeSocks, EMessages eErrno, Csock * pcSock );
1520 
1522  // Connection State Functions
1523 
1525  // members
1526  EMessages m_errno;
1527  uint64_t m_iCallTimeouts;
1528  uint64_t m_iBytesRead;
1529  uint64_t m_iBytesWritten;
1530  uint64_t m_iSelectWait;
1531 };
1532 
1533 
1540 template<class T>
1542 {
1543 public:
1545  virtual ~TSocketManager() {}
1546  virtual T * GetSockObj( const CS_STRING & sHostname, uint16_t uPort, int iTimeout = 60 )
1547  {
1548  return( new T( sHostname, uPort, iTimeout ) );
1549  }
1550 };
1551 
1552 #ifndef _NO_CSOCKET_NS
1553 }
1554 #endif /* _NO_CSOCKET_NS */
1555 
1556 #endif /* _HAS_CSOCKET_ */
1557 
void CSAdjustTVTimeout(struct timeval &tv, long iTimeoutMS)
adjusts tv with a new timeout if iTimeoutMS is smaller
void SetRequireClientCertFlags(unsigned int iRequireCertFlags)
bitwise flags, 0 means don&#39;t require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER...
Definition: Csocket.h:1312
void SSLErrors(const char *filename, uint32_t iLineNum)
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1185
int GetCsockClassIdx()
used to retrieve the context position of the socket to its associated ssl connection. Setup once in InitSSL() via SSL_get_ex_new_index
virtual ~CCron()
Definition: Csocket.h:373
simple class to share common code to both TSockManager and Csock
Definition: Csocket.h:482
void MonitorFD(CSMonitorFD *pMonitorFD)
add an FD set to monitor
Definition: Csocket.h:514
ssize_t cs_ssize_t
Definition: Csocket.h:145
Ease of use templated socket manager.
Definition: Csocket.h:1541
Definition: Csocket.h:202
uint64_t millitime()
virtual void ReadPaused()
This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused.
Definition: Csocket.h:991
void SetIPv6(bool b)
Definition: Csocket.h:1045
void SetBindHost(const CS_STRING &s)
sets the hostname to bind to (vhost support)
Definition: Csocket.h:1202
void SetBindHost(const CS_STRING &sBindHost)
sets the host to bind to
Definition: Csocket.h:1292
Definition: Csocket.h:1232
CSCharBuffer(size_t iSize)
Definition: Csocket.h:166
Csock * GetCsockFromCTX(X509_STORE_CTX *pCTX)
returns the sock object associated to the particular context. returns NULL on failure or if not avail...
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1026
void ShutdownCsocket()
Shutdown and release global allocated memory.
virtual void SockError(int iErrno, const CS_STRING &sDescription)
A sock error occured event.
Definition: Csocket.h:959
const CS_STRING & GetSockName() const
Definition: Csocket.h:1274
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:1298
this function is a wrapper around getaddrinfo (for ipv6)
Definition: Csocket.h:253
CS_STRING m_sSockName
Definition: Csocket.h:1222
ESSLMethod
Definition: Csocket.h:589
virtual T * GetSockObj(const CS_STRING &sHostname, uint16_t uPort, int iTimeout=60)
Definition: Csocket.h:1546
void Add(cs_sock_t iFD, short iMonitorEvents)
adds a file descriptor to be monitored
Definition: Csocket.h:464
bool GetIPv6() const
Definition: Csocket.h:1044
void SetConState(ECONState eState)
sets the connection state to eState
Definition: Csocket.h:1018
EAFRequire GetAFRequire() const
Definition: Csocket.h:224
bool TFD_ISSET(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:348
void SetAFRequire(EAFRequire iWhich)
Definition: Csocket.h:223
virtual ~CSSockAddr()
Definition: Csocket.h:197
CSSockAddr::EAFRequire GetAFRequire() const
Definition: Csocket.h:1279
void Remove(cs_sock_t iFD)
removes this fd from monitoring
Definition: Csocket.h:466
const CS_STRING & GetPemLocation() const
Definition: Csocket.h:1193
ETConn
Definition: Csocket.h:565
bool m_bEnabled
Definition: Csocket.h:474
bool m_bRunOnNextCall
if set to true, RunJob() gets called on next invocation of run() despite the timeout ...
Definition: Csocket.h:417
void SetTimeout(int i)
sets the connection timeout
Definition: Csocket.h:1206
uint16_t GetPort() const
Definition: Csocket.h:1273
Definition: Csocket.h:1330
virtual bool FDsThatTriggered(const std::map< cs_sock_t, short > &miiReadyFds)
called when there are fd&#39;s belonging to this class that have triggered
Definition: Csocket.h:450
char * operator()()
Definition: Csocket.h:174
EFRead
Definition: Csocket.h:572
Ease of use self deleting char * class.
Definition: Csocket.h:163
EFSelect
Definition: Csocket.h:581
virtual void Connected()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:903
ECONState
Definition: Csocket.h:597
const CS_STRING & GetCipher() const
Definition: Csocket.h:1192
uint32_t GetTimeout() const
Definition: Csocket.h:1278
virtual ~CSMonitorFD()
Definition: Csocket.h:435
Definition: Csocket.h:300
void SetDetach(bool b)
Definition: Csocket.h:1271
CSSockAddr::EAFRequire m_iAFrequire
Definition: Csocket.h:1226
void SetPemLocation(const CS_STRING &s)
set the location of the pemfile
Definition: Csocket.h:1306
this lookup is for the vhost bind
Definition: Csocket.h:1031
void SetSockName(const CS_STRING &s)
sets the name of the socket, used for reference, ie in FindSockByName()
Definition: Csocket.h:1200
void CS_Delete(T *&p)
Definition: Csocket.h:294
virtual void SSLFinishSetup(SSL *pSSL)
Gets called immediatly after the m_ssl member is setup and initialized, useful if you need to assign ...
Definition: Csocket.h:998
const CS_STRING & GetHostname() const
Definition: Csocket.h:1183
void SetSelectTimeout(uint64_t iTimeout)
Set the Select Timeout in MICROSECONDS ( 1000 == 1 millisecond ) Setting this to 0 will cause no time...
Definition: Csocket.h:1456
bool GetIPv6() const
Definition: Csocket.h:212
int GetMaxConns() const
Definition: Csocket.h:1277
ECloseType
Definition: Csocket.h:608
in_addr * GetAddr()
Definition: Csocket.h:216
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1275
options for creating a connection
Definition: Csocket.h:1162
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1210
CSSockAddr::EAFRequire GetAFRequire() const
Definition: Csocket.h:1189
Basic socket class.
Definition: Csocket.h:537
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1300
const CS_STRING & GetPemPass() const
Definition: Csocket.h:1283
virtual void Timeout()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:919
virtual ~CSListener()
Definition: Csocket.h:1269
bool m_bIsSSL
Definition: Csocket.h:1225
const CS_STRING & GetCipher() const
Definition: Csocket.h:1281
String class that is used inside ZNC.
Definition: ZNCString.h:67
ECompType
Definition: Csocket.h:297
#define CS_STRING
Definition: Csocket.h:115
socklen_t GetSockAddrLen6()
Definition: Csocket.h:218
void SetPort(uint16_t iPort)
sets the port to listen on. Set to 0 to listen on a random port
Definition: Csocket.h:1288
void SetMaxConns(int i)
set max connections as called by accept()
Definition: Csocket.h:1296
virtual ~CSConnection()
Definition: Csocket.h:1181
CSMonitorFD()
Definition: Csocket.h:434
uint16_t GetPort() const
Definition: Csocket.h:1186
CSConnection(const CS_STRING &sHostname, uint16_t iPort, int iTimeout=60)
Definition: Csocket.h:1170
time_t GetLastCheckTimeout()
Definition: Csocket.h:1005
uint16_t m_iPort
Definition: Csocket.h:1223
timeval GetNextRun() const
returns the timestamp of the next estimated run time. Note that it may not run at this EXACT time...
Definition: Csocket.h:409
void SetPemPass(const CS_STRING &s)
set the pemfile pass
Definition: Csocket.h:1218
int GetTimeout() const
Definition: Csocket.h:1187
virtual ~TSocketManager()
Definition: Csocket.h:1545
int cs_sock_t
Definition: Csocket.h:144
const uint32_t CS_BLOCKSIZE
Definition: Csocket.h:293
options container to create a listener
Definition: Csocket.h:1247
bool InitCsocket()
This does all the csocket initialized inclusing InitSSL() and win32 specific initializations, only needs to be called once.
int GetErrno()
return the last known error as set by this class
Definition: Csocket.h:1450
CSSSListener(uint16_t iPort, const CS_STRING &sBindHost="")
Definition: Csocket.h:1333
virtual bool ConnectionFrom(const CS_STRING &sHost, uint16_t iPort)
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:970
const CS_STRING & GetPemLocation() const
Definition: Csocket.h:1282
bool IsClosed()
Definition: Csocket.h:821
void SetSkipConnect(bool b)
Definition: Csocket.h:1062
std::vector< CSMonitorFD * > m_vcMonitorFD
Definition: Csocket.h:518
this is the main cron job class
Definition: Csocket.h:369
uint64_t GetSelectTimeout()
Get the Select Timeout in MICROSECONDS ( 1000 == 1 millisecond )
Definition: Csocket.h:1453
bool IsEnabled() const
Definition: Csocket.h:470
ECONState GetConState() const
returns the current connection state
Definition: Csocket.h:1016
void SetHostname(const CS_STRING &s)
sets the hostname to connect to
Definition: Csocket.h:1198
void SetPemPass(const CS_STRING &s)
set the pemfile pass
Definition: Csocket.h:1308
virtual void Listening(const CS_STRING &sBindIP, uint16_t uPort)
called when type is LISTENER and the listening port is up and running
Definition: Csocket.h:977
Definition: Csocket.h:301
void SetSockName(const CS_STRING &sSockName)
sets the sock name for later reference (ie FindSockByName)
Definition: Csocket.h:1290
virtual void ReadData(const char *data, size_t len)
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:927
socklen_t GetSockAddrLen()
Definition: Csocket.h:214
virtual void ReadLine(const CS_STRING &sLine)
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:936
virtual void Disconnected()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:911
sockaddr_in6 * GetSockAddr6()
Definition: Csocket.h:219
void SetPort(uint16_t i)
sets the port to connect to
Definition: Csocket.h:1204
sockaddr wrapper.
Definition: Csocket.h:185
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
Definition: Csocket.h:1052
void __Perror(const CS_STRING &s, const char *pszFile, uint32_t iLineNo)
CSSSLConnection(const CS_STRING &sHostname, uint16_t iPort, int iTimeout=60)
Definition: Csocket.h:1235
bool HasReadLine() const
returns the value of m_bEnableReadLine, if ReadLine is enabled
Definition: Csocket.h:941
int GetAddrInfo(const CS_STRING &sHostname, Csock *pSock, CSSockAddr &csSockAddr)
backwards compatible wrapper around CGetAddrInfo and gethostbyname
CSockCommon()
Definition: Csocket.h:485
CSSockAddr()
Definition: Csocket.h:188
EDNSLType
Definition: Csocket.h:1029
const CS_STRING & GetPemPass() const
Definition: Csocket.h:1194
TSocketManager()
Definition: Csocket.h:1544
CSListener(uint16_t iPort, const CS_STRING &sBindHost="", bool bDetach=false)
Definition: Csocket.h:1255
void TFD_ZERO(fd_set *set)
wrappers for FD_SET and such to work in templates.
Definition: Csocket.h:338
bool GetIsSSL() const
Definition: Csocket.h:1188
bool GetDetach() const
Definition: Csocket.h:1272
EAFRequire
Definition: Csocket.h:200
int(* FPCertVerifyCB)(int, X509_STORE_CTX *)
Definition: Csocket.h:523
void SetBindHost(const CS_STRING &sBindHost)
Definition: Csocket.h:1027
void SetRequireClientCertFlags(uint32_t iRequireClientCertFlags)
bitwise flags, 0 means don&#39;t require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER...
Definition: Csocket.h:879
void SetCertVerifyCB(FPCertVerifyCB pFP)
Definition: Csocket.h:849
int m_iTimeout
Definition: Csocket.h:1224
const CS_STRING & GetSockName() const
Definition: Csocket.h:1184
in6_addr * GetAddr6()
Definition: Csocket.h:220
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1208
void TFD_SET(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:343
virtual void ConnectionRefused()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Csocket.h:987
ECloseType GetCloseType()
returns int of type to close
Definition: Csocket.h:820
Best class to use to interact with the sockets.
Definition: Csocket.h:1362
bool GetIsSSL() const
Definition: Csocket.h:1276
void DisableMonitor()
causes this monitor to be removed
Definition: Csocket.h:468
int GetMaxConns() const
returns the number of max pending connections when type is LISTENER
Definition: Csocket.h:1093
std::map< cs_sock_t, short > m_miiMonitorFDs
Definition: Csocket.h:473
void SetPemLocation(const CS_STRING &s)
set the location of the pemfile
Definition: Csocket.h:1216
ECheckType
this is a strict wrapper around C-api select(). Added in the event you need to do special work here ...
Definition: Csocket.h:1494
CS_STRING m_sPemPass
Definition: Csocket.h:1228
std::vector< CCron * > m_vcCrons
Definition: Csocket.h:517
int GetSockError()
Definition: Csocket.h:328
Class to tie sockets to for monitoring by Csocket at either the Csock or TSockManager.
Definition: Csocket.h:431
EMessages
Definition: Csocket.h:1372
Definition: Csocket.h:299
~CSCharBuffer()
Definition: Csocket.h:170
bool InitSSL(ECompType eCompressionType=CT_NONE)
You HAVE to call this in order to use the SSL library, calling InitCsocket() also calls this so unles...
void TFD_CLR(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:353
void SetRequiresClientCert(bool b)
set to true if require a client certificate (deprecated
Definition: Csocket.h:1310
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1294
uint32_t GetRequireClientCertFlags() const
Definition: Csocket.h:1284
sockaddr_in * GetSockAddr()
Definition: Csocket.h:215
const std::vector< CCron * > & GetCrons() const
returns a const reference to the crons associated to this socket
Definition: Csocket.h:492