KVIrc  4.9.2
DeveloperAPIs
Public Types | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
KviIrcSocket Class Reference

This class is the lowest level of the KVIrc networking stack. More...

#include <KviIrcSocket.h>

+ Inheritance diagram for KviIrcSocket:

Public Types

enum  SocketState {
  Idle, Connecting, ProxyLogin, ProxyHttpError,
  Connected, ProxyFinalV4, ProxyFinalV5, ProxyFinalHttp,
  ProxySelectAuthMethodV5, ProxyUserPassV5, SSLHandshake
}
 

Public Member Functions

void abort ()
 Aborts the connection. More...
 
void clearOutputQueue (bool bPrivateMessagesOnly)
 Clears the output queue. More...
 
KviConsoleWindowconsole ()
 Returns the console. More...
 
bool getLocalHostIp (QString &szIp, bool bIPv6)
 Gets the localhost IP. More...
 
unsigned int id ()
 Returns the id of the socket. More...
 
bool isConnected ()
 Returns true if the socket is connected. More...
 
 KviIrcSocket (KviIrcLink *pLink)
 Constructs the IRC socket object. More...
 
int lastError ()
 Returns the last error. More...
 
KviIrcLinklink ()
 Returns the link. More...
 
unsigned int outputQueueSize ()
 Returns the current size of the output queue. More...
 
unsigned int readBytes ()
 Returns the number of bytes read. More...
 
bool sendPacket (KviDataBuffer *pData)
 Returns true if the packet is sent to the socket. More...
 
unsigned int sentBytes ()
 Returns the number of bytes sent. More...
 
unsigned int sentPackets ()
 Returns the number of packets sent. More...
 
KviError::Code startConnection (KviIrcServer *pServer, KviProxy *pProxy=0, const char *pcBindAddress=0)
 Starts the connection. More...
 
SocketState state ()
 Returns the state of the socket. More...
 
bool usingSSL ()
 Returns true if the socket is a Secure Socket Layer (SSL) More...
 
 ~KviIrcSocket ()
 Destroys the IRC socket object. More...
 

Protected Slots

void connectionTimedOut ()
 Called when the connection timeouts. More...
 
void doSSLHandshake (int)
 Starts the SSL handshake. More...
 
void flushSendQueue ()
 Attempts to send as much as possible to the server. More...
 
void readData (int)
 Called when the read notifier is enabled. More...
 
void readHttpProxyErrorData (int)
 Called when the proxy read notifier encounters an error. More...
 
void readProxyData (int)
 Called when the proxy read notifier is enabled. More...
 
void writeNotifierFired (int)
 Called when the write notifier is enabled. More...
 

Protected Member Functions

void connectedToIrcServer ()
 Called when the connection to the irc server has been established. More...
 
void connectedToProxy ()
 Called when the connection to the proxy has been established. More...
 
void connectionEstablished ()
 Called when the connection has been established. More...
 
void free_msgEntry (KviIrcSocketMsgEntry *e)
 Removes the message entry. More...
 
void handleInvalidSocketRead (int iReadLength)
 Checks if the socket error is a transient error. More...
 
void linkUp ()
 Connection established. Sets the link up. More...
 
void proxyAuthUserPassV5 ()
 Starts the negotiation of user/pass for the proxy. More...
 
void proxyHandleHttpFinalReply (const char *pcBuffer, int iBufLen)
 Gets the final HTTP reply and handles it. More...
 
void proxyHandleV4FinalReply (unsigned char cReply)
 Gets the final SOCKSv4 reply and handles it. More...
 
void proxyHandleV5AuthReply (unsigned char cReply)
 Gets the authentication reply and handles it. More...
 
void proxyHandleV5FinalReply (unsigned char cReply)
 Gets the final SOCKSv5 reply and handles it. More...
 
void proxyHandleV5MethodReply (unsigned char cReply)
 Gets the method selection reply and handles it. More...
 
void proxyLoginHttp ()
 Called to login to an HTTP proxy. More...
 
void proxyLoginV4 ()
 Called to login to a SOCKSv4 proxy. More...
 
void proxyLoginV5 ()
 Called to login to a SOCKSv5 proxy. More...
 
void proxySendTargetDataV5 ()
 Sends the request details. More...
 
virtual void queue_insertMessage (KviIrcSocketMsgEntry *pMsg)
 Appends a KviIrcSocketMsgEntry to the tail of the message queue. More...
 
