ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
CIRCSock Class Reference

#include <IRCSock.h>

+ Inheritance diagram for CIRCSock:
+ Collaboration diagram for CIRCSock:

Public Types

enum  EChanModeArgs { ListArg = 0, HasArg = 1, ArgWhenSet = 2, NoArg = 3 }
 
enum  ETConn { OUTBOUND = 0, LISTENER = 1, INBOUND = 2 }
 
enum  EFRead {
  READ_EOF = 0, READ_ERR = -1, READ_EAGAIN = -2, READ_CONNREFUSED = -3,
  READ_TIMEDOUT = -4
}
 
enum  EFSelect { SEL_OK = 0, SEL_TIMEOUT = -1, SEL_EAGAIN = -2, SEL_ERR = -3 }
 
enum  ESSLMethod { SSL23 = 0, SSL2 = 2, SSL3 = 3, TLS1 = 4 }
 
enum  ECONState {
  CST_START = 0, CST_DNS = CST_START, CST_BINDVHOST = 1, CST_DESTDNS = 2,
  CST_CONNECT = 3, CST_CONNECTSSL = 4, CST_OK = 5
}
 
enum  ECloseType { CLT_DONT = 0, CLT_NOW = 1, CLT_AFTERWRITE = 2, CLT_DEREFERENCE = 3 }
 
enum  { TMO_READ = 1, TMO_WRITE = 2, TMO_ACCEPT = 4, TMO_ALL = TMO_READ|TMO_WRITE|TMO_ACCEPT }
 this timeout isn't just connection timeout, but also timeout on NOT recieving data, to disable this set it to 0 then the normal TCP timeout will apply (basically TCP will kill a dead connection) Set the timeout, set to 0 to never timeout More...
 
enum  EDNSLType { DNS_VHOST, DNS_DEST }
 

Public Member Functions

 CIRCSock (CIRCNetwork *pNetwork)
 
virtual ~CIRCSock ()
 
bool OnCTCPReply (CNick &Nick, CString &sMessage)
 
bool OnPrivCTCP (CNick &Nick, CString &sMessage)
 
bool OnChanCTCP (CNick &Nick, const CString &sChan, CString &sMessage)
 
bool OnGeneralCTCP (CNick &Nick, CString &sMessage)
 
bool OnPrivMsg (CNick &Nick, CString &sMessage)
 
bool OnChanMsg (CNick &Nick, const CString &sChan, CString &sMessage)
 
bool OnPrivNotice (CNick &Nick, CString &sMessage)
 
bool OnChanNotice (CNick &Nick, const CString &sChan, CString &sMessage)
 
bool OnServerCapAvailable (const CString &sCap)
 
virtual void ReadLine (const CString &sData)
 
virtual void Connected ()
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
virtual void Disconnected ()
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
virtual void ConnectionRefused ()
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
virtual void SockError (int iErrno, const CString &sDescription)
 
virtual void Timeout ()
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
virtual void ReachedMaxBuffer ()
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers this event. More...
 
void PutIRC (const CString &sLine)
 
void PutIRCQuick (const CString &sLine)
 Should be used for PONG only. More...
 
void ResetChans ()
 
void Quit (const CString &sQuitMsg="")
 
void PauseCap ()
 You can call this from CModule::OnServerCapResult to suspend sending other CAP requests and CAP END for a while. More...
 
void ResumeCap ()
 If you used PauseCap, call this when CAP negotiation and logging in should be resumed again. More...
 
void SetPass (const CString &s)
 
unsigned int GetMaxNickLen () const
 
EChanModeArgs GetModeType (unsigned char uMode) const
 
unsigned char GetPermFromMode (unsigned char uMode) const
 
const std::map< unsigned char,
EChanModeArgs > & 
GetChanModes () const
 
bool IsPermChar (const char c) const
 
bool IsPermMode (const char c) const
 
const CStringGetPerms () const
 
const CStringGetPermModes () const
 
CString GetNickMask () const
 
const CStringGetNick () const
 
const CStringGetPass () const
 
CIRCNetworkGetNetwork () const
 
bool HasNamesx () const
 
bool HasUHNames () const
 
const std::set< unsigned char > & GetUserModes () const
 
bool IsAuthed () const
 
bool IsCapAccepted (const CString &sCap)
 
const MCStringGetISupport () const
 
CString GetISupport (const CString &sKey, const CString &sDefault="") const
 
void ForwardRaw353 (const CString &sLine) const
 
void ForwardRaw353 (const CString &sLine, CClient *pClient) const
 
virtual int ConvertAddress (const struct sockaddr_storage *pAddr, socklen_t iAddrLen, CS_STRING &sIP, u_short *piPort)
 
virtual int ConvertAddress (const struct sockaddr_storage *pAddr, socklen_t iAddrLen, CS_STRING &sIP, uint16_t *piPort)
 retrieve name info (numeric only) for a given sockaddr_storage More...
 
void SetEncoding (const CString &)
 
virtual CsockGetSockObj (const CS_STRING &sHostname, uint16_t iPort)
 override this for accept sockets More...
 
virtual void Dereference ()
 in the event you pass this class to Copy(), you MUST call this function or on the original Csock other wise bad side effects will happen (double deletes, weird sock closures, etc) if you call this function and have not handled the internal pointers, other bad things can happend (memory leaks, fd leaks, etc) the whole point of this function is to allow this class to go away without shutting down More...
 
virtual void Copy (const Csock &cCopy)
 use this to copy a sock from one to the other, override it if you have special needs in the event of a copy More...
 
Csockoperator<< (const CS_STRING &s)
 
Csockoperator<< (std::ostream &(*io)(std::ostream &))
 
Csockoperator<< (int32_t i)
 
Csockoperator<< (uint32_t i)
 
Csockoperator<< (int64_t i)
 
