Qt 4.8
qsocks5socketengine_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSOCKS5SOCKETENGINE_P_H
43 #define QSOCKS5SOCKETENGINE_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
57 #include "qnetworkproxy.h"
58 
60 
61 #ifndef QT_NO_SOCKS5
62 
64 
66 {
67  Q_OBJECT
68 public:
69  QSocks5SocketEngine(QObject *parent = 0);
71 
73  bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
74 
75  void setProxy(const QNetworkProxy &networkProxy);
76 
77  int socketDescriptor() const;
78 
79  bool isValid() const;
80 
81  bool connectInternal();
82  bool connectToHost(const QHostAddress &address, quint16 port);
83  bool connectToHostByName(const QString &name, quint16 port);
84  bool bind(const QHostAddress &address, quint16 port);
85  bool listen();
86  int accept();
87  void close();
88 
89  qint64 bytesAvailable() const;
90 
91  qint64 read(char *data, qint64 maxlen);
92  qint64 write(const char *data, qint64 len);
93 
94 #ifndef QT_NO_UDPSOCKET
95 #ifndef QT_NO_NETWORKINTERFACE
96  bool joinMulticastGroup(const QHostAddress &groupAddress,
97  const QNetworkInterface &interface);
98  bool leaveMulticastGroup(const QHostAddress &groupAddress,
99  const QNetworkInterface &interface);
101  bool setMulticastInterface(const QNetworkInterface &iface);
102 #endif // QT_NO_NETWORKINTERFACE
103 
104  qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
105  quint16 *port = 0);
106  qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
107  quint16 port);
108  bool hasPendingDatagrams() const;
109  qint64 pendingDatagramSize() const;
110 #endif // QT_NO_UDPSOCKET
111 
112  qint64 bytesToWrite() const;
113 
114  int option(SocketOption option) const;
115  bool setOption(SocketOption option, int value);
116 
117  bool waitForRead(int msecs = 30000, bool *timedOut = 0);
118  bool waitForWrite(int msecs = 30000, bool *timedOut = 0);
119  bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
120  bool checkRead, bool checkWrite,
121  int msecs = 30000, bool *timedOut = 0);
122 
123  bool isReadNotificationEnabled() const;
124  void setReadNotificationEnabled(bool enable);
125  bool isWriteNotificationEnabled() const;
126  void setWriteNotificationEnabled(bool enable);
127  bool isExceptionNotificationEnabled() const;
128  void setExceptionNotificationEnabled(bool enable);
129 
130 private:
133  Q_PRIVATE_SLOT(d_func(), void _q_controlSocketConnected())
134  Q_PRIVATE_SLOT(d_func(), void _q_controlSocketReadNotification())
135  Q_PRIVATE_SLOT(d_func(), void _q_controlSocketError(QAbstractSocket::SocketError))
136 #ifndef QT_NO_UDPSOCKET
137  Q_PRIVATE_SLOT(d_func(), void _q_udpSocketReadNotification())
138 #endif
139  Q_PRIVATE_SLOT(d_func(), void _q_controlSocketBytesWritten())
140  Q_PRIVATE_SLOT(d_func(), void _q_emitPendingReadNotification())
141  Q_PRIVATE_SLOT(d_func(), void _q_emitPendingWriteNotification())
142  Q_PRIVATE_SLOT(d_func(), void _q_emitPendingConnectionNotification())
143  Q_PRIVATE_SLOT(d_func(), void _q_controlSocketDisconnected())
144  Q_PRIVATE_SLOT(d_func(), void _q_controlSocketStateChanged(QAbstractSocket::SocketState))
145 
146 };
147 
148 
149 class QTcpSocket;
150 
152 {
153 public:
155  virtual ~QSocks5Authenticator();
156  virtual char methodId();
157  virtual bool beginAuthenticate(QTcpSocket *socket, bool *completed);
158  virtual bool continueAuthenticate(QTcpSocket *socket, bool *completed);
159 
160  virtual bool seal(const QByteArray buf, QByteArray *sealedBuf);
161  virtual bool unSeal(const QByteArray sealedBuf, QByteArray *buf);
162  virtual bool unSeal(QTcpSocket *sealedSocket, QByteArray *buf);
163 
164  virtual QString errorString() { return QString(); }
165 };
166 
168 {
169 public:
170  QSocks5PasswordAuthenticator(const QString &userName, const QString &password);
171  char methodId();
172  bool beginAuthenticate(QTcpSocket *socket, bool *completed);
173  bool continueAuthenticate(QTcpSocket *socket, bool *completed);
174 
176 
177 private:
180 };
181 
182 struct QSocks5Data;
183 struct QSocks5ConnectData;
185 struct QSocks5BindData;
186 
188 {
190 public:
193 
195  {
208  HostNameLookupError
209  };
211 
213  {
217  UdpAssociateMode
218  };
220 
222  {
223  SocksFailure = 0x01,
224  ConnectionNotAllowed = 0x02,
225  NetworkUnreachable = 0x03,
226  HostUnreachable = 0x04,
227  ConnectionRefused = 0x05,
228  TTLExpired = 0x06,
229  CommandNotSupported = 0x07,
230  AddressTypeNotSupported = 0x08,
231  LastKnownError = AddressTypeNotSupported,
232  UnknownError
233  };
234 
235  void initialize(Socks5Mode socks5Mode);
236 
237  void setErrorState(Socks5State state, const QString &extraMessage = QString());
238  void setErrorState(Socks5State state, Socks5Error socks5error);
239 
240  void reauthenticate();
241  void parseAuthenticationMethodReply();
242  void parseAuthenticatingReply();
243  void sendRequestMethod();
244  void parseRequestMethodReply();
245  void parseNewConnection();
246 
247  bool waitForConnected(int msecs, bool *timedOut);
248 
249  void _q_controlSocketConnected();
250  void _q_controlSocketReadNotification();
251  void _q_controlSocketError(QAbstractSocket::SocketError);
252 #ifndef QT_NO_UDPSOCKET
253  void checkForDatagrams() const;
254  void _q_udpSocketReadNotification();
255 #endif
256  void _q_controlSocketBytesWritten();
257  void _q_controlSocketDisconnected();
258  void _q_controlSocketStateChanged(QAbstractSocket::SocketState);
259 
261 
262  bool readNotificationEnabled, writeNotificationEnabled, exceptNotificationEnabled;
263 
265 
268 #ifndef QT_NO_UDPSOCKET
270 #endif
273 
276 
278  void _q_emitPendingReadNotification();
279  void emitReadNotification();
281  void _q_emitPendingWriteNotification();
282  void emitWriteNotification();
284  void _q_emitPendingConnectionNotification();
285  void emitConnectionNotification();
286 };
287 
289 {
290 public:
291  virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
292  const QNetworkProxy &, QObject *parent);
293  virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
294 };
295 
296 
298 #endif // QT_NO_SOCKS5
299 #endif // QSOCKS5SOCKETENGINE_H
virtual bool isReadNotificationEnabled() const =0
virtual bool waitForRead(int msecs=30000, bool *timedOut=0)=0
virtual void setExceptionNotificationEnabled(bool enable)=0
virtual qint64 bytesToWrite() const =0
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
SocketType
This enum describes the transport layer protocol.
virtual int socketDescriptor() const =0
virtual bool connectToHostByName(const QString &name, quint16 port)=0
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSocks5UdpAssociateData * udpData
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
virtual bool bind(const QHostAddress &address, quint16 port)=0
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual int option(SocketOption option) const =0
virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)=0
virtual int accept()=0
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
SocketState
This enum describes the different states in which a socket can be.
The QNetworkProxy class provides a network layer proxy.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual bool isWriteNotificationEnabled() const =0
virtual bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)=0
virtual void setWriteNotificationEnabled(bool enable)=0
const char * name
SocketError
This enum describes the socket errors that can occur.
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
virtual bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)=0
virtual qint64 write(const char *data, qint64 len)=0
virtual bool listen()=0
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual bool hasPendingDatagrams() const =0
virtual QNetworkInterface multicastInterface() const =0
virtual qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)=0
virtual bool isExceptionNotificationEnabled() const =0
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
virtual bool setMulticastInterface(const QNetworkInterface &iface)=0
virtual QString errorString()
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
virtual void close()=0
virtual bool waitForWrite(int msecs=30000, bool *timedOut=0)=0
virtual bool setOption(SocketOption option, int value)=0
virtual qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)=0
virtual qint64 read(char *data, qint64 maxlen)=0
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
virtual bool isValid() const =0
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces...
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
QSocks5ConnectData * connectData
virtual void setReadNotificationEnabled(bool enable)=0
virtual bool connectToHost(const QHostAddress &address, quint16 port)=0
virtual bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=0)=0
virtual qint64 bytesAvailable() const =0
virtual qint64 pendingDatagramSize() const =0