Qt 4.8
qnetworkreply.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qnetworkreply.h"
43 #include "qnetworkreply_p.h"
44 #include <QtNetwork/qsslconfiguration.h>
45 
47 
49  : readBufferMaxSize(0),
50  operation(QNetworkAccessManager::UnknownOperation),
51  errorCode(QNetworkReply::NoError)
52  , isFinished(false)
53 {
54  // set the default attribute values
56 }
57 
58 
361  : QIODevice(*new QNetworkReplyPrivate, parent)
362 {
363 }
364 
369  : QIODevice(dd, parent)
370 {
371 }
372 
381 {
382 }
383 
396 {
398 }
399 
404 {
405  return true;
406 }
407 
414 {
415  return d_func()->readBufferMaxSize;
416 }
417 
437 {
439  d->readBufferMaxSize = size;
440 }
441 
447 {
448  return d_func()->manager;
449 }
450 
459 {
460  return d_func()->request;
461 }
462 
469 {
470  return d_func()->operation;
471 }
472 
480 {
481  return d_func()->errorCode;
482 }
483 
495 {
496  return d_func()->isFinished;
497 }
498 
511 {
512  return !isFinished();
513 }
514 
522 {
523  return d_func()->url;
524 }
525 
534 {
535  return d_func()->cookedHeaders.value(header);
536 }
537 
545 {
546  Q_D(const QNetworkReply);
547  return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
548 }
549 
560 {
561  Q_D(const QNetworkReply);
563  d->findRawHeader(headerName);
564  if (it != d->rawHeaders.constEnd())
565  return it->second;
566  return QByteArray();
567 }
568 
582 {
583  Q_D(const QNetworkReply);
584  return d->rawHeaders;
585 }
586 
593 {
594  return d_func()->rawHeadersKeys();
595 }
596 
608 {
609  return d_func()->attributes.value(code);
610 }
611 
612 #ifndef QT_NO_OPENSSL
613 
623 {
624  QSslConfiguration config;
625 
626  // determine if we support this extension
627  int id = metaObject()->indexOfMethod("sslConfigurationImplementation()");
628  if (id != -1) {
629  void *arr[] = { &config, 0 };
630  const_cast<QNetworkReply *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
631  }
632  return config;
633 }
634 
640 {
641  if (config.isNull())
642  return;
643 
644  int id = metaObject()->indexOfMethod("setSslConfigurationImplementation(QSslConfiguration)");
645  if (id != -1) {
646  QSslConfiguration copy(config);
647  void *arr[] = { 0, &copy };
648  qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
649  }
650 }
651 
676 {
677  // do this cryptic trick, because we could not add a virtual method to this class later on
678  // since that breaks binary compatibility
679  int id = metaObject()->indexOfMethod("ignoreSslErrorsImplementation(QList<QSslError>)");
680  if (id != -1) {
681  QList<QSslError> copy(errors);
682  void *arr[] = { 0, &copy };
683  qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
684  }
685 }
686 #endif
687 
708 {
709 }
710 
715 {
716  return -1; // you can't write
717 }
718 
729 {
731  d->operation = operation;
732 }
733 
744 {
746  d->request = request;
747 }
748 
759 {
761  d->errorCode = errorCode;
762  setErrorString(errorString); // in QIODevice
763 }
764 
777 {
779  d->isFinished = finished;
780 }
781 
782 
792 {
794  d->url = url;
795 }
796 
804 {
806  d->setCookedHeader(header, value);
807 }
808 
821 {
823  d->setRawHeader(headerName, value);
824 }
825 
834 {
836  if (value.isValid())
837  d->attributes.insert(code, value);
838  else
839  d->attributes.remove(code);
840 }
841 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
NetworkError error() const
Returns the error that was found during the processing of this request.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setUrl(const QUrl &url)
Sets the URL being processed to be url.
virtual void setReadBufferSize(qint64 size)
Sets the size of the read buffer to be size bytes.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
Definition: qiodevice.cpp:590
void setError(NetworkError errorCode, const QString &errorString)
Sets the error condition to be errorCode.
#define it(className, varName)
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value)
Sets the attribute code to have value value.
bool isRunning() const
Returns true when the request is still processing and the reply has not finished or was aborted yet...
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
virtual qint64 writeData(const char *data, qint64 len)
Operation
Indicates the operation this reply is processing.
const QList< RawHeaderPair > & rawHeaderPairs() const
Returns a list of raw header pairs.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
KnownHeaders
List of known header types that QNetworkRequest parses.
QNetworkRequest request() const
Returns the request that was posted for this reply.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void setOperation(QNetworkAccessManager::Operation operation)
Sets the associated operation for this object to be operation.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void close()
Closes this device for reading.
bool isNull() const
Returns true if this is a null QSslConfiguration object.
qint64 readBufferSize() const
Returns the size of the read buffer, in bytes.
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
Sets the known header header to be of value value.
QList< QByteArray > rawHeaderList() const
Returns a list of headers fields that were sent by the remote server, in the order that they were sen...
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the raw header headerName to be of value value.
__int64 qint64
Definition: qglobal.h:942
~QNetworkReply()
Disposes of this reply and frees any resources associated with it.
The QNetworkAccessManager class allows the application to send network requests and receive replies...
void setRequest(const QNetworkRequest &request)
Sets the associated request for this object to be request.
QVariant header(QNetworkRequest::KnownHeaders header) const
Returns the value of the known header header, if that header was sent by the remote server...
Attribute
Attribute codes for the QNetworkRequest and QNetworkReply.
virtual void ignoreSslErrors()
If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors.
void setSslConfiguration(const QSslConfiguration &configuration)
Sets the SSL configuration for the network connection associated with this request, if possible, to be that of config.
void finished()
This signal is emitted when the reply has finished processing.
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw contents of the header headerName as sent by the remote server.
bool isFinished() const
Returns true when the reply has finished or was aborted.
QNetworkReply(QObject *parent=0)
Creates a QNetworkReply object with parent parent.
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
void setFinished(bool)
Sets the reply as finished.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
Definition: qiodevice.cpp:1660
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QObject * parent
Definition: qobject.h:92
virtual bool isSequential() const
The QSslConfiguration class holds the configuration and state of an SSL connection.
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the raw header of name headerName was sent by the remote server.
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 value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
QNetworkAccessManager::Operation operation() const
Returns the operation that was posted for this reply.
QSslConfiguration sslConfiguration() const
Returns the SSL configuration and state associated with this reply, if SSL was used.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62