void queue_removeAllMessages ()
 Removes all messages from the queue. More...
 
bool queue_removeMessage ()
 Removes a message from the head of the queue. More...
 
void queue_removePrivateMessages ()
 Removes private messages from the queue. More...
 
void raiseError (KviError::Code eError)
 Raises an error. More...
 
virtual void reset ()
 Resets the connection. More...
 
bool sendRawData (const char *pcBuffer, int iBufLen)
 Sends raw data to the socket. More...
 
virtual void setState (SocketState state)
 Sets the state of the socket. More...
 

Protected Attributes

bool m_bInProcessData
 
KviError::Code m_eLastError
 
KviConsoleWindowm_pConsole
 
QTimer * m_pFlushTimer
 
KviIrcServerm_pIrcServer
 
KviIrcLinkm_pLink
 
KviProxym_pProxy
 
QSocketNotifier * m_pRsn
 
KviIrcSocketMsgEntrym_pSendQueueHead
 
KviIrcSocketMsgEntrym_pSendQueueTail
 
QTimer * m_pTimeoutTimer
 
QSocketNotifier * m_pWsn
 
kvi_socket_t m_sock
 
SocketState m_state
 
struct timeval m_tAntiFloodLastMessageTime
 
unsigned int m_uId
 
unsigned int m_uReadBytes
 
unsigned int m_uSentBytes
 
unsigned int m_uSentPackets
 

Private Member Functions

void outputProxyError (const QString &szMsg)
 Outputs a proxy error. More...
 
void outputProxyMessage (const QString &szMsg)
 Outputs a proxy message. More...
 
void outputSocketError (const QString &szMsg)
 Outputs a socket error. More...
 
void outputSocketMessage (const QString &szMsg)
 Outputs a socket message. More...
 
void outputSocketWarning (const QString &szMsg)
 Outputs a socket warning. More...
 
void outputSSLError (const QString &szMsg)
 Outputs a SSL error. More...
 
void outputSSLMessage (const QString &szMsg)
 Outputs a SSL message. More...
 

Detailed Description

This class is the lowest level of the KVIrc networking stack.

It sends and receives raw data packets from the underlying system socket. It should output only verbose "progress" messages.

Member Enumeration Documentation

Enumerator
Idle 

Socket idling

Connecting 

Socket connecting

ProxyLogin 

Socket loggin in to a proxy

ProxyHttpError 

Socket error on http proxy

Connected 

Socket connected

ProxyFinalV4 

Socket received the final proxy v4 reply

ProxyFinalV5 

Socket received the final proxy v5 reply

ProxyFinalHttp 

Socket received the final proxy http reply

ProxySelectAuthMethodV5 

Socket received v5 method select reply

ProxyUserPassV5 

Socket received user/pass reply

SSLHandshake 

Socket is doing the SSL handshake

Constructor & Destructor Documentation

KviIrcSocket::KviIrcSocket ( KviIrcLink pLink)
KviIrcSocket::~KviIrcSocket ( )

Destroys the IRC socket object.

References m_pFlushTimer, and reset().

Member Function Documentation

void KviIrcSocket::abort ( )

Aborts the connection.

Returns
void

References Connected, flushSendQueue(), m_state, KviError::OperationAborted, raiseError(), and reset().

Referenced by KviIrcLink::abort().

void KviIrcSocket::clearOutputQueue ( bool  bPrivateMessagesOnly)

Clears the output queue.

Parameters
bPrivateMessagesOnlyWhether to clear only private messages
Returns
void

References queue_removeAllMessages(), and queue_removePrivateMessages().

Referenced by KviIrcLink::clearOutputQueue().

void KviIrcSocket::connectedToIrcServer ( )
protected

Called when the connection to the irc server has been established.

Returns
void

References linkUp(), m_pIrcServer, and KviIrcServer::useSSL().

Referenced by connectionEstablished(), proxyHandleHttpFinalReply(), proxyHandleV4FinalReply(), and proxyHandleV5FinalReply().

void KviIrcSocket::connectedToProxy ( )
protected

Called when the connection to the proxy has been established.

Returns
void

References connect(), KviProxy::Http, m_pProxy, m_pRsn, m_sock, KviProxy::protocol(), ProxyLogin, proxyLoginHttp(), proxyLoginV4(), proxyLoginV5(), readProxyData(), setState(), and KviProxy::Socks5.

Referenced by connectionEstablished().

