KVIrc 5.2.0
Developer APIs
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 "kvi_socket.h"
35#include "kvi_sockettype.h"
36#include "KviCString.h"
37#include "KviError.h"
38#include "KviPointerList.h"
39#include "KviTimeUtils.h"
40
41#include <QObject>
42
43#include <memory>
44
46class KviDataBuffer;
49class KviIrcLink;
50class KviIrcServer;
51class KviProxy;
52class KviSSL;
53class QSocketNotifier;
54class QTimer;
55
66
74class KVIRC_API KviIrcSocket : public QObject
75{
76 Q_OBJECT
77public:
83 KviIrcSocket(KviIrcLink * pLink);
84
89
90public:
108
109protected:
110 unsigned int m_uId;
114 SocketState m_state = Idle; // current socket state
115 QSocketNotifier * m_pWsn = nullptr; // read socket notifier
116 QSocketNotifier * m_pRsn = nullptr; // write socket notifier
117 KviIrcServer * m_pIrcServer = nullptr; // current server data
118 KviProxy * m_pProxy = nullptr; // current proxy data
119 QTimer * m_pTimeoutTimer = nullptr; // timeout for connect()
120 unsigned int m_uReadBytes = 0; // total read bytes per session
121 unsigned int m_uSentBytes = 0; // total sent bytes per session
122 unsigned int m_uSentPackets = 0; // total packets sent per session
124 KviIrcSocketMsgEntry * m_pSendQueueHead = nullptr; // data queue
125 KviIrcSocketMsgEntry * m_pSendQueueTail = nullptr;
126 std::unique_ptr<QTimer> m_pFlushTimer;
127 struct timeval m_tAntiFloodLastMessageTime;
128 bool m_bInProcessData = false;
129#ifdef COMPILE_SSL_SUPPORT
130 KviSSL * m_pSSL = nullptr;
131#endif
132public:
137 KviConsoleWindow * console() const { return m_pConsole; }
138
143 KviIrcLink * link() const { return m_pLink; }
144
149 SocketState state() const { return m_state; }
150
155 int lastError() const { return m_eLastError; }
156
161 unsigned int id() const { return m_uId; }
162
167 bool usingSSL() const
168 {
169#ifdef COMPILE_SSL_SUPPORT
170 return m_pSSL;
171#else
172 return false;
173#endif
174 }
175
176#ifdef COMPILE_SSL_SUPPORT
181 KviSSL * getSSL() const { return m_pSSL; }
182#endif
187 unsigned int readBytes() const { return m_uReadBytes; }
188
193 unsigned int sentBytes() const { return m_uSentBytes; }
194
199 unsigned int sentPackets() const { return m_uSentPackets; }
200 //unsigned int readPackets() const { return m_uReadPackets; }
201
206 bool isConnected() const { return m_state == Connected; }
207
215 KviError::Code startConnection(KviIrcServer * pServer, KviProxy * pProxy = nullptr, const char * pcBindAddress = nullptr);
216
217#ifdef COMPILE_SSL_SUPPORT
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
261protected:
262#ifdef COMPILE_SSL_SUPPORT
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
448private:
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);
497protected 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_
Error List.
C++ Template based double linked pointer list class.
Time management.
Definition Idle.h:33
Definition KviConsoleWindow.h:74
Definition KviDataBuffer.h:31
Definition KviIrcConnectionTarget.h:36
An abstraction of a connection to an IRC server.
Definition KviIrcConnection.h:97
The class which manages the irc servers.
Definition KviIrcServer.h:52
This class is the lowest level of the KVIrc networking stack.
Definition KviIrcSocket.h:75
KviConsoleWindow * console() const
Returns the console.
Definition KviIrcSocket.h:137
KviIrcLink * link() const
Returns the link.
Definition KviIrcSocket.h:143
KviConsoleWindow * m_pConsole
Definition KviIrcSocket.h:112
bool isConnected() const
Returns true if the socket is connected.
Definition KviIrcSocket.h:206
std::unique_ptr< QTimer > m_pFlushTimer
Definition KviIrcSocket.h:126
SocketState state() const
Returns the state of the socket.
Definition KviIrcSocket.h:149
int lastError() const
Returns the last error.
Definition KviIrcSocket.h:155
unsigned int m_uId
Definition KviIrcSocket.h:110
bool usingSSL() const
Returns true if the socket is a Secure Socket Layer (SSL)
Definition KviIrcSocket.h:167
unsigned int readBytes() const
Returns the number of bytes read.
Definition KviIrcSocket.h:187
unsigned int sentBytes() const
Returns the number of bytes sent.
Definition KviIrcSocket.h:193
unsigned int sentPackets() const
Returns the number of packets sent.
Definition KviIrcSocket.h:199
KviIrcLink * m_pLink
Definition KviIrcSocket.h:111
SocketState
Definition KviIrcSocket.h:95
@ ProxyFinalV5
Definition KviIrcSocket.h:102
@ Connected
Definition KviIrcSocket.h:100
@ ProxyFinalHttp
Definition KviIrcSocket.h:103
@ ProxyHttpError
Definition KviIrcSocket.h:99
@ Connecting
Definition KviIrcSocket.h:97
@ ProxySelectAuthMethodV5
Definition KviIrcSocket.h:104
@ Idle
Definition KviIrcSocket.h:96
@ ProxyUserPassV5
Definition KviIrcSocket.h:105
@ ProxyLogin
Definition KviIrcSocket.h:98
@ ProxyFinalV4
Definition KviIrcSocket.h:101
unsigned int id() const
Returns the id of the socket.
Definition KviIrcSocket.h:161
Definition KviProxy.h:37
#define e
Definition detector.cpp:70
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127
#define KVI_INVALID_SOCKET
(defined(COMPILE_ON_WINDOWS) || (defined(COMPILE_ON_MINGW) && !defined(OS2))
Definition kvi_socket.h:75
int kvi_socket_t
Definition kvi_sockettype.h:40
Code
Contains all error codes.
Definition KviError.h:48
@ Success
Definition KviError.h:49
Definition KviIrcSocket.h:62
KviDataBuffer * pData
Definition KviIrcSocket.h:63
KviIrcSocketMsgEntry * next_ptr
Definition KviIrcSocket.h:64