1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
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 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 QNETWORKACCESSMANAGER_H |
41 | #define QNETWORKACCESSMANAGER_H |
42 | |
43 | #include <QtNetwork/qtnetworkglobal.h> |
44 | #include <QtNetwork/qnetworkrequest.h> |
45 | #include <QtCore/QString> |
46 | #include <QtCore/QVector> |
47 | #include <QtCore/QObject> |
48 | #ifndef QT_NO_SSL |
49 | #include <QtNetwork/QSslConfiguration> |
50 | #include <QtNetwork/QSslPreSharedKeyAuthenticator> |
51 | #endif |
52 | |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | class QIODevice; |
56 | class QAbstractNetworkCache; |
57 | class QAuthenticator; |
58 | class QByteArray; |
59 | template<typename T> class QList; |
60 | class QNetworkCookie; |
61 | class QNetworkCookieJar; |
62 | class QNetworkReply; |
63 | class QNetworkProxy; |
64 | class QNetworkProxyFactory; |
65 | class QSslError; |
66 | class QHstsPolicy; |
67 | #ifndef QT_NO_BEARERMANAGEMENT |
68 | class QNetworkConfiguration; |
69 | #endif |
70 | class QHttpMultiPart; |
71 | |
72 | class QNetworkReplyImplPrivate; |
73 | class QNetworkAccessManagerPrivate; |
74 | class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject |
75 | { |
76 | Q_OBJECT |
77 | |
78 | #ifndef QT_NO_BEARERMANAGEMENT |
79 | Q_PROPERTY(NetworkAccessibility networkAccessible READ networkAccessible WRITE setNetworkAccessible NOTIFY networkAccessibleChanged) |
80 | #endif |
81 | |
82 | public: |
83 | enum Operation { |
84 | HeadOperation = 1, |
85 | GetOperation, |
86 | PutOperation, |
87 | PostOperation, |
88 | DeleteOperation, |
89 | CustomOperation, |
90 | |
91 | UnknownOperation = 0 |
92 | }; |
93 | |
94 | #ifndef QT_NO_BEARERMANAGEMENT |
95 | enum NetworkAccessibility { |
96 | UnknownAccessibility = -1, |
97 | NotAccessible = 0, |
98 | Accessible = 1 |
99 | }; |
100 | Q_ENUM(NetworkAccessibility) |
101 | #endif |
102 | |
103 | explicit QNetworkAccessManager(QObject *parent = nullptr); |
104 | ~QNetworkAccessManager(); |
105 | |
106 | // ### Qt 6: turn into virtual |
107 | QStringList supportedSchemes() const; |
108 | |
109 | void clearAccessCache(); |
110 | |
111 | void clearConnectionCache(); |
112 | |
113 | #ifndef QT_NO_NETWORKPROXY |
114 | QNetworkProxy proxy() const; |
115 | void setProxy(const QNetworkProxy &proxy); |
116 | QNetworkProxyFactory *proxyFactory() const; |
117 | void setProxyFactory(QNetworkProxyFactory *factory); |
118 | #endif |
119 | |
120 | QAbstractNetworkCache *cache() const; |
121 | void setCache(QAbstractNetworkCache *cache); |
122 | |
123 | QNetworkCookieJar *cookieJar() const; |
124 | void setCookieJar(QNetworkCookieJar *cookieJar); |
125 | |
126 | void setStrictTransportSecurityEnabled(bool enabled); |
127 | bool isStrictTransportSecurityEnabled() const; |
128 | void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir = QString()); |
129 | bool isStrictTransportSecurityStoreEnabled() const; |
130 | void addStrictTransportSecurityHosts(const QVector<QHstsPolicy> &knownHosts); |
131 | QVector<QHstsPolicy> strictTransportSecurityHosts() const; |
132 | |
133 | QNetworkReply *(const QNetworkRequest &request); |
134 | QNetworkReply *get(const QNetworkRequest &request); |
135 | QNetworkReply *post(const QNetworkRequest &request, QIODevice *data); |
136 | QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data); |
137 | QNetworkReply *put(const QNetworkRequest &request, QIODevice *data); |
138 | QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data); |
139 | QNetworkReply *deleteResource(const QNetworkRequest &request); |
140 | QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr); |
141 | QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data); |
142 | |
143 | #if QT_CONFIG(http) |
144 | QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart); |
145 | QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart); |
146 | QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart); |
147 | #endif |
148 | |
149 | #ifndef QT_NO_BEARERMANAGEMENT |
150 | void setConfiguration(const QNetworkConfiguration &config); |
151 | QNetworkConfiguration configuration() const; |
152 | QNetworkConfiguration activeConfiguration() const; |
153 | |
154 | void setNetworkAccessible(NetworkAccessibility accessible); |
155 | NetworkAccessibility networkAccessible() const; |
156 | #endif |
157 | |
158 | #ifndef QT_NO_SSL |
159 | void connectToHostEncrypted(const QString &hostName, quint16 port = 443, |
160 | const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration()); |
161 | void connectToHostEncrypted(const QString &hostName, quint16 port, |
162 | const QSslConfiguration &sslConfiguration, |
163 | const QString &peerName); |
164 | #endif |
165 | void connectToHost(const QString &hostName, quint16 port = 80); |
166 | |
167 | void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy); |
168 | QNetworkRequest::RedirectPolicy redirectPolicy() const; |
169 | |
170 | bool autoDeleteReplies(); |
171 | void setAutoDeleteReplies(bool autoDelete); |
172 | |
173 | Q_SIGNALS: |
174 | #ifndef QT_NO_NETWORKPROXY |
175 | void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); |
176 | #endif |
177 | void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator); |
178 | void finished(QNetworkReply *reply); |
179 | #ifndef QT_NO_SSL |
180 | void encrypted(QNetworkReply *reply); |
181 | void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors); |
182 | void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator); |
183 | #endif |
184 | |
185 | #ifndef QT_NO_BEARERMANAGEMENT |
186 | void networkSessionConnected(); |
187 | |
188 | void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible); |
189 | #endif |
190 | |
191 | protected: |
192 | virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, |
193 | QIODevice *outgoingData = nullptr); |
194 | |
195 | protected Q_SLOTS: |
196 | QStringList supportedSchemesImplementation() const; |
197 | |
198 | private: |
199 | friend class QNetworkReplyImplPrivate; |
200 | friend class QNetworkReplyHttpImpl; |
201 | friend class QNetworkReplyHttpImplPrivate; |
202 | friend class QNetworkReplyFileImpl; |
203 | |
204 | #ifdef Q_OS_WASM |
205 | friend class QNetworkReplyWasmImpl; |
206 | #endif |
207 | Q_DECLARE_PRIVATE(QNetworkAccessManager) |
208 | Q_PRIVATE_SLOT(d_func(), void _q_replyFinished()) |
209 | Q_PRIVATE_SLOT(d_func(), void _q_replyEncrypted()) |
210 | Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>)) |
211 | Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)) |
212 | #ifndef QT_NO_BEARERMANAGEMENT |
213 | Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed()) |
214 | Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State)) |
215 | Q_PRIVATE_SLOT(d_func(), void _q_configurationChanged(const QNetworkConfiguration &)) |
216 | Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed(QNetworkSession::SessionError)) |
217 | #endif |
218 | Q_PRIVATE_SLOT(d_func(), void _q_onlineStateChanged(bool)) |
219 | }; |
220 | |
221 | QT_END_NAMESPACE |
222 | |
223 | #endif |
224 | |