void KviIrcSocket::connectionEstablished ( )
protected

Called when the connection has been established.

If it's a proxy we need to perform the login operations, otherwise we're connected to the irc server

Returns
void

References connectedToIrcServer(), connectedToProxy(), KVI_INVALID_SOCKET, m_pProxy, and m_sock.

Referenced by writeNotifierFired().

void KviIrcSocket::connectionTimedOut ( )
protectedslot

Called when the connection timeouts.

Returns
void

References KviError::ConnectionTimedOut, raiseError(), and reset().

Referenced by startConnection().

KviConsoleWindow* KviIrcSocket::console ( )
inline

Returns the console.

Returns
KviConsoleWindow *
void KviIrcSocket::doSSLHandshake ( int  )
protectedslot
void KviIrcSocket::flushSendQueue ( )
protectedslot
void KviIrcSocket::free_msgEntry ( KviIrcSocketMsgEntry e)
protected

Removes the message entry.

Parameters
eThe entry
Returns
void

References KviMemory::free(), and _KviIrcSocketMsgEntry::pData.

Referenced by queue_removePrivateMessages().

bool KviIrcSocket::getLocalHostIp ( QString &  szIp,
bool  bIPv6 
)

Gets the localhost IP.

Parameters
szIpThe source IP address
bIPv6Whether to use IPv6 sockets
Returns
bool

References KviNetUtils::binaryIpToStringIp(), Connected, kvi_socket_getsockname(), m_sock, m_state, and KviRuntimeInfo::name().

Referenced by dcc_kvs_get_listen_ip_address().

void KviIrcSocket::handleInvalidSocketRead ( int  iReadLength)
protected

Checks if the socket error is a transient error.

If it is not a transient error it resets the socket and fires the appropriate event. Otherwise it does nothing.

Parameters
iReadLengthThe number of bytes read
Returns
void

References KVI_ASSERT, kvi_socket_error(), raiseError(), KviError::RemoteEndClosedConnection, reset(), and KviError::translateSystemError().

Referenced by readData(), readHttpProxyErrorData(), and readProxyData().

unsigned int KviIrcSocket::id ( )
inline

Returns the id of the socket.

Returns
unsigned int
bool KviIrcSocket::isConnected ( )
inline

Returns true if the socket is connected.

Returns
bool
int KviIrcSocket::lastError ( )
inline

Returns the last error.

Returns
int

Referenced by KviIrcLink::socketStateChange().

KviIrcLink* KviIrcSocket::link ( )
inline

Returns the link.

Returns
KviIrcLink *
void KviIrcSocket::linkUp ( )
protected

Connection established. Sets the link up.

Returns
void

References connect(), Connected, KVI_INVALID_SOCKET, m_pRsn, m_pWsn, m_sock, readData(), and setState().

Referenced by connectedToIrcServer(), and doSSLHandshake().

void KviIrcSocket::outputProxyError ( const QString &  szMsg)
private

Outputs a proxy error.

Parameters
szMsgThe message :)
Returns
void

References __tr2qs, KVI_OUT_SOCKETERROR, m_pConsole, and KviWindow::output().

Referenced by proxyHandleHttpFinalReply().

void KviIrcSocket::outputProxyMessage ( const QString &  szMsg)
private
unsigned int KviIrcSocket::outputQueueSize ( )

Returns the current size of the output queue.

Returns
unsigned int

References m_pSendQueueTail, and _KviIrcSocketMsgEntry::next_ptr.

Referenced by KviIrcLink::outputQueueSize().

void KviIrcSocket::outputSocketError ( const QString &  szMsg)
private

Outputs a socket error.

Parameters
szMsgThe message :)
Returns
void

References __tr2qs, KVI_OUT_SOCKETERROR, m_pConsole, and KviWindow::output().

Referenced by raiseError().

void KviIrcSocket::outputSocketMessage ( const QString &  szMsg)
private

Outputs a socket message.

Parameters
szMsgThe message :)
Returns
void

References __tr2qs, KVI_OUT_SOCKETMESSAGE, m_pConsole, and KviWindow::output().

Referenced by raiseError(), and startConnection().

void KviIrcSocket::outputSocketWarning ( const QString &  szMsg)
private

Outputs a socket warning.

Parameters
szMsgThe message :)
Returns
void

References __tr2qs, KVI_OUT_SOCKETWARNING, m_pConsole, and KviWindow::output().