Csockoperator<< (uint64_t i)
 
Csockoperator<< (float i)
 
Csockoperator<< (double i)
 
virtual bool Connect ()
 Create the connection, this is used by the socket manager, and shouldn't be called directly by the user. More...
 
virtual bool Listen (uint16_t iPort, int iMaxConns=SOMAXCONN, const CS_STRING &sBindHost="", uint32_t iTimeout=0, bool bDetach=false)
 Listens for connections. More...
 
virtual cs_sock_t Accept (CS_STRING &sHost, uint16_t &iRPort)
 Accept an inbound connection, this is used internally. More...
 
virtual bool AcceptSSL ()
 Accept an inbound SSL connection, this is used internally and called after Accept. More...
 
virtual bool SSLClientSetup ()
 This sets up the SSL Client, this is used internally. More...
 
virtual bool SSLServerSetup ()
 This sets up the SSL Server, this is used internally. More...
 
virtual bool ConnectSSL ()
 Create the SSL connection. More...
 
bool StartTLS ()
 start a TLS connection on an existing plain connection More...
 
virtual bool Write (const char *data, size_t len)
 Write data to the socket. More...
 
virtual bool Write (const CS_STRING &sData)
 Write a text string to the socket. More...
 
virtual cs_ssize_t Read (char *data, size_t len)
 Read from the socket Just pass in a pointer, big enough to hold len bytes. More...
 
CS_STRING GetLocalIP ()
 
CS_STRING GetRemoteIP ()
 
virtual bool IsConnected () const
 Tells you if the socket is connected. More...
 
virtual void SetIsConnected (bool b)
 Sets the sock, telling it its connected (internal use only) More...
 
cs_sock_tGetRSock ()
 returns a reference to the sock More...
 
void SetRSock (cs_sock_t iSock)
 
cs_sock_tGetWSock ()
 
void SetWSock (cs_sock_t iSock)
 
void SetSock (cs_sock_t iSock)
 
cs_sock_tGetSock ()
 
void CallSockError (int iErrno, const CS_STRING &sDescription="")
 calls SockError, if sDescription is not set, then strerror is used to pull out a default description More...
 
virtual void ResetTimer ()
 resets the time counter, this is virtual in the event you need an event on the timer being Reset More...
 
void PauseRead ()
 will pause/unpause reading on this socket More...
 
void UnPauseRead ()
 
bool IsReadPaused ()
 
void SetTimeout (int iTimeout, uint32_t iTimeoutType=TMO_ALL)
 Currently this uses the same value for all timeouts, and iTimeoutType merely states which event will be checked for timeouts. More...
 
void SetTimeoutType (uint32_t iTimeoutType)
 
int GetTimeout () const
 
uint32_t GetTimeoutType () const
 
virtual bool CheckTimeout (time_t iNow)
 returns true if the socket has timed out More...
 
virtual void PushBuff (const char *data, size_t len, bool bStartAtZero=false)
 pushes data up on the buffer, if a line is ready it calls the ReadLine event More...
 
CS_STRINGGetInternalReadBuffer ()
 This gives access to the internal read buffer, if your not going to use ReadLine(), then you may want to clear this out (if its binary data and not many '\n') More...
 
CS_STRINGGetInternalWriteBuffer ()
 This gives access to the internal write buffer. More...
 
void SetMaxBufferThreshold (uint32_t iThreshold)
 sets the max buffered threshold when EnableReadLine() is enabled More...
 
uint32_t GetMaxBufferThreshold () const
 
int GetType () const
 Returns the connection type from enum eConnType. More...
 
void SetType (int iType)
 
const CS_STRINGGetSockName () const
 Returns a reference to the socket name. More...
 
void SetSockName (const CS_STRING &sName)
 
const CS_STRINGGetHostName () const
 Returns a reference to the host name. More...
 
void SetHostName (const CS_STRING &sHostname)
 
uint64_t GetStartTime () const
 Gets the starting time of this socket. More...
 
void ResetStartTime ()
 Resets the start time. More...
 
uint64_t GetBytesRead () const
 Gets the amount of data read during the existence of the socket. More...
 
void ResetBytesRead ()
 
uint64_t GetBytesWritten () const
 Gets the amount of data written during the existence of the socket. More...
 
void ResetBytesWritten ()
 
double GetAvgRead (uint64_t iSample=1000)
 Get Avg Read Speed in sample milliseconds (default is 1000 milliseconds or 1 second) More...
 
double GetAvgWrite (uint64_t iSample=1000)
 Get Avg Write Speed in sample milliseconds (default is 1000 milliseconds or 1 second) More...
 
uint16_t GetRemotePort ()
 Returns the remote port. More...
 
uint16_t GetLocalPort ()
 Returns the local port. More...
 
uint16_t GetPort ()
 Returns the port. More...
 
void SetPort (uint16_t iPort)
 
void Close (ECloseType eCloseType=CLT_NOW)
 just mark us as closed, the parent can pick it up More...
 
ECloseType GetCloseType ()
 returns int of type to close More...
 
bool IsClosed ()
 
void NonBlockingIO ()
 Use this to change your fd's to blocking or none blocking. More...
 
bool GetSSL ()
 Return true if this socket is using ssl. Note this does not mean the SSL state is finished, but simply that its configured to use ssl. More...
 
void SetSSL (bool b)
 
void SetCipher (const CS_STRING &sCipher)
 Set the cipher type ( openssl cipher [to see ciphers available] ) More...
 
const CS_STRINGGetCipher ()
 
void SetPemLocation (const CS_STRING &sPemFile)
 Set the pem file location. More...
 
const CS_STRINGGetPemLocation ()
 
void SetPemPass (const CS_STRING &sPassword)
 
const CS_STRINGGetPemPass () const
 
