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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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