Referenced by flushSendQueue(), and startConnection().

void KviIrcSocket::outputSSLError ( const QString &  szMsg)
private

Outputs a SSL error.

Parameters
szMsgThe message :)
Returns
void

References __tr2qs, KVI_OUT_SSL, m_pConsole, and KviWindow::output().

void KviIrcSocket::outputSSLMessage ( const QString &  szMsg)
private

Outputs a SSL message.

Parameters
szMsgThe message :)
Returns
void

References __tr2qs, KVI_OUT_SSL, m_pConsole, and KviWindow::output().

void KviIrcSocket::proxyAuthUserPassV5 ( )
protected

Starts the negotiation of user/pass for the proxy.

Returns
void

References m_pProxy, KviMemory::move(), KviProxy::pass(), KviProxy::passLen(), ProxyUserPassV5, sendRawData(), setState(), KviProxy::user(), and KviProxy::userLen().

Referenced by proxyHandleV5MethodReply().

void KviIrcSocket::proxyHandleHttpFinalReply ( const char *  pcBuffer,
int  iBufLen 
)
protected

Gets the final HTTP reply and handles it.

Parameters
pcBufferThe buffer containing the proxy reply
iBufLenSize of the buffer containing the proxy reply
Returns
void

References __tr2qs, _OUTPUT_VERBOSE, connect(), connectedToIrcServer(), KviCString::cutFromFirst(), KviWindow::decodeText(), KviCString::findFirstIdx(), kvi_strEqualCIN(), m_pConsole, m_pRsn, m_pWsn, m_sock, outputProxyError(), outputProxyMessage(), ProxyHttpError, KviCString::ptr(), readHttpProxyErrorData(), setState(), and KviCString::trim().

Referenced by readProxyData().

void KviIrcSocket::proxyHandleV4FinalReply ( unsigned char  cReply)
protected
void KviIrcSocket::proxyHandleV5AuthReply ( unsigned char  cReply)
protected

Gets the authentication reply and handles it.

Parameters
cReplyThe proxy reply
Returns
void

References __tr2qs, _OUTPUT_VERBOSE, outputProxyMessage(), KviError::ProxyAuthFailed, proxySendTargetDataV5(), raiseError(), and reset().

Referenced by readProxyData().

void KviIrcSocket::proxyHandleV5FinalReply ( unsigned char  cReply)
protected
void KviIrcSocket::proxyHandleV5MethodReply ( unsigned char  cReply)
protected

Gets the method selection reply and handles it.

Parameters
cReplyThe proxy reply
Returns
void

References __tr2qs, _OUTPUT_VERBOSE, outputProxyMessage(), proxyAuthUserPassV5(), KviError::ProxyNoAcceptableAuthMethod, proxySendTargetDataV5(), raiseError(), reset(), and KviError::UnrecognizedProxyReply.

Referenced by readProxyData().

void KviIrcSocket::proxyLoginHttp ( )
protected
void KviIrcSocket::proxyLoginV4 ( )
protected
void KviIrcSocket::proxyLoginV5 ( )
protected
void KviIrcSocket::proxySendTargetDataV5 ( )
protected
void KviIrcSocket::queue_insertMessage ( KviIrcSocketMsgEntry pMsg)
protectedvirtual

Appends a KviIrcSocketMsgEntry to the tail of the message queue.

The pMsg for this message is set to 0.

Parameters
pMsgThe message to append to the queue
Returns
void

References KVI_ASSERT, m_pSendQueueHead, m_pSendQueueTail, and _KviIrcSocketMsgEntry::next_ptr.

Referenced by sendPacket(), and sendRawData().

void KviIrcSocket::queue_removeAllMessages ( )
protected

Removes all messages from the queue.

Returns
void

References m_pSendQueueHead, and queue_removeMessage().

Referenced by clearOutputQueue(), and reset().

bool KviIrcSocket::queue_removeMessage ( )
protected

Removes a message from the head of the queue.

Returns
bool

References KviMemory::free(), KVI_ASSERT, m_pSendQueueHead, m_pSendQueueTail, _KviIrcSocketMsgEntry::next_ptr, and _KviIrcSocketMsgEntry::pData.

Referenced by flushSendQueue(), and queue_removeAllMessages().

void KviIrcSocket::queue_removePrivateMessages ( )
protected
void KviIrcSocket::raiseError ( KviError::Code  eError)
protected
unsigned int KviIrcSocket::readBytes ( )
inline