void SetSSLMethod (int iMethod)
 Set the SSL method type. More...
 
int GetSSLMethod ()
 
void SetSSLObject (SSL *ssl)
 
void SetCTXObject (SSL_CTX *sslCtx)
 
SSL_SESSION * GetSSLSession ()
 
void SetCertVerifyCB (FPCertVerifyCB pFP)
 
bool HasWriteBuffer () const
 Get the send buffer. More...
 
void ClearWriteBuffer ()
 
bool SslIsEstablished ()
 is SSL_accept finished ? is the ssl properly finished (from write no error) More...
 
bool ConnectInetd (bool bIsSSL=false, const CS_STRING &sHostname="")
 Use this to bind this socket to inetd. More...
 
bool ConnectFD (int iReadFD, int iWriteFD, const CS_STRING &sName, bool bIsSSL=false, ETConn eDirection=INBOUND)
 Tie this guy to an existing real file descriptor. More...
 
X509 * GetX509 ()
 Get the peer's X509 cert. More...
 
CS_STRING GetPeerPubKey ()
 Returns the peer's public key. More...
 
long GetPeerFingerprint (CS_STRING &sFP)
 Returns the peer's certificate finger print. More...
 
uint32_t GetRequireClientCertFlags ()
 
void SetRequiresClientCert (bool bRequiresCert)
 legacy, deprecated More...
 
void SetRequireClientCertFlags (uint32_t iRequireClientCertFlags)
 bitwise flags, 0 means don't require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER_CERT will cause the connection to fail if no cert More...
 
virtual void SetParentSockName (const CS_STRING &sParentName)
 Set The INBOUND Parent sockname. More...
 
const CS_STRINGGetParentSockName ()
 
virtual void SetRate (uint32_t iBytes, uint64_t iMilliseconds)
 sets the rate at which we can send data More...
 
uint32_t GetRateBytes ()
 
uint64_t GetRateTime ()
 
virtual void ReadData (const char *data, size_t len)
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
virtual void ReadLine (const CS_STRING &sLine)
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
void EnableReadLine ()
 set the value of m_bEnableReadLine to true, we don't want to store a buffer for ReadLine, unless we want it More...
 
void DisableReadLine ()
 
bool HasReadLine () const
 returns the value of m_bEnableReadLine, if ReadLine is enabled More...
 
virtual void SockError (int iErrno, const CS_STRING &sDescription)
 A sock error occured event. More...
 
virtual bool ConnectionFrom (const CS_STRING &sHost, uint16_t iPort)
 Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks. More...
 
virtual void Listening (const CS_STRING &sBindIP, uint16_t uPort)
 called when type is LISTENER and the listening port is up and running More...
 
virtual void ReadPaused ()
 This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused. More...
 
virtual void SSLFinishSetup (SSL *pSSL)
 Gets called immediatly after the m_ssl member is setup and initialized, useful if you need to assign anything to this ssl session via SSL_set_ex_data. More...
 
time_t GetTimeSinceLastDataTransaction (time_t iNow=0)
 return how long it has been (in seconds) since the last read or successful write More...
 
time_t GetLastCheckTimeout ()
 
time_t GetNextCheckTimeout (time_t iNow=0)
 Returns the time when CheckTimeout() should be called next. More...
 
virtual int GetPending ()
 return the data imediatly ready for read More...
 
ECONState GetConState () const
 returns the current connection state More...
 
void SetConState (ECONState eState)
 sets the connection state to eState More...
 
bool CreateSocksFD ()
 grabs fd's for the sockets More...
 
void CloseSocksFD ()
 puts the socks back to the state they were prior to calling CreateSocksFD More...
 
const CS_STRINGGetBindHost () const
 
void SetBindHost (const CS_STRING &sBindHost)
 
int DNSLookup (EDNSLType eDNSLType)
 dns lookup More...
 
bool SetupVHost ()
 this is only used on outbound connections, listeners bind in a different spot More...
 
bool GetIPv6 () const
 
void SetIPv6 (bool b)
 
void SetAFRequire (CSSockAddr::EAFRequire iAFRequire)
 
bool AllowWrite (uint64_t &iNOW) const
 returns true if this socket can write its data, primarily used with rate shaping, initialize iNOW to 0 and it sets it on the first call More...
 
void SetSkipConnect (bool b)
 
virtual int GetAddrInfo (const CS_STRING &sHostname, CSSockAddr &csSockAddr)
 override this call with your own DNS lookup method if you have one. More...
 
int GetMaxConns () const
 returns the number of max pending connections when type is LISTENER More...
 
void CleanupCrons ()
 
void CleanupFDMonitors ()
 
const std::vector< CCron * > & GetCrons () const
 returns a const reference to the crons associated to this socket More...
 
virtual void Cron ()
 This has a garbage collecter, and is used internall to call the jobs. More...
 
virtual void AddCron (CCron *pcCron)
 insert a newly created cron More...
 
virtual void DelCron (const CS_STRING &sName, bool bDeleteAll=true, bool bCaseSensitive=true)
 deletes a cron by name More...
 
virtual void DelCron (uint32_t iPos)
 delete cron by idx More...
 
virtual void DelCronByAddr (CCron *pcCron)
 delete cron by address More...
 
void CheckFDs (const std::map< cs_sock_t, short > &miiReadyFds)
 
void AssignFDs (std::map< cs_sock_t, short > &miiReadyFds, struct timeval *tvtimeout)
 
void MonitorFD (CSMonitorFD *pMonitorFD)
 add an FD set to monitor More...
 

Static Public Member Functions

static bool IsFloodProtected (double fRate)
 

Protected Attributes

bool m_bAuthed
 
bool m_bNamesx
 
bool m_bUHNames
 
CString m_sPerms
 
CString m_sPermModes
 
