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 QNETWORKREPLYIMPL_P_H
41#define QNETWORKREPLYIMPL_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the Network Access API. This header file may change from
49// version to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtNetwork/private/qtnetworkglobal_p.h>
55#include "qnetworkreply.h"
56#include "qnetworkreply_p.h"
57#include "qnetworkaccessmanager.h"
58#include "qnetworkproxy.h"
59#include "QtCore/qmap.h"
60#include "QtCore/qqueue.h"
61#include "QtCore/qbuffer.h"
62#include "private/qringbuffer_p.h"
63#include "private/qbytedata_p.h"
64#include <QSharedPointer>
65
66QT_BEGIN_NAMESPACE
67
68class QAbstractNetworkCache;
69class QNetworkAccessBackend;
70
71class QNetworkReplyImplPrivate;
72class QNetworkReplyImpl: public QNetworkReply
73{
74 Q_OBJECT
75public:
76 QNetworkReplyImpl(QObject *parent = nullptr);
77 ~QNetworkReplyImpl();
78 virtual void abort() override;
79
80 // reimplemented from QNetworkReply / QIODevice
81 virtual void close() override;
82 virtual qint64 bytesAvailable() const override;
83 virtual void setReadBufferSize(qint64 size) override;
84
85 virtual qint64 readData(char *data, qint64 maxlen) override;
86 virtual bool event(QEvent *) override;
87
88 Q_DECLARE_PRIVATE(QNetworkReplyImpl)
89 Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
90 Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead())
91 Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished())
92 Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData())
93 Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished())
94
95#ifndef QT_NO_SSL
96protected:
97 void sslConfigurationImplementation(QSslConfiguration &configuration) const override;
98 void setSslConfigurationImplementation(const QSslConfiguration &configuration) override;
99 virtual void ignoreSslErrors() override;
100 virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors) override;
101#endif
102};
103
104class QNetworkReplyImplPrivate: public QNetworkReplyPrivate
105{
106public:
107 enum InternalNotifications {
108 NotifyDownstreamReadyWrite,
109 };
110
111 QNetworkReplyImplPrivate();
112
113 void _q_startOperation();
114 void _q_copyReadyRead();
115 void _q_copyReadChannelFinished();
116 void _q_bufferOutgoingData();
117 void _q_bufferOutgoingDataFinished();
118
119 void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
120 QIODevice *outgoingData);
121
122 void pauseNotificationHandling();
123 void resumeNotificationHandling();
124 void backendNotify(InternalNotifications notification);
125 void handleNotifications();
126 void createCache();
127 void completeCacheSave();
128
129 // callbacks from the backend (through the manager):
130 void setCachingEnabled(bool enable);
131 bool isCachingEnabled() const;
132 void consume(qint64 count);
133 void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal);
134 qint64 nextDownstreamBlockSize() const;
135
136 void initCacheSaveDevice();
137 void appendDownstreamDataSignalEmissions();
138 void appendDownstreamData(QByteDataBuffer &data);
139 void appendDownstreamData(QIODevice *data);
140
141 void setDownloadBuffer(QSharedPointer<char> sp, qint64 size);
142 char* getDownloadBuffer(qint64 size);
143 void appendDownstreamDataDownloadBuffer(qint64, qint64);
144
145 void finished();
146 void error(QNetworkReply::NetworkError code, const QString &errorString);
147 void metaDataChanged();
148 void redirectionRequested(const QUrl &target);
149 void encrypted();
150 void sslErrors(const QList<QSslError> &errors);
151
152 void readFromBackend();
153
154 QNetworkAccessBackend *backend;
155 QIODevice *outgoingData;
156 QSharedPointer<QRingBuffer> outgoingDataBuffer;
157 QIODevice *copyDevice;
158 QAbstractNetworkCache *networkCache() const;
159
160 bool cacheEnabled;
161 QIODevice *cacheSaveDevice;
162
163 std::vector<InternalNotifications> pendingNotifications;
164 bool notificationHandlingPaused;
165
166 QUrl urlForLastAuthentication;
167#ifndef QT_NO_NETWORKPROXY
168 QNetworkProxy lastProxyAuthentication;
169 QList<QNetworkProxy> proxyList;
170#endif
171
172 qint64 bytesDownloaded;
173 qint64 bytesUploaded;
174
175 QString httpReasonPhrase;
176 int httpStatusCode;
177
178 State state;
179
180 // Only used when the "zero copy" style is used.
181 // Please note that the whole "zero copy" download buffer API is private right now. Do not use it.
182 qint64 downloadBufferReadPosition;
183 qint64 downloadBufferCurrentSize;
184 qint64 downloadBufferMaximumSize;
185 QSharedPointer<char> downloadBufferPointer;
186 char* downloadBuffer;
187
188 Q_DECLARE_PUBLIC(QNetworkReplyImpl)
189};
190Q_DECLARE_TYPEINFO(QNetworkReplyImplPrivate::InternalNotifications, Q_PRIMITIVE_TYPE);
191
192QT_END_NAMESPACE
193
194Q_DECLARE_METATYPE(QSharedPointer<char>)
195
196#endif
197