KVIrc  4.9.2
DeveloperAPIs
KviIrcSocket.h
Go to the documentation of this file.
1 #ifndef _KVI_IRCSOCKET_H_
2 #define _KVI_IRCSOCKET_H_
3 //=============================================================================
4 //
5 // File : KviIrcSocket.h
6 // Creation date : Tue Jul 30 19:25:17 2002 GMT by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
33 #include "kvi_settings.h"
34 #include "KviCString.h"
35 #include "kvi_sockettype.h"
36 #include "KviTimeUtils.h"
37 #include "KviPointerList.h"
38 #include "KviError.h"
39 
40 #include <QObject>
41 
42 class QTimer;
43 class QSocketNotifier;
44 class KviIrcServer;
45 class KviProxy;
46 class KviIrcConnection;
48 class KviIrcLink;
49 class KviSSL;
50 class KviConsoleWindow;
52 
58 typedef struct _KviIrcSocketMsgEntry
59 {
63 
71 class KVIRC_API KviIrcSocket : public QObject
72 {
73  Q_OBJECT
74 public:
80  KviIrcSocket(KviIrcLink * pLink);
81 
85  ~KviIrcSocket();
86 
87 public:
92  {
93  Idle,
103  SSLHandshake
104  };
105 
106 protected:
107  unsigned int m_uId;
112  QSocketNotifier * m_pWsn;
113  QSocketNotifier * m_pRsn;
116  QTimer * m_pTimeoutTimer;
117  unsigned int m_uReadBytes;
118  unsigned int m_uSentBytes;
120  unsigned int m_uSentPackets;
123  QTimer * m_pFlushTimer;
124  struct timeval m_tAntiFloodLastMessageTime;
126 #ifdef COMPILE_SSL_SUPPORT
127  KviSSL * m_pSSL;
128 #endif
129 public:
134  KviConsoleWindow * console() { return m_pConsole; };
135 
140  KviIrcLink * link() { return m_pLink; };
141 
146  SocketState state() { return m_state; };
147 
152  int lastError() { return m_eLastError; };
153 
158  unsigned int id() { return m_uId; };
159 
164 #ifdef COMPILE_SSL_SUPPORT
165  bool usingSSL()
166  {
167  return m_pSSL;
168  };
169 #else
170  bool usingSSL()
171  {
172  return false;
173  };
174 #endif
175 
176 #ifdef COMPILE_SSL_SUPPORT
177 
181  KviSSL * getSSL() { return m_pSSL; };
182 #endif
183 
187  unsigned int readBytes() { return m_uReadBytes; };
188 
193  unsigned int sentBytes() { return m_uSentBytes; };
194 
199  unsigned int sentPackets() { return m_uSentPackets; };
200  //unsigned int readPackets(){ return m_uReadPackets; };
201 
206  bool isConnected() { return m_state == Connected; };
207 
215  KviError::Code startConnection(KviIrcServer * pServer, KviProxy * pProxy = 0, const char * pcBindAddress = 0);
216 
217 #ifdef COMPILE_SSL_SUPPORT
218 
224  void enterSSLMode();
225 #endif // COMPILE_SSL_SUPPORT
226 
232  bool sendPacket(KviDataBuffer * pData);
233 
238  void abort();
239 
246  bool getLocalHostIp(QString & szIp, bool bIPv6);
247 
253  void clearOutputQueue(bool bPrivateMessagesOnly);
254 
259  unsigned int outputQueueSize();
260 
261 protected:
262 #ifdef COMPILE_SSL_SUPPORT
263 
267  void raiseSSLError();
268 
273  void printSSLPeerCertificate();
274 
279  void printSSLCipherInfo();
280 #endif // COMPILE_SSL_SUPPORT
281 
288  bool sendRawData(const char * pcBuffer, int iBufLen);
289 
295  void raiseError(KviError::Code eError);
296 
304  void connectionEstablished();
305 
310  void connectedToProxy();
311 
316  void connectedToIrcServer();
317 
322  void proxyLoginHttp();
323 
328  void proxyLoginV4();
329 
334  void proxyLoginV5();
335 
340  void proxyAuthUserPassV5();
341 
346  void proxySendTargetDataV5();
347 
353  void proxyHandleV5AuthReply(unsigned char cReply);
354 
360  void proxyHandleV5MethodReply(unsigned char cReply);
361 
367  void proxyHandleV5FinalReply(unsigned char cReply);
368 
374  void proxyHandleV4FinalReply(unsigned char cReply);
375 
382  void proxyHandleHttpFinalReply(const char * pcBuffer, int iBufLen);
383 
388  void linkUp();
389 
399  void handleInvalidSocketRead(int iReadLength);
400 
405  virtual void reset();
406 
412  void free_msgEntry(KviIrcSocketMsgEntry * e);
413 
421  virtual void queue_insertMessage(KviIrcSocketMsgEntry * pMsg);
422 
427  bool queue_removeMessage();
428 
433  void queue_removeAllMessages();
434 
439  void queue_removePrivateMessages();
440 
446  virtual void setState(SocketState state);
447 
448 private:
454  void outputSSLMessage(const QString & szMsg);
455 
461  void outputSSLError(const QString & szMsg);
462 
468  void outputProxyMessage(const QString & szMsg);
469 
475  void outputProxyError(const QString & szMsg);
476 
482  void outputSocketMessage(const QString & szMsg);
483 
489  void outputSocketWarning(const QString & szMsg);
490 
496  void outputSocketError(const QString & szMsg);
497 protected slots:
502  void connectionTimedOut();
503 
508  void writeNotifierFired(int);
509 
514  void readData(int);
515 
520  void readProxyData(int);
521 
526  void readHttpProxyErrorData(int);
527 
536  void flushSendQueue();
537 
542  void doSSLHandshake(int);
543 };
544 
545 #endif //_KVI_IRCSOCKET_H_
int kvi_socket_t
Definition: kvi_sockettype.h:40
bool isConnected()
Returns true if the socket is connected.
Definition: KviIrcSocket.h:206
unsigned int m_uReadBytes
Definition: KviIrcSocket.h:117
Definition: KviIrcSocket.h:93
Definition: KviIrcSocket.h:97
Definition: KviConsoleWindow.h:75
The class which manages the irc servers.
Definition: KviIrcServer.h:51
#define KVIRC_API
Definition: kvi_settings.h:128
Definition: KviIrcSocket.h:98
Definition: KviIrcSocket.h:101
struct _KviIrcSocketMsgEntry * next_ptr
Definition: KviIrcSocket.h:61
An abstraction of a connection to an IRC server.
Definition: KviIrcConnection.h:95
SocketState state()
Returns the state of the socket.
Definition: KviIrcSocket.h:146
unsigned int m_uSentPackets
Definition: KviIrcSocket.h:120
unsigned int readBytes()
Returns the number of bytes read.
Definition: KviIrcSocket.h:187
KviIrcServer * m_pIrcServer
Definition: KviIrcSocket.h:114
Definition: KviDataBuffer.h:30
Definition: KviProxy.h:37
QTimer * m_pTimeoutTimer
Definition: KviIrcSocket.h:116
unsigned int id()
Returns the id of the socket.
Definition: KviIrcSocket.h:158
#define e
Definition: detector.cpp:69
SocketState m_state
Definition: KviIrcSocket.h:111
QSocketNotifier * m_pRsn
Definition: KviIrcSocket.h:113
Definition: KviIrcSocket.h:102
KviProxy * m_pProxy
Definition: KviIrcSocket.h:115
QSocketNotifier * m_pWsn
Definition: KviIrcSocket.h:112
KviIrcSocketMsgEntry * m_pSendQueueTail
Definition: KviIrcSocket.h:122
Code
Contains all error codes.
Definition: KviError.h:47
unsigned int m_uSentBytes
Definition: KviIrcSocket.h:118
KviIrcSocketMsgEntry * m_pSendQueueHead
Definition: KviIrcSocket.h:121
KviDataBuffer * pData
Definition: KviIrcSocket.h:60
Definition: KviIrcSocket.h:96
unsigned int sentPackets()
Returns the number of packets sent.
Definition: KviIrcSocket.h:199
KviIrcLink * m_pLink
Definition: KviIrcSocket.h:108
Definition: KviIrcSocket.h:99
Time management.
Definition: KviIrcSocket.h:94
KviIrcLink * link()
Returns the link.
Definition: KviIrcSocket.h:140
unsigned int m_uId
Definition: KviIrcSocket.h:107
C++ Template based double linked pointer list class.
QTimer * m_pFlushTimer
Definition: KviIrcSocket.h:123
bool m_bInProcessData
Definition: KviIrcSocket.h:125
KviError::Code m_eLastError
Definition: KviIrcSocket.h:119
unsigned int sentBytes()
Returns the number of bytes sent.
Definition: KviIrcSocket.h:193
int lastError()
Returns the last error.
Definition: KviIrcSocket.h:152
bool usingSSL()
Returns true if the socket is a Secure Socket Layer (SSL)
Definition: KviIrcSocket.h:170
Error List.
KviConsoleWindow * m_pConsole
Definition: KviIrcSocket.h:109
kvi_socket_t m_sock
Definition: KviIrcSocket.h:110
Holds the messages entries.
Definition: KviIrcSocket.h:58
SocketState
Definition: KviIrcSocket.h:91
KviConsoleWindow * console()
Returns the console.
Definition: KviIrcSocket.h:134
struct _KviIrcSocketMsgEntry KviIrcSocketMsgEntry
Definition: KviIrcSocket.h:51
This file contains compile time settings.
Definition: KviIrcSocket.h:95
Definition: KviIrcConnectionTarget.h:35
This class is the lowest level of the KVIrc networking stack.
Definition: KviIrcSocket.h:71
Definition: KviIrcSocket.h:100