1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWebSockets 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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QWEBSOCKET_H |
41 | #define QWEBSOCKET_H |
42 | |
43 | #include <QtCore/QUrl> |
44 | #include <QtNetwork/QAbstractSocket> |
45 | #include <QtNetwork/QNetworkRequest> |
46 | #ifndef QT_NO_NETWORKPROXY |
47 | #include <QtNetwork/QNetworkProxy> |
48 | #endif |
49 | #ifndef QT_NO_SSL |
50 | #include <QtNetwork/QSslError> |
51 | #include <QtNetwork/QSslConfiguration> |
52 | #endif |
53 | #include "QtWebSockets/qwebsockets_global.h" |
54 | #include "QtWebSockets/qwebsocketprotocol.h" |
55 | |
56 | QT_BEGIN_NAMESPACE |
57 | |
58 | class QTcpSocket; |
59 | class QWebSocketPrivate; |
60 | class QMaskGenerator; |
61 | |
62 | class Q_WEBSOCKETS_EXPORT QWebSocket : public QObject |
63 | { |
64 | Q_OBJECT |
65 | Q_DISABLE_COPY(QWebSocket) |
66 | Q_DECLARE_PRIVATE(QWebSocket) |
67 | |
68 | public: |
69 | explicit QWebSocket(const QString &origin = QString(), |
70 | QWebSocketProtocol::Version version = QWebSocketProtocol::VersionLatest, |
71 | QObject *parent = nullptr); |
72 | ~QWebSocket() override; |
73 | |
74 | void abort(); |
75 | QAbstractSocket::SocketError error() const; |
76 | QString errorString() const; |
77 | bool flush(); |
78 | bool isValid() const; |
79 | QHostAddress localAddress() const; |
80 | quint16 localPort() const; |
81 | QAbstractSocket::PauseModes pauseMode() const; |
82 | QHostAddress peerAddress() const; |
83 | QString peerName() const; |
84 | quint16 peerPort() const; |
85 | #ifndef QT_NO_NETWORKPROXY |
86 | QNetworkProxy proxy() const; |
87 | void setProxy(const QNetworkProxy &networkProxy); |
88 | #endif |
89 | void setMaskGenerator(const QMaskGenerator *maskGenerator); |
90 | const QMaskGenerator *maskGenerator() const; |
91 | qint64 readBufferSize() const; |
92 | void setReadBufferSize(qint64 size); |
93 | |
94 | void resume(); |
95 | void setPauseMode(QAbstractSocket::PauseModes pauseMode); |
96 | |
97 | QAbstractSocket::SocketState state() const; |
98 | |
99 | QWebSocketProtocol::Version version() const; |
100 | QString resourceName() const; |
101 | QUrl requestUrl() const; |
102 | QNetworkRequest request() const; |
103 | QString origin() const; |
104 | QWebSocketProtocol::CloseCode closeCode() const; |
105 | QString closeReason() const; |
106 | |
107 | qint64 sendTextMessage(const QString &message); |
108 | qint64 sendBinaryMessage(const QByteArray &data); |
109 | |
110 | #ifndef QT_NO_SSL |
111 | void ignoreSslErrors(const QList<QSslError> &errors); |
112 | void setSslConfiguration(const QSslConfiguration &sslConfiguration); |
113 | QSslConfiguration sslConfiguration() const; |
114 | #endif |
115 | |
116 | qint64 bytesToWrite() const; |
117 | |
118 | void setMaxAllowedIncomingFrameSize(quint64 maxAllowedIncomingFrameSize); |
119 | quint64 maxAllowedIncomingFrameSize() const; |
120 | void setMaxAllowedIncomingMessageSize(quint64 maxAllowedIncomingMessageSize); |
121 | quint64 maxAllowedIncomingMessageSize() const; |
122 | static quint64 maxIncomingMessageSize(); |
123 | static quint64 maxIncomingFrameSize(); |
124 | |
125 | void setOutgoingFrameSize(quint64 outgoingFrameSize); |
126 | quint64 outgoingFrameSize() const; |
127 | static quint64 maxOutgoingFrameSize(); |
128 | |
129 | public Q_SLOTS: |
130 | void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CloseCodeNormal, |
131 | const QString &reason = QString()); |
132 | void open(const QUrl &url); |
133 | void open(const QNetworkRequest &request); |
134 | void ping(const QByteArray &payload = QByteArray()); |
135 | #ifndef QT_NO_SSL |
136 | void ignoreSslErrors(); |
137 | #endif |
138 | |
139 | Q_SIGNALS: |
140 | void aboutToClose(); |
141 | void connected(); |
142 | void disconnected(); |
143 | void stateChanged(QAbstractSocket::SocketState state); |
144 | #ifndef QT_NO_NETWORKPROXY |
145 | void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator); |
146 | #endif |
147 | void readChannelFinished(); |
148 | void textFrameReceived(const QString &frame, bool isLastFrame); |
149 | void binaryFrameReceived(const QByteArray &frame, bool isLastFrame); |
150 | void textMessageReceived(const QString &message); |
151 | void binaryMessageReceived(const QByteArray &message); |
152 | void error(QAbstractSocket::SocketError error); |
153 | void pong(quint64 elapsedTime, const QByteArray &payload); |
154 | void bytesWritten(qint64 bytes); |
155 | |
156 | #ifndef QT_NO_SSL |
157 | void sslErrors(const QList<QSslError> &errors); |
158 | void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator); |
159 | #endif |
160 | |
161 | private: |
162 | QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, |
163 | QObject *parent = nullptr); |
164 | }; |
165 | |
166 | QT_END_NAMESPACE |
167 | |
168 | #endif // QWEBSOCKET_H |
169 | |