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 | |
4 | #ifndef QNETWORKREPLYIMPL_P_H |
5 | #define QNETWORKREPLYIMPL_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/private/qtnetworkglobal_p.h> |
19 | #include "qnetworkreply.h" |
20 | #include "qnetworkreply_p.h" |
21 | #include "qnetworkaccessmanager.h" |
22 | #include "qnetworkproxy.h" |
23 | #include "QtCore/qmap.h" |
24 | #include "QtCore/qqueue.h" |
25 | #include "QtCore/qbuffer.h" |
26 | #include "private/qringbuffer_p.h" |
27 | #include "private/qbytedata_p.h" |
28 | #include <QSharedPointer> |
29 | |
30 | #include <memory> |
31 | |
32 | QT_BEGIN_NAMESPACE |
33 | |
34 | class QAbstractNetworkCache; |
35 | class QNetworkAccessBackend; |
36 | |
37 | class QNetworkReplyImplPrivate; |
38 | class QNetworkReplyImpl: public QNetworkReply |
39 | { |
40 | Q_OBJECT |
41 | public: |
42 | QNetworkReplyImpl(QObject *parent = nullptr); |
43 | ~QNetworkReplyImpl(); |
44 | virtual void abort() override; |
45 | |
46 | // reimplemented from QNetworkReply / QIODevice |
47 | virtual void close() override; |
48 | virtual qint64 bytesAvailable() const override; |
49 | virtual void setReadBufferSize(qint64 size) override; |
50 | |
51 | virtual qint64 readData(char *data, qint64 maxlen) override; |
52 | virtual bool event(QEvent *) override; |
53 | |
54 | Q_DECLARE_PRIVATE(QNetworkReplyImpl) |
55 | Q_PRIVATE_SLOT(d_func(), void _q_startOperation()) |
56 | Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead()) |
57 | Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished()) |
58 | Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData()) |
59 | Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished()) |
60 | |
61 | #ifndef QT_NO_SSL |
62 | protected: |
63 | void sslConfigurationImplementation(QSslConfiguration &configuration) const override; |
64 | void setSslConfigurationImplementation(const QSslConfiguration &configuration) override; |
65 | virtual void ignoreSslErrors() override; |
66 | virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors) override; |
67 | #endif |
68 | }; |
69 | |
70 | class QNetworkReplyImplPrivate: public QNetworkReplyPrivate |
71 | { |
72 | public: |
73 | enum InternalNotifications { |
74 | NotifyDownstreamReadyWrite, |
75 | }; |
76 | |
77 | QNetworkReplyImplPrivate(); |
78 | |
79 | void _q_startOperation(); |
80 | void _q_copyReadyRead(); |
81 | void _q_copyReadChannelFinished(); |
82 | void _q_bufferOutgoingData(); |
83 | void _q_bufferOutgoingDataFinished(); |
84 | |
85 | void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, |
86 | QIODevice *outgoingData); |
87 | |
88 | void pauseNotificationHandling(); |
89 | void resumeNotificationHandling(); |
90 | void backendNotify(InternalNotifications notification); |
91 | void handleNotifications(); |
92 | void createCache(); |
93 | void completeCacheSave(); |
94 | |
95 | // callbacks from the backend (through the manager): |
96 | void setCachingEnabled(bool enable); |
97 | bool isCachingEnabled() const; |
98 | void consume(qint64 count); |
99 | void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal); |
100 | qint64 nextDownstreamBlockSize() const; |
101 | |
102 | void initCacheSaveDevice(); |
103 | void appendDownstreamDataSignalEmissions(); |
104 | void appendDownstreamData(QByteDataBuffer &data); |
105 | void appendDownstreamData(QIODevice *data); |
106 | |
107 | void setDownloadBuffer(QSharedPointer<char> sp, qint64 size); |
108 | char* getDownloadBuffer(qint64 size); |
109 | void appendDownstreamDataDownloadBuffer(qint64, qint64); |
110 | |
111 | void finished(); |
112 | void error(QNetworkReply::NetworkError code, const QString &errorString); |
113 | void metaDataChanged(); |
114 | void redirectionRequested(const QUrl &target); |
115 | void encrypted(); |
116 | void sslErrors(const QList<QSslError> &errors); |
117 | |
118 | void readFromBackend(); |
119 | |
120 | QNetworkAccessBackend *backend; |
121 | QIODevice *outgoingData; |
122 | std::shared_ptr<QRingBuffer> outgoingDataBuffer; |
123 | QIODevice *copyDevice; |
124 | QAbstractNetworkCache *networkCache() const; |
125 | |
126 | bool cacheEnabled; |
127 | QIODevice *cacheSaveDevice; |
128 | |
129 | std::vector<InternalNotifications> pendingNotifications; |
130 | bool notificationHandlingPaused; |
131 | |
132 | QUrl urlForLastAuthentication; |
133 | #ifndef QT_NO_NETWORKPROXY |
134 | QNetworkProxy lastProxyAuthentication; |
135 | QList<QNetworkProxy> proxyList; |
136 | #endif |
137 | |
138 | qint64 bytesDownloaded; |
139 | qint64 bytesUploaded; |
140 | |
141 | QString httpReasonPhrase; |
142 | int httpStatusCode; |
143 | |
144 | State state; |
145 | |
146 | // Only used when the "zero copy" style is used. |
147 | // Please note that the whole "zero copy" download buffer API is private right now. Do not use it. |
148 | qint64 downloadBufferReadPosition; |
149 | qint64 downloadBufferCurrentSize; |
150 | qint64 downloadBufferMaximumSize; |
151 | QSharedPointer<char> downloadBufferPointer; |
152 | char* downloadBuffer; |
153 | |
154 | Q_DECLARE_PUBLIC(QNetworkReplyImpl) |
155 | }; |
156 | Q_DECLARE_TYPEINFO(QNetworkReplyImplPrivate::InternalNotifications, Q_PRIMITIVE_TYPE); |
157 | |
158 | QT_END_NAMESPACE |
159 | |
160 | #endif |
161 | |