1// Copyright (C) 2020 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
4#ifndef QNETWORKACCESSBACKEND_P_H
5#define QNETWORKACCESSBACKEND_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the Network Access API. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/qtnetworkglobal.h>
19
20#include <QtNetwork/qnetworkrequest.h>
21#include <QtNetwork/qnetworkaccessmanager.h>
22#include <QtNetwork/qnetworkreply.h>
23
24#include <QtCore/qobject.h>
25#include <QtCore/qflags.h>
26#include <QtCore/qbytearrayview.h>
27#include <QtCore/private/qglobal_p.h>
28
29#if QT_CONFIG(ssl)
30#include <QtNetwork/qsslconfiguration.h>
31#endif
32
33QT_BEGIN_NAMESPACE
34
35class QNetworkReplyImplPrivate;
36class QNetworkAccessManagerPrivate;
37class QNetworkAccessBackendPrivate;
38class Q_NETWORK_EXPORT QNetworkAccessBackend : public QObject
39{
40 Q_OBJECT
41 Q_DECLARE_PRIVATE(QNetworkAccessBackend);
42
43public:
44 enum class TargetType {
45 Networked = 0x1, // We need to query for proxy in case it is needed
46 Local = 0x2, // Local file, generated data or local device
47 };
48 Q_ENUM(TargetType)
49 Q_DECLARE_FLAGS(TargetTypes, TargetType)
50
51 enum class SecurityFeature {
52 None = 0x0,
53 TLS = 0x1, // We need to set QSslConfiguration
54 };
55 Q_ENUM(SecurityFeature)
56 Q_DECLARE_FLAGS(SecurityFeatures, SecurityFeature)
57
58 enum class IOFeature {
59 None = 0x0,
60 ZeroCopy = 0x1, // readPointer and advanceReadPointer() is available!
61 NeedResetableUpload = 0x2, // Need to buffer upload data
62 SupportsSynchronousMode = 0x4, // Used for XMLHttpRequest
63 };
64 Q_ENUM(IOFeature)
65 Q_DECLARE_FLAGS(IOFeatures, IOFeature)
66
67 QNetworkAccessBackend(TargetTypes targetTypes, SecurityFeatures securityFeatures,
68 IOFeatures ioFeatures);
69 QNetworkAccessBackend(TargetTypes targetTypes);
70 QNetworkAccessBackend(TargetTypes targetTypes, SecurityFeatures securityFeatures);
71 QNetworkAccessBackend(TargetTypes targetTypes, IOFeatures ioFeatures);
72 virtual ~QNetworkAccessBackend();
73
74 SecurityFeatures securityFeatures() const noexcept;
75 TargetTypes targetTypes() const noexcept;
76 IOFeatures ioFeatures() const noexcept;
77
78 inline bool needsResetableUploadData() const noexcept
79 {
80 return ioFeatures() & IOFeature::NeedResetableUpload;
81 }
82
83 virtual bool start();
84 virtual void open() = 0;
85 virtual void close() = 0;
86#if QT_CONFIG(ssl)
87 virtual void setSslConfiguration(const QSslConfiguration &configuration);
88 virtual QSslConfiguration sslConfiguration() const;
89#endif
90 virtual void ignoreSslErrors();
91 virtual void ignoreSslErrors(const QList<QSslError> &errors);
92 virtual qint64 bytesAvailable() const = 0;
93 virtual QByteArrayView readPointer();
94 virtual void advanceReadPointer(qint64 distance);
95 virtual qint64 read(char *data, qint64 maxlen);
96 virtual bool wantToRead();
97
98#if QT_CONFIG(networkproxy)
99 QList<QNetworkProxy> proxyList() const;
100#endif
101 QUrl url() const;
102 void setUrl(const QUrl &url);
103 QVariant header(QNetworkRequest::KnownHeaders header) const;
104 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
105 QByteArray rawHeader(const QByteArray &header) const;
106 void setRawHeader(const QByteArray &header, const QByteArray &value);
107 QNetworkAccessManager::Operation operation() const;
108
109 bool isCachingEnabled() const;
110 void setCachingEnabled(bool canCache);
111
112 void setAttribute(QNetworkRequest::Attribute attribute, const QVariant &value);
113
114 QIODevice *createUploadByteDevice();
115 QIODevice *uploadByteDevice();
116
117 QAbstractNetworkCache *networkCache() const;
118
119public slots:
120 void readyRead();
121protected slots:
122 void finished();
123 void error(QNetworkReply::NetworkError code, const QString &errorString);
124#ifndef QT_NO_NETWORKPROXY
125 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
126#endif
127 void authenticationRequired(QAuthenticator *auth);
128 void metaDataChanged();
129 void redirectionRequested(const QUrl &destination);
130
131private:
132 void setReplyPrivate(QNetworkReplyImplPrivate *reply);
133 void setManagerPrivate(QNetworkAccessManagerPrivate *manager);
134 bool isSynchronous() const;
135 void setSynchronous(bool synchronous);
136
137 friend class QNetworkAccessManager; // for setReplyPrivate
138 friend class QNetworkAccessManagerPrivate; // for setManagerPrivate
139 friend class QNetworkReplyImplPrivate; // for {set,is}Synchronous()
140};
141
142class Q_NETWORK_EXPORT QNetworkAccessBackendFactory : public QObject
143{
144 Q_OBJECT
145public:
146 QNetworkAccessBackendFactory();
147 virtual ~QNetworkAccessBackendFactory();
148 virtual QStringList supportedSchemes() const = 0;
149 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
150 const QNetworkRequest &request) const = 0;
151};
152
153#define QNetworkAccessBackendFactory_iid "org.qt-project.Qt.NetworkAccessBackendFactory"
154Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid);
155
156QT_END_NAMESPACE
157#endif
158

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