Returns the number of bytes read.

Returns
unsigned int
void KviIrcSocket::readData ( int  )
protectedslot
void KviIrcSocket::readHttpProxyErrorData ( int  )
protectedslot

Called when the proxy read notifier encounters an error.

Returns
void

References KviWindow::decodeText(), handleInvalidSocketRead(), kvi_socket_recv(), m_pConsole, m_sock, and outputProxyMessage().

Referenced by proxyHandleHttpFinalReply().

void KviIrcSocket::readProxyData ( int  )
protectedslot
void KviIrcSocket::reset ( )
protectedvirtual
bool KviIrcSocket::sendPacket ( KviDataBuffer pData)

Returns true if the packet is sent to the socket.

Parameters
pDataThe source data packet
Returns
bool

References KviMemory::allocate(), Connected, flushSendQueue(), m_bInProcessData, m_state, _KviIrcSocketMsgEntry::pData, and queue_insertMessage().

Referenced by KviIrcLink::sendPacket().

bool KviIrcSocket::sendRawData ( const char *  pcBuffer,
int  iBufLen 
)
protected

Sends raw data to the socket.

Parameters
pcBufferThe data buffer
iBufLenThe size of the buffer
Returns
bool

References KviMemory::allocate(), Connecting, KviDataBuffer::data(), flushSendQueue(), m_bInProcessData, m_state, KviMemory::move(), _KviIrcSocketMsgEntry::pData, and queue_insertMessage().

Referenced by proxyAuthUserPassV5(), proxyLoginHttp(), proxyLoginV4(), proxyLoginV5(), and proxySendTargetDataV5().

unsigned int KviIrcSocket::sentBytes ( )
inline

Returns the number of bytes sent.

Returns
unsigned int
unsigned int KviIrcSocket::sentPackets ( )
inline

Returns the number of packets sent.

Returns
unsigned int
void KviIrcSocket::setState ( SocketState  state)
protectedvirtual
KviError::Code KviIrcSocket::startConnection ( KviIrcServer pServer,
KviProxy pProxy = 0,
const char *  pcBindAddress = 0 
)
SocketState KviIrcSocket::state ( )
inline

Returns the state of the socket.

Returns
SocketState

Referenced by KviIrcLink::processData(), setState(), and KviIrcLink::socketStateChange().

bool KviIrcSocket::usingSSL ( )
inline

Returns true if the socket is a Secure Socket Layer (SSL)

Returns
bool

Referenced by context_kvs_fnc_getSSLCertInfo().

void KviIrcSocket::writeNotifierFired ( int  )
protectedslot

Member Data Documentation

bool KviIrcSocket::m_bInProcessData
protected
KviError::Code KviIrcSocket::m_eLastError
protected

Referenced by KviIrcSocket(), and raiseError().

KviConsoleWindow* KviIrcSocket::m_pConsole
protected
QTimer* KviIrcSocket::m_pFlushTimer
protected
KviIrcServer* KviIrcSocket::m_pIrcServer
protected
KviIrcLink* KviIrcSocket::m_pLink
protected

Referenced by KviIrcSocket(), readData(), and setState().

KviProxy* KviIrcSocket::m_pProxy
protected
QSocketNotifier* KviIrcSocket::m_pRsn
protected
KviIrcSocketMsgEntry* KviIrcSocket::m_pSendQueueHead
protected
KviIrcSocketMsgEntry* KviIrcSocket::m_pSendQueueTail
protected
QTimer* KviIrcSocket::m_pTimeoutTimer
protected
QSocketNotifier* KviIrcSocket::m_pWsn
protected
kvi_socket_t KviIrcSocket::m_sock
protected
SocketState KviIrcSocket::m_state
protected
struct timeval KviIrcSocket::m_tAntiFloodLastMessageTime
protected

Referenced by flushSendQueue(), KviIrcSocket(), and reset().

unsigned int KviIrcSocket::m_uId
protected

Referenced by KviIrcSocket().

unsigned int KviIrcSocket::m_uReadBytes
protected

Referenced by KviIrcSocket(), readData(), and reset().

unsigned int KviIrcSocket::m_uSentBytes
protected

Referenced by flushSendQueue(), KviIrcSocket(), and reset().

unsigned int KviIrcSocket::m_uSentPackets
protected

Referenced by flushSendQueue(), KviIrcSocket(), and reset().


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