1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKACCESSMANAGER_P_H
6#define QNETWORKACCESSMANAGER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include "qnetworkaccessmanager.h"
21#include "qnetworkaccesscache_p.h"
22#include "qnetworkaccessbackend_p.h"
23#include "private/qnetconmonitor_p.h"
24#include "qnetworkrequest.h"
25#include "qhsts_p.h"
26#include "private/qobject_p.h"
27#include "QtNetwork/qnetworkproxy.h"
28#include "qnetworkaccessauthenticationmanager_p.h"
29
30#if QT_CONFIG(settings)
31#include "qhstsstore_p.h"
32#endif // QT_CONFIG(settings)
33
34QT_BEGIN_NAMESPACE
35
36class QAuthenticator;
37class QAbstractNetworkCache;
38class QNetworkAuthenticationCredential;
39class QNetworkCookieJar;
40
41class QNetworkAccessManagerPrivate: public QObjectPrivate
42{
43public:
44 QNetworkAccessManagerPrivate()
45 : networkCache(nullptr),
46 cookieJar(nullptr),
47 thread(nullptr),
48#ifndef QT_NO_NETWORKPROXY
49 proxyFactory(nullptr),
50#endif
51 cookieJarCreated(false),
52 defaultAccessControl(true),
53 redirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy),
54 authenticationManager(std::make_shared<QNetworkAccessAuthenticationManager>())
55 {
56 }
57 ~QNetworkAccessManagerPrivate();
58
59 QThread * createThread();
60 void destroyThread();
61
62 void _q_replyFinished(QNetworkReply *reply);
63 void _q_replyEncrypted(QNetworkReply *reply);
64 void _q_replySslErrors(const QList<QSslError> &errors);
65 void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
66 QNetworkReply *postProcess(QNetworkReply *reply);
67 void createCookieJar() const;
68
69 void authenticationRequired(QAuthenticator *authenticator,
70 QNetworkReply *reply,
71 bool synchronous,
72 QUrl &url,
73 QUrl *urlForLastAuthentication,
74 bool allowAuthenticationReuse = true);
75 void cacheCredentials(const QUrl &url, const QAuthenticator *auth);
76 QNetworkAuthenticationCredential *fetchCachedCredentials(const QUrl &url,
77 const QAuthenticator *auth = nullptr);
78
79#ifndef QT_NO_NETWORKPROXY
80 void proxyAuthenticationRequired(const QUrl &url,
81 const QNetworkProxy &proxy,
82 bool synchronous,
83 QAuthenticator *authenticator,
84 QNetworkProxy *lastProxyAuthentication);
85 void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth);
86 QNetworkAuthenticationCredential *fetchCachedProxyCredentials(const QNetworkProxy &proxy,
87 const QAuthenticator *auth = nullptr);
88 QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query);
89#endif
90
91 QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request);
92 QStringList backendSupportedSchemes() const;
93
94#if QT_CONFIG(http) || defined(Q_OS_WASM)
95 QNetworkRequest prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart);
96#endif
97
98 void ensureBackendPluginsLoaded();
99
100 // this is the cache for storing downloaded files
101 QAbstractNetworkCache *networkCache;
102
103 QNetworkCookieJar *cookieJar;
104
105 QThread *thread;
106
107
108#ifndef QT_NO_NETWORKPROXY
109 QNetworkProxy proxy;
110 QNetworkProxyFactory *proxyFactory;
111#endif
112
113 bool cookieJarCreated;
114 bool defaultAccessControl;
115 QNetworkRequest::RedirectPolicy redirectPolicy = QNetworkRequest::NoLessSafeRedirectPolicy;
116
117 // The cache with authorization data:
118 std::shared_ptr<QNetworkAccessAuthenticationManager> authenticationManager;
119
120 Q_AUTOTEST_EXPORT static void clearAuthenticationCache(QNetworkAccessManager *manager);
121 Q_AUTOTEST_EXPORT static void clearConnectionCache(QNetworkAccessManager *manager);
122
123 QHstsCache stsCache;
124#if QT_CONFIG(settings)
125 QScopedPointer<QHstsStore> stsStore;
126#endif // QT_CONFIG(settings)
127 bool stsEnabled = false;
128
129 bool autoDeleteReplies = false;
130
131 std::chrono::milliseconds transferTimeout{0};
132
133 Q_DECLARE_PUBLIC(QNetworkAccessManager)
134};
135
136QT_END_NAMESPACE
137
138#endif
139

source code of qtbase/src/network/access/qnetworkaccessmanager_p.h