std::set< unsigned char > m_scUserModes
 
std::map< unsigned char,
EChanModeArgs
m_mueChanModes
 
CIRCNetworkm_pNetwork
 
CNick m_Nick
 
CString m_sPass
 
std::map< CString, CChan * > m_msChans
 
unsigned int m_uMaxNickLen
 
unsigned int m_uCapPaused
 
SCString m_ssAcceptedCaps
 
SCString m_ssPendingCaps
 
time_t m_lastCTCP
 
unsigned int m_uNumCTCP
 
MCString m_mISupport
 
std::deque< CStringm_vsSendQueue
 
short int m_iSendsAllowed
 
unsigned short int m_uFloodBurst
 
double m_fFloodRate
 
bool m_bFloodProtection
 
std::vector< CCron * > m_vcCrons
 
std::vector< CSMonitorFD * > m_vcMonitorFD
 

Static Protected Attributes

static const time_t m_uCTCPFloodTime
 
static const unsigned int m_uCTCPFloodCount
 

Friends

class CIRCFloodTimer
 

Member Enumeration Documentation

anonymous enum
inherited

this timeout isn't just connection timeout, but also timeout on NOT recieving data, to disable this set it to 0 then the normal TCP timeout will apply (basically TCP will kill a dead connection) Set the timeout, set to 0 to never timeout

Enumerator
TMO_READ 
TMO_WRITE 
TMO_ACCEPT 
TMO_ALL 
Enumerator
ListArg 
HasArg 
ArgWhenSet 
NoArg 
enum Csock::ECloseType
inherited
Enumerator
CLT_DONT 

don't close DER

CLT_NOW 

close immediatly

CLT_AFTERWRITE 

close after finishing writing the buffer

CLT_DEREFERENCE 

used after copy in Csock::Dereference() to cleanup a sock thats being shutdown

enum Csock::ECONState
inherited
Enumerator
CST_START 
CST_DNS 
CST_BINDVHOST 
CST_DESTDNS 
CST_CONNECT 
CST_CONNECTSSL 
CST_OK 
enum Csock::EDNSLType
inherited
Enumerator
DNS_VHOST 

this lookup is for the vhost bind

DNS_DEST 

this lookup is for the destination address

enum Csock::EFRead
inherited
Enumerator
READ_EOF 

End Of File, done reading.

READ_ERR 

Error on the socket, socket closed, done reading.

READ_EAGAIN 

Try to get data again.

READ_CONNREFUSED 

Connection Refused.

READ_TIMEDOUT 

Connection timed out.

enum Csock::EFSelect
inherited
Enumerator
SEL_OK 

Select passed ok.

SEL_TIMEOUT 

Select timed out.

SEL_EAGAIN 

Select wants you to try again.

SEL_ERR 

Select recieved an error.

enum Csock::ESSLMethod
inherited
Enumerator
SSL23 
SSL2 
SSL3 
TLS1 
enum Csock::ETConn
inherited
Enumerator
OUTBOUND 

outbound connection

LISTENER 

a socket accepting connections

INBOUND 

an inbound connection, passed from LISTENER

Constructor & Destructor Documentation

CIRCSock::CIRCSock ( CIRCNetwork pNetwork)
virtual CIRCSock::~CIRCSock ( )
virtual

Member Function Documentation

virtual cs_sock_t Csock::Accept ( CS_STRING sHost,
uint16_t &  iRPort 
)
virtualinherited

Accept an inbound connection, this is used internally.

virtual bool Csock::AcceptSSL ( )
virtualinherited

Accept an inbound SSL connection, this is used internally and called after Accept.

virtual void CSockCommon::AddCron ( CCron pcCron)
virtualinherited

insert a newly created cron

bool Csock::AllowWrite ( uint64_t &  iNOW) const
inherited

returns true if this socket can write its data, primarily used with rate shaping, initialize iNOW to 0 and it sets it on the first call

void CSockCommon::AssignFDs ( std::map< cs_sock_t, short > &  miiReadyFds,
struct timeval *  tvtimeout 
)
inherited
void Csock::CallSockError ( int  iErrno,
const CS_STRING sDescription = "" 
)
inherited

calls SockError, if sDescription is not set, then strerror is used to pull out a default description

Parameters
iErrnothe errno to send
sDescriptionthe description of the error that occurred
void CSockCommon::CheckFDs ( const std::map< cs_sock_t, short > &  miiReadyFds)
inherited
virtual bool Csock::CheckTimeout ( time_t  iNow)
virtualinherited

returns true if the socket has timed out

void CSockCommon::CleanupCrons ( )
inherited
void CSockCommon::CleanupFDMonitors ( )
inherited
void Csock::ClearWriteBuffer ( )
inherited
void Csock::Close ( ECloseType  eCloseType = CLT_NOW)
inherited

just mark us as closed, the parent can pick it up

Referenced by CExecSock::Kill().

void Csock::CloseSocksFD ( )
inherited

puts the socks back to the state they were prior to calling CreateSocksFD

virtual bool Csock::Connect ( )
virtualinherited

Create the connection, this is used by the socket manager, and shouldn't be called directly by the user.

Returns
true on success
virtual void CIRCSock::Connected ( )
virtual

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

Connected event

Reimplemented from Csock.

bool Csock::ConnectFD ( int  iReadFD,
int  iWriteFD,
const CS_STRING sName,
bool  bIsSSL = false,
ETConn  eDirection = INBOUND 
)
inherited

Tie this guy to an existing real file descriptor.

Referenced by CExecSock::Execute().

bool Csock::ConnectInetd ( bool  bIsSSL = false,
const CS_STRING sHostname = "" 
)
inherited

Use this to bind this socket to inetd.

virtual bool Csock::ConnectionFrom ( const CS_STRING sHost,
uint16_t  iPort 
)
inlinevirtualinherited

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

Incoming Connection Event return false and the connection will fail default returns true

virtual void CIRCSock::ConnectionRefused ( )
virtual

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

Connection Refused Event

Reimplemented from Csock.

virtual bool Csock::ConnectSSL ( )
virtualinherited

Create the SSL connection.

Returns
true on success

This is used by the socket manager, and shouldn't be called directly by the user.

virtual int CZNCSock::ConvertAddress ( const struct sockaddr_storage *  pAddr,
socklen_t  iAddrLen,
CS_STRING sIP,
u_short *  piPort 
)
virtualinherited
virtual int Csock::ConvertAddress ( const struct sockaddr_storage *  pAddr,
socklen_t  iAddrLen,
CS_STRING sIP,
uint16_t *  piPort 
)
virtualinherited

retrieve name info (numeric only) for a given sockaddr_storage

Parameters
pAddrthe sockaddr_storage
iAddrLenthe length
sIPfilled with the IP from getnameinfo
piPortif not null, filled with the port
Returns
0 on success.

In the event you want to do additional work before or after getnameinfo is called, you can override this and do just that. One example is in the event that an ipv6 ip is a mapped ipv4 mapped, you can check like so.

  • if( pAddr->ss_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED( &(((const struct sockaddr_in6 *)pAddr)->sin6_addr ) )
virtual void Csock::Copy ( const Csock cCopy)
virtualinherited

use this to copy a sock from one to the other, override it if you have special needs in the event of a copy

bool Csock::CreateSocksFD ( )
inherited

grabs fd's for the sockets

virtual void CSockCommon::Cron ( )
virtualinherited

This has a garbage collecter, and is used internall to call the jobs.

virtual void CSockCommon::DelCron ( const CS_STRING sName,
bool  bDeleteAll = true,
bool  bCaseSensitive = true 
)
virtualinherited

deletes a cron by name

Parameters
sNamethe name of the cron
bDeleteAlldelete all crons that match sName
bCaseSensitiveuse strcmp or strcasecmp
virtual void CSockCommon::DelCron ( uint32_t  iPos)
virtualinherited

delete cron by idx

virtual void CSockCommon::DelCronByAddr ( CCron pcCron)
virtualinherited

delete cron by address

virtual void Csock::Dereference ( )
virtualinherited

in the event you pass this class to Copy(), you MUST call this function or on the original Csock other wise bad side effects will happen (double deletes, weird sock closures, etc) if you call this function and have not handled the internal pointers, other bad things can happend (memory leaks, fd leaks, etc) the whole point of this function is to allow this class to go away without shutting down

void Csock::DisableReadLine ( )
inherited
virtual void CIRCSock::Disconnected ( )
virtual

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

Disconnected event

Reimplemented from Csock.

int Csock::DNSLookup ( EDNSLType  eDNSLType)
inherited

dns lookup

See Also
EDNSLType
Returns
0 for success, EAGAIN to check back again (same arguments as before), ETIMEDOUT on failure
void Csock::EnableReadLine ( )
inherited

set the value of m_bEnableReadLine to true, we don't want to store a buffer for ReadLine, unless we want it

Referenced by CClient::CClient().

void CIRCSock::ForwardRaw353 ( const CString sLine) const
void CIRCSock::ForwardRaw353 ( const CString sLine,
CClient pClient 
) const
virtual int Csock::GetAddrInfo ( const CS_STRING sHostname,
CSSockAddr csSockAddr 
)
virtualinherited

override this call with your own DNS lookup method if you have one.

By default this function is blocking

Parameters
sHostnamethe hostname to resolve
csSockAddrthe destination sock address info
See Also
CSSockAddr
Returns
0 on success, ETIMEDOUT if no lookup was found, EAGAIN if you should check again later for an answer
double Csock::GetAvgRead ( uint64_t  iSample = 1000)
inherited

Get Avg Read Speed in sample milliseconds (default is 1000 milliseconds or 1 second)

double Csock::GetAvgWrite ( uint64_t  iSample = 1000)
inherited

Get Avg Write Speed in sample milliseconds (default is 1000 milliseconds or 1 second)

const CS_STRING& Csock::GetBindHost ( ) const
inlineinherited
uint64_t Csock::GetBytesRead ( ) const
inherited

Gets the amount of data read during the existence of the socket.

uint64_t Csock::GetBytesWritten ( ) const
inherited

Gets the amount of data written during the existence of the socket.

const std::map<unsigned char, EChanModeArgs>& CIRCSock::GetChanModes ( ) const
inline

References m_mueChanModes.

const CS_STRING& Csock::GetCipher ( )
inherited
ECloseType Csock::GetCloseType ( )
inlineinherited

returns int of type to close

See Also
ECloseType
ECONState Csock::GetConState ( ) const
inlineinherited

returns the current connection state

const std::vector<CCron *>& CSockCommon::GetCrons ( ) const
inlineinherited

returns a const reference to the crons associated to this socket

const CS_STRING& Csock::GetHostName ( ) const
inherited

Returns a reference to the host name.

CS_STRING& Csock::GetInternalReadBuffer ( )
inherited

This gives access to the internal read buffer, if your not going to use ReadLine(), then you may want to clear this out (if its binary data and not many '\n')

CS_STRING& Csock::GetInternalWriteBuffer ( )
inherited

This gives access to the internal write buffer.

If you want to check if the send queue fills up, check here.

bool Csock::GetIPv6 ( ) const
inlineinherited
const MCString& CIRCSock::GetISupport ( ) const
inline

References m_mISupport.

CString CIRCSock::GetISupport ( const CString sKey,
const CString sDefault = "" 
) const
time_t Csock::GetLastCheckTimeout ( )
inlineinherited
CS_STRING Csock::GetLocalIP ( )
inherited
uint16_t Csock::GetLocalPort ( )
inherited

Returns the local port.

uint32_t Csock::GetMaxBufferThreshold ( ) const
inherited
int Csock::GetMaxConns ( ) const
inlineinherited

returns the number of max pending connections when type is LISTENER

unsigned int CIRCSock::GetMaxNickLen ( ) const
inline

References m_uMaxNickLen.

EChanModeArgs CIRCSock::GetModeType ( unsigned char  uMode) const
CIRCNetwork* CIRCSock::GetNetwork ( ) const
inline

References m_pNetwork.

time_t Csock::GetNextCheckTimeout ( time_t  iNow = 0)
inherited

Returns the time when CheckTimeout() should be called next.

const CString& CIRCSock::GetNick ( ) const
inline

References CNick::GetNick(), and m_Nick.

CString CIRCSock::GetNickMask ( ) const
inline

References CNick::GetNickMask(), and m_Nick.

const CS_STRING& Csock::GetParentSockName ( )
inherited
const CString& CIRCSock::GetPass ( ) const
inline

References m_sPass.

long Csock::GetPeerFingerprint ( CS_STRING sFP)
inherited

Returns the peer's certificate finger print.

CS_STRING Csock::GetPeerPubKey ( )
inherited

Returns the peer's public key.

const CS_STRING& Csock::GetPemLocation ( )
inherited
const CS_STRING& Csock::GetPemPass ( ) const
inherited
virtual int Csock::GetPending ( )
virtualinherited

return the data imediatly ready for read

unsigned char CIRCSock::GetPermFromMode ( unsigned char  uMode) const
const CString& CIRCSock::GetPermModes ( ) const
inline

References m_sPermModes.

Referenced by IsPermMode().

const CString& CIRCSock::GetPerms ( ) const
inline

References m_sPerms.

Referenced by IsPermChar().

uint16_t Csock::GetPort ( )
inherited

Returns the port.

uint32_t Csock::GetRateBytes ( )
inherited
uint64_t Csock::GetRateTime ( )
inherited
CS_STRING Csock::GetRemoteIP ( )
inherited
uint16_t Csock::GetRemotePort ( )
inherited

Returns the remote port.

uint32_t Csock::GetRequireClientCertFlags ( )
inherited
cs_sock_t& Csock::GetRSock ( )
inherited

returns a reference to the sock

Referenced by CExecSock::~CExecSock().

cs_sock_t& Csock::GetSock ( )
inherited
const CS_STRING& Csock::GetSockName ( ) const
inherited

Returns a reference to the socket name.

virtual Csock* Csock::GetSockObj ( const CS_STRING sHostname,
uint16_t  iPort 
)
virtualinherited

override this for accept sockets

bool Csock::GetSSL ( )
inherited

Return true if this socket is using ssl. Note this does not mean the SSL state is finished, but simply that its configured to use ssl.

int Csock::GetSSLMethod ( )
inherited
SSL_SESSION* Csock::GetSSLSession ( )
inherited
uint64_t Csock::GetStartTime ( ) const
inherited

Gets the starting time of this socket.

int Csock::GetTimeout ( ) const
inherited
uint32_t Csock::GetTimeoutType ( ) const
inherited
time_t Csock::GetTimeSinceLastDataTransaction ( time_t  iNow = 0)
inherited

return how long it has been (in seconds) since the last read or successful write

int Csock::GetType ( ) const
inherited

Returns the connection type from enum eConnType.

const std::set<unsigned char>& CIRCSock::GetUserModes ( ) const
inline

References m_scUserModes.

cs_sock_t& Csock::GetWSock ( )
inherited

Referenced by CExecSock::~CExecSock().

X509* Csock::GetX509 ( )
inherited

Get the peer's X509 cert.

bool CIRCSock::HasNamesx ( ) const
inline

References m_bNamesx.

bool Csock::HasReadLine ( ) const
inlineinherited

returns the value of m_bEnableReadLine, if ReadLine is enabled

bool CIRCSock::HasUHNames ( ) const
inline

References m_bUHNames.

bool Csock::HasWriteBuffer ( ) const
inherited

Get the send buffer.

bool CIRCSock::IsAuthed ( ) const
inline

References m_bAuthed.

bool CIRCSock::IsCapAccepted ( const CString sCap)
inline

References m_ssAcceptedCaps.

bool Csock::IsClosed ( )
inlineinherited
virtual bool Csock::IsConnected ( ) const
virtualinherited

Tells you if the socket is connected.

static bool CIRCSock::IsFloodProtected ( double  fRate)
static
bool CIRCSock::IsPermChar ( const char  c) const
inline

References GetPerms().

bool CIRCSock::IsPermMode ( const char  c) const
inline

References GetPermModes().

bool Csock::IsReadPaused ( )
inherited
virtual bool Csock::Listen ( uint16_t  iPort,
int  iMaxConns = SOMAXCONN,
const CS_STRING sBindHost = "",
uint32_t  iTimeout = 0,
bool  bDetach = false 
)
virtualinherited

Listens for connections.

Parameters
iPortthe port to listen on
iMaxConnsthe maximum amount of pending connections to allow
sBindHostthe vhost on which to listen
iTimeoutif no connections come in by this timeout, the listener is closed
bDetachdon't block waiting for port to come up, instead detach and return immediately
virtual void Csock::Listening ( const CS_STRING sBindIP,
uint16_t  uPort 
)
inlinevirtualinherited

called when type is LISTENER and the listening port is up and running

Parameters
sBindIPthe IP that is being bound to. Empty if no bind restriction
uPortthe listening port
void CSockCommon::MonitorFD ( CSMonitorFD pMonitorFD)
inlineinherited

add an FD set to monitor

void Csock::NonBlockingIO ( )
inherited

Use this to change your fd's to blocking or none blocking.

bool CIRCSock::OnChanCTCP ( CNick Nick,
const CString sChan,
CString sMessage 
)
bool CIRCSock::OnChanMsg ( CNick Nick,
const CString sChan,
CString sMessage 
)
bool CIRCSock::OnChanNotice ( CNick Nick,
const CString sChan,
CString sMessage 
)
bool CIRCSock::OnCTCPReply ( CNick Nick,
CString sMessage 
)
bool CIRCSock::OnGeneralCTCP ( CNick Nick,
CString sMessage 
)
bool CIRCSock::OnPrivCTCP ( CNick Nick,
CString sMessage 
)
bool CIRCSock::OnPrivMsg ( CNick Nick,
CString sMessage 
)
bool CIRCSock::OnPrivNotice ( CNick Nick,
CString sMessage 
)
bool CIRCSock::OnServerCapAvailable ( const CString sCap)
Csock& Csock::operator<< ( const CS_STRING s)
inherited
Csock& Csock::operator<< ( std::ostream &(*)(std::ostream &)  io)
inherited
Csock& Csock::operator<< ( int32_t  i)
inherited
Csock& Csock::operator<< ( uint32_t  i)
inherited
Csock& Csock::operator<< ( int64_t  i)
inherited
Csock& Csock::operator<< ( uint64_t  i)
inherited
Csock& Csock::operator<< ( float  i)
inherited
Csock& Csock::operator<< ( double  i)
inherited
void CIRCSock::PauseCap ( )

You can call this from CModule::OnServerCapResult to suspend sending other CAP requests and CAP END for a while.

Each call to PauseCap should be balanced with a call to ResumeCap.

void Csock::PauseRead ( )
inherited

will pause/unpause reading on this socket

virtual void Csock::PushBuff ( const char *  data,
size_t  len,
bool  bStartAtZero = false 
)
virtualinherited

pushes data up on the buffer, if a line is ready it calls the ReadLine event

void CIRCSock::PutIRC ( const CString sLine)
void CIRCSock::PutIRCQuick ( const CString sLine)

Should be used for PONG only.

void CIRCSock::Quit ( const CString sQuitMsg = "")
virtual void CIRCSock::ReachedMaxBuffer ( )
virtual

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers this event.

Either Override it and do nothing, or SetMaxBufferThreshold() This event will only get called if m_bEnableReadLine is enabled

Reimplemented from Csock.

virtual cs_ssize_t Csock::Read ( char *  data,
size_t  len 
)
virtualinherited

Read from the socket Just pass in a pointer, big enough to hold len bytes.

Parameters
datathe buffer to read into
lenthe size of the buffer
Returns
Returns READ_EOF for EOF Returns READ_ERR for ERROR Returns READ_EAGAIN for Try Again ( EAGAIN ) Returns READ_CONNREFUSED for connection refused Returns READ_TIMEDOUT for a connection that timed out at the TCP level Otherwise returns the bytes read into data
virtual void Csock::ReadData ( const char *  data,
size_t  len 
)
inlinevirtualinherited

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

Ready to read data event

Reimplemented in CPySocket, CPerlSocket, and CHTTPSock.

virtual void CIRCSock::ReadLine ( const CString sData)
virtual
virtual void Csock::ReadLine ( const CS_STRING sLine)
inlinevirtualinherited

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

With ReadLine, if your not going to use it IE a data stream,

See Also
EnableReadLine()

Ready to Read a full line event. If encoding is provided, this is guaranteed to be UTF-8

virtual void Csock::ReadPaused ( )
inlinevirtualinherited

This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused.

void Csock::ResetBytesRead ( )
inherited
void Csock::ResetBytesWritten ( )
inherited
void CIRCSock::ResetChans ( )
void Csock::ResetStartTime ( )
inherited

Resets the start time.

virtual void Csock::ResetTimer ( )
virtualinherited

resets the time counter, this is virtual in the event you need an event on the timer being Reset

void CIRCSock::ResumeCap ( )

If you used PauseCap, call this when CAP negotiation and logging in should be resumed again.

void Csock::SetAFRequire ( CSSockAddr::EAFRequire  iAFRequire)
inlineinherited
void Csock::SetBindHost ( const CS_STRING sBindHost)
inlineinherited
void Csock::SetCertVerifyCB ( FPCertVerifyCB  pFP)
inlineinherited
void Csock::SetCipher ( const CS_STRING sCipher)
inherited

Set the cipher type ( openssl cipher [to see ciphers available] )

void Csock::SetConState ( ECONState  eState)
inlineinherited

sets the connection state to eState

void Csock::SetCTXObject ( SSL_CTX *  sslCtx)
inherited
void CZNCSock::SetEncoding ( const CString )
inlineinherited
void Csock::SetHostName ( const CS_STRING sHostname)
inherited
void Csock::SetIPv6 ( bool  b)
inlineinherited
virtual void Csock::SetIsConnected ( bool  b)
virtualinherited

Sets the sock, telling it its connected (internal use only)

void Csock::SetMaxBufferThreshold ( uint32_t  iThreshold)
inherited

sets the max buffered threshold when EnableReadLine() is enabled

Referenced by CClient::CClient().

virtual void Csock::SetParentSockName ( const CS_STRING sParentName)
virtualinherited

Set The INBOUND Parent sockname.

void CIRCSock::SetPass ( const CString s)
inline

References m_sPass.

void Csock::SetPemLocation ( const CS_STRING sPemFile)
inherited

Set the pem file location.

void Csock::SetPemPass ( const CS_STRING sPassword)
inherited
void Csock::SetPort ( uint16_t  iPort)
inherited
virtual void Csock::SetRate ( uint32_t  iBytes,
uint64_t  iMilliseconds 
)
virtualinherited

sets the rate at which we can send data

Parameters
iBytesthe amount of bytes we can write
iMillisecondsthe amount of time we have to rate to iBytes
void Csock::SetRequireClientCertFlags ( uint32_t  iRequireClientCertFlags)
inlineinherited

bitwise flags, 0 means don't require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER_CERT will cause the connection to fail if no cert

void Csock::SetRequiresClientCert ( bool  bRequiresCert)
inherited

legacy, deprecated

See Also
SetRequireClientCertFlags
void Csock::SetRSock ( cs_sock_t  iSock)
inherited

Referenced by CExecSock::~CExecSock().

void Csock::SetSkipConnect ( bool  b)
inlineinherited
void Csock::SetSock ( cs_sock_t  iSock)
inherited
void Csock::SetSockName ( const CS_STRING sName)
inherited
void Csock::SetSSL ( bool  b)
inherited
void Csock::SetSSLMethod ( int  iMethod)
inherited

Set the SSL method type.

void Csock::SetSSLObject ( SSL *  ssl)
inherited
void Csock::SetTimeout ( int  iTimeout,
uint32_t  iTimeoutType = TMO_ALL 
)
inherited

Currently this uses the same value for all timeouts, and iTimeoutType merely states which event will be checked for timeouts.

void Csock::SetTimeoutType ( uint32_t  iTimeoutType)
inherited
void Csock::SetType ( int  iType)
inherited
bool Csock::SetupVHost ( )
inherited

this is only used on outbound connections, listeners bind in a different spot

void Csock::SetWSock ( cs_sock_t  iSock)
inherited

Referenced by CExecSock::~CExecSock().

virtual void CIRCSock::SockError ( int  iErrno,
const CString sDescription 
)
virtual
virtual void Csock::SockError ( int  iErrno,
const CS_STRING sDescription 
)
inlinevirtualinherited

A sock error occured event.

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks

virtual bool Csock::SSLClientSetup ( )
virtualinherited

This sets up the SSL Client, this is used internally.

virtual void Csock::SSLFinishSetup ( SSL *  pSSL)
inlinevirtualinherited

Gets called immediatly after the m_ssl member is setup and initialized, useful if you need to assign anything to this ssl session via SSL_set_ex_data.

bool Csock::SslIsEstablished ( )
inherited

is SSL_accept finished ? is the ssl properly finished (from write no error)

virtual bool Csock::SSLServerSetup ( )
virtualinherited

This sets up the SSL Server, this is used internally.

bool Csock::StartTLS ( )
inherited

start a TLS connection on an existing plain connection

virtual void CIRCSock::Timeout ( )
virtual

Override these functions for an easy interface when using the Socket Manager Don't bother using these callbacks if you are using this class directly (without Socket Manager) as the Socket Manager calls most of these callbacks.

Sock Timed out event

Reimplemented from Csock.

void Csock::UnPauseRead ( )
inherited
virtual bool Csock::Write ( const char *  data,
size_t  len 
)
virtualinherited

Write data to the socket.

If not all of the data is sent, it will be stored on an internal buffer, and tried again with next call to Write if the socket is blocking, it will send everything, its ok to check ernno after this (nothing else is processed)

Parameters
datathe data to send
lenthe length of data
virtual bool Csock::Write ( const CS_STRING sData)
virtualinherited

Write a text string to the socket.

Encoding is used, if set

Parameters
sDatathe string to send; if encoding is provided, sData should be UTF-8 and will be encoded
See Also
Write( const char *, int )

Friends And Related Function Documentation

friend class CIRCFloodTimer
friend

Member Data Documentation

bool CIRCSock::m_bAuthed
protected

Referenced by IsAuthed().

bool CIRCSock::m_bFloodProtection
protected
bool CIRCSock::m_bNamesx
protected

Referenced by HasNamesx().

bool CIRCSock::m_bUHNames
protected

Referenced by HasUHNames().

double CIRCSock::m_fFloodRate
protected
short int CIRCSock::m_iSendsAllowed
protected
time_t CIRCSock::m_lastCTCP
protected
MCString CIRCSock::m_mISupport
protected

Referenced by GetISupport().

std::map<CString, CChan*> CIRCSock::m_msChans
protected
std::map<unsigned char, EChanModeArgs> CIRCSock::m_mueChanModes
protected

Referenced by GetChanModes().

CNick CIRCSock::m_Nick
protected

Referenced by GetNick(), and GetNickMask().

CIRCNetwork* CIRCSock::m_pNetwork
protected

Referenced by GetNetwork().

std::set<unsigned char> CIRCSock::m_scUserModes
protected

Referenced by GetUserModes().

CString CIRCSock::m_sPass
protected

Referenced by GetPass(), and SetPass().

CString CIRCSock::m_sPermModes
protected

Referenced by GetPermModes().

CString CIRCSock::m_sPerms
protected

Referenced by GetPerms().

SCString CIRCSock::m_ssAcceptedCaps
protected

Referenced by IsCapAccepted().

SCString CIRCSock::m_ssPendingCaps
protected
unsigned int CIRCSock::m_uCapPaused
protected
const unsigned int CIRCSock::m_uCTCPFloodCount
staticprotected
const time_t CIRCSock::m_uCTCPFloodTime
staticprotected
unsigned short int CIRCSock::m_uFloodBurst
protected
unsigned int CIRCSock::m_uMaxNickLen
protected

Referenced by GetMaxNickLen().

unsigned int CIRCSock::m_uNumCTCP
protected
std::vector<CCron *> CSockCommon::m_vcCrons
protectedinherited
std::vector<CSMonitorFD *> CSockCommon::m_vcMonitorFD
protectedinherited
std::deque<CString> CIRCSock::m_vsSendQueue
protected

The documentation for this class was generated from the following file: