46 #include "QtCore/qcoreapplication.h" 47 #include "QtCore/qdatetime.h" 48 #include "QtNetwork/qsslconfiguration.h" 49 #include "QtNetwork/qnetworksession.h" 53 #include <QtCore/QCoreApplication> 60 : backend(0), outgoingData(0),
62 cacheEnabled(false), cacheSaveDevice(0),
63 notificationHandlingPaused(false),
64 bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), preMigrationDownloaded(-1),
67 , downloadBufferReadPosition(0)
68 , downloadBufferCurrentSize(0)
69 , downloadBufferMaximumSize(0)
78 qDebug(
"QNetworkReplyImpl::_q_startOperation was called more than once");
94 #ifndef QT_NO_BEARERMANAGEMENT 108 if (!session->isOpen())
111 qWarning(
"Backend is waiting for QNetworkSession to connect, but there is none!");
129 q_func()->setFinished(
true);
154 if (bytesToRead == 0)
160 byteData.
resize(bytesToRead);
162 if (bytesActuallyRead == -1) {
168 byteData.resize(bytesActuallyRead);
239 if (bytesToBuffer <= 0)
240 bytesToBuffer = 2*1024;
245 if (bytesBuffered == -1) {
251 }
else if (bytesBuffered == 0) {
263 #ifndef QT_NO_BEARERMANAGEMENT 278 #ifndef QT_NO_NETWORKPROXY 330 qint64 previousDataSize = 0;
350 bool bufferingDisallowed =
354 if (bufferingDisallowed) {
410 switch (notification) {
483 qCritical(
"QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");
491 qDebug(
"QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- " 492 "backend %s probably needs to be fixed",
528 emit q->uploadProgress(bytesSent, bytesTotal);
535 enum { DesiredBufferSize = 32 * 1024 };
537 return DesiredBufferSize;
560 if (redirectionTarget.
isValid()) {
570 qCritical(
"QNetworkReplyImpl: network cache returned a device that is not open -- " 571 "class %s probably needs to be fixed",
602 bytesWritten += item.
size();
643 qCritical(
"QNetworkReplyImpl: copy from QIODevice already in progress -- " 644 "backend probly needs to be fixed");
663 qFatal(
"QNetworkReplyImplPrivate::appendDownstreamData not implemented");
679 if (bufferAllocationPolicy.
isValid() && bufferAllocationPolicy.
toLongLong() >= size) {
748 #ifndef QT_NO_BEARERMANAGEMENT 753 if (!totalSize.
isNull()) {
773 q->setFinished(
true);
778 if (totalSize.
isNull() || totalSize == -1) {
783 emit q->uploadProgress(0, 0);
794 emit q->readChannelFinished();
804 qWarning(
"QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.");
809 q->setErrorString(errorMessage);
832 emit q->metaDataChanged();
842 #ifndef QT_NO_OPENSSL 844 emit q->sslErrors(errors);
862 if (
d->isCachingEnabled())
863 d->networkCache()->remove(
url());
891 d->backend->deleteLater();
905 d->backend->closeDownstreamChannel();
932 if (
d->downloadBuffer) {
933 qint64 maxAvail =
d->downloadBufferCurrentSize -
d->downloadBufferReadPosition;
943 if (size >
d->readBufferMaxSize &&
944 size >
d->readBuffer.byteAmount())
950 d->backend->setDownstreamLimited(
d->readBufferMaxSize > 0);
951 d->backend->setReadBufferSize(size);
955 #ifndef QT_NO_OPENSSL 961 d->backend->fetchSslConfiguration(config);
968 if (
d->backend && !config.
isNull())
969 d->backend->setSslConfiguration(config);
976 d->backend->ignoreSslErrors();
983 d->backend->ignoreSslErrors(errors);
985 #endif // QT_NO_OPENSSL 995 if (
d->downloadBuffer) {
996 qint64 maxAvail = qMin<qint64>(
d->downloadBufferCurrentSize -
d->downloadBufferReadPosition, maxlen);
1000 qMemCopy(data,
d->downloadBuffer +
d->downloadBufferReadPosition, maxAvail);
1001 d->downloadBufferReadPosition += maxAvail;
1006 if (
d->readBuffer.isEmpty())
1013 *data =
d->readBuffer.getChar();
1015 d->backend->emitReadBufferFreed(1);
1019 maxlen = qMin<qint64>(maxlen,
d->readBuffer.byteAmount());
1020 qint64 bytesRead =
d->readBuffer.read(data, maxlen);
1022 d->backend->emitReadBufferFreed(bytesRead);
1032 d_func()->handleNotifications();
1048 if (state == Finished || state == Aborted)
1060 if (backend && !backend->canResume())
1070 cookedHeaders.clear();
1073 preMigrationDownloaded = bytesDownloaded;
1079 backend->reply =
this;
1080 backend->setResumeOffset(bytesDownloaded);
1084 if (qobject_cast<QNetworkAccessHttpBackend *>(backend)) {
1085 _q_startOperation();
1091 #endif // QT_NO_HTTP 1096 #ifndef QT_NO_BEARERMANAGEMENT 1106 qRegisterMetaType<QNetworkReply::NetworkError>(
"QNetworkReply::NetworkError");
1109 "Network access is disabled.");
1124 #include "moc_qnetworkreplyimpl_p.cpp" The QVariant class acts like a union for the most common Qt data types.
void appendDownstreamDataDownloadBuffer(qint64, qint64)
QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, QNetworkAccessManager::Operation op)
void _q_bufferOutgoingData()
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
#define QT_END_NAMESPACE
This macro expands to.
QVariant qVariantFromValue(const T &)
void setUrl(const QUrl &url)
Sets the URL being processed to be url.
virtual bool needsResetableUploadData()
virtual void setReadBufferSize(qint64 size)
Sets the size of the read buffer to be size bytes.
virtual qint64 readData(char *data, qint64 maxlen)
void setError(NetworkError errorCode, const QString &errorString)
Sets the error condition to be errorCode.
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
QPointer< QNetworkAccessManager > manager
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
static void downloadBufferDeleter(char *ptr)
void append(const QByteArray &qba)
virtual void ignoreSslErrors()
If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors.
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
void resumeNotificationHandling()
virtual void closeDownstreamChannel()=0
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
The QByteArray class provides an array of bytes.
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
NetworkError
Indicates all possible error conditions found during the processing of the request.
Operation
Indicates the operation this reply is processing.
virtual void setReadBufferSize(qint64 size)
Sets the size of the read buffer to be size bytes.
QList< QNetworkProxy > proxyList
#define Q_ARG(type, data)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
QNetworkAccessBackend * backend
void _q_copyReadChannelFinished()
void append(QByteDataBuffer &other)
NotificationQueue pendingNotifications
virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const
virtual bool remove(const QUrl &url)=0
Removes the cache entry for url, returning true if success otherwise false.
virtual void downstreamReadyWrite()
qint64 nextDownstreamBlockSize() const
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
QSharedPointer< char > downloadBufferPointer
void appendDownstreamData(QByteDataBuffer &data)
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
virtual Q_INVOKABLE void ignoreSslErrorsImplementation(const QList< QSslError > &errors)
QNetworkRequest request() const
Returns the request that was posted for this reply.
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
virtual void insert(QIODevice *device)=0
Inserts the data in device and the prepared meta data into the cache.
const T value(const Key &key) const
Returns the value associated with the key.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
QUrl url() const
Returns the URL this network request is referring to.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
void setParent(QObject *)
Makes the object a child of parent.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
void setOperation(QNetworkAccessManager::Operation operation)
Sets the associated operation for this object to be operation.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
bool notificationHandlingPaused
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool isCachingEnabled() const
void redirectionRequested(const QUrl &target)
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
void setSynchronous(bool sync)
char * reserve(int bytes)
SessionError
This enum describes the session errors that can occur.
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
virtual void close()
Closes this device for reading.
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
qint64 preMigrationDownloaded
void appendDownstreamDataSignalEmissions()
void pauseNotificationHandling()
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
QNetworkReplyImplPrivate()
bool isNull() const
Returns true if this is a null QSslConfiguration object.
LoadControl
Indicates if an aspect of the request's loading mechanism has been manually overridden, e.
Q_CORE_EXPORT void qWarning(const char *,...)
qint64 readBufferSize() const
Returns the size of the read buffer, in bytes.
static const char * data(const QByteArray &arr)
virtual bool setCookiesFromUrl(const QList< QNetworkCookie > &cookieList, const QUrl &url)
Adds the cookies in the list cookieList to this cookie jar.
qint64 downloadBufferCurrentSize
char * getDownloadBuffer(qint64 size)
const T * ptr(const T &t)
QNetworkAccessManager::Operation operation
void clear()
Removes all items from the list.
QAbstractNetworkCache * networkCache() const
virtual QIODevice * prepare(const QNetworkCacheMetaData &metaData)=0
Returns the device that should be populated with the data for the cache item metaData.
void setRequest(const QNetworkRequest &request)
Sets the associated request for this object to be request.
void _q_networkSessionFailed()
void setDownloadBuffer(QSharedPointer< char > sp, qint64 size)
State state() const
Returns the state of the session.
QAbstractNetworkCache * networkCache() const
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
QNetworkReply::NetworkError errorCode
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
T * data() const
Returns the value of the pointer referenced by this object.
void * qMemCopy(void *dest, const void *src, size_t n)
const char * constData() const
Returns a pointer to the data stored in the byte array.
QIODevice * cacheSaveDevice
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
void enqueue(const T &t)
Adds value t to the tail of the queue.
Q_CORE_EXPORT void qFatal(const char *,...)
QString scheme() const
Returns the scheme of the URL.
QSharedPointer< QRingBuffer > outgoingDataBuffer
virtual void close()
Closes this device for reading.
void handleNotifications()
void sslErrors(const QList< QSslError > &errors)
Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const
QObject * parent() const
Returns a pointer to the parent object.
void resize(int size)
Sets the size of the byte array to size bytes.
void error(QNetworkReply::NetworkError code, const QString &errorString)
int size() const
Returns the number of items in the list.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
T qvariant_cast(const QVariant &)
QNetworkReplyImpl(QObject *parent=0)
int size() const
Returns the number of bytes in this byte array.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration)
virtual void abort()
Aborts the operation immediately and close down any network connections still open.
The QSslConfiguration class holds the configuration and state of an SSL connection.
void setCachingEnabled(bool enable)
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
QByteDataBuffer readBuffer
virtual void copyFinished(QIODevice *)
QUrl url() const
Returns the URL of the content downloaded or uploaded.
QNetworkAccessManager * manager() const
Returns the QNetworkAccessManager that was used to create this QNetworkReply object.
T dequeue()
Removes the head item in the queue and returns it.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
The QIODevice class is the base interface class of all I/O devices in Qt.
void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal)
qint64 bufferCount() const
The QEvent class is the base class of all event classes.
QNetworkAccessManager::Operation operation() const
Returns the operation that was posted for this reply.
Type type() const
Returns the event type.
qint64 lastBytesDownloaded
void backendNotify(InternalNotifications notification)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
virtual qint64 bytesAvailable() const
Returns the number of bytes available for reading with QIODevice::read().
void initCacheSaveDevice()
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
void _q_networkSessionConnected()
qint64 byteAmount() const
qint64 downloadBufferMaximumSize
QNetworkCookieJar * cookieJar() const
Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cook...
virtual bool event(QEvent *)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
virtual bool start()
Starts the backend.
Q_CORE_EXPORT void qCritical(const char *,...)
void _q_bufferOutgoingDataFinished()
The QAbstractNetworkCache class provides the interface for cache implementations. ...
#define forever
This macro is provided for convenience for writing infinite loops.