qnetworkreply.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtNetwork module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QNETWORKREPLY_H
00043 #define QNETWORKREPLY_H
00044 
00045 #include <QtCore/QIODevice>
00046 #include <QtCore/QString>
00047 #include <QtCore/QVariant>
00048 
00049 #include <QtNetwork/QNetworkRequest>
00050 #include <QtNetwork/QNetworkAccessManager>
00051 
00052 QT_BEGIN_HEADER
00053 
00054 QT_BEGIN_NAMESPACE
00055 
00056 QT_MODULE(Network)
00057 
00058 class QUrl;
00059 class QVariant;
00060 class QAuthenticator;
00061 class QSslConfiguration;
00062 class QSslError;
00063 
00064 class QNetworkReplyPrivate;
00065 class Q_NETWORK_EXPORT QNetworkReply: public QIODevice
00066 {
00067     Q_OBJECT
00068     Q_ENUMS(NetworkError)
00069 public:
00070     enum NetworkError {
00071         NoError = 0,
00072 
00073         // network layer errors [relating to the destination server] (1-99):
00074         ConnectionRefusedError = 1,
00075         RemoteHostClosedError,
00076         HostNotFoundError,
00077         TimeoutError,
00078         OperationCanceledError,
00079         SslHandshakeFailedError,
00080         TemporaryNetworkFailureError,
00081         UnknownNetworkError = 99,
00082 
00083         // proxy errors (101-199):
00084         ProxyConnectionRefusedError = 101,
00085         ProxyConnectionClosedError,
00086         ProxyNotFoundError,
00087         ProxyTimeoutError,
00088         ProxyAuthenticationRequiredError,
00089         UnknownProxyError = 199,
00090 
00091         // content errors (201-299):
00092         ContentAccessDenied = 201,
00093         ContentOperationNotPermittedError,
00094         ContentNotFoundError,
00095         AuthenticationRequiredError,
00096         ContentReSendError,
00097         UnknownContentError = 299,
00098 
00099         // protocol errors
00100         ProtocolUnknownError = 301,
00101         ProtocolInvalidOperationError,
00102         ProtocolFailure = 399
00103     };
00104 
00105     ~QNetworkReply();
00106     virtual void abort() = 0;
00107 
00108     // reimplemented from QIODevice
00109     virtual void close();
00110     virtual bool isSequential() const;
00111 
00112     // like QAbstractSocket:
00113     qint64 readBufferSize() const;
00114     virtual void setReadBufferSize(qint64 size);
00115 
00116     QNetworkAccessManager *manager() const;
00117     QNetworkAccessManager::Operation operation() const;
00118     QNetworkRequest request() const;
00119     NetworkError error() const;
00120     bool isFinished() const;
00121     bool isRunning() const;
00122     QUrl url() const;
00123 
00124     // "cooked" headers
00125     QVariant header(QNetworkRequest::KnownHeaders header) const;
00126 
00127     // raw headers:
00128     bool hasRawHeader(const QByteArray &headerName) const;
00129     QList<QByteArray> rawHeaderList() const;
00130     QByteArray rawHeader(const QByteArray &headerName) const;
00131 
00132     typedef QPair<QByteArray, QByteArray> RawHeaderPair;
00133     const QList<RawHeaderPair>& rawHeaderPairs() const;
00134 
00135     // attributes
00136     QVariant attribute(QNetworkRequest::Attribute code) const;
00137 
00138 #ifndef QT_NO_OPENSSL
00139     QSslConfiguration sslConfiguration() const;
00140     void setSslConfiguration(const QSslConfiguration &configuration);
00141     void ignoreSslErrors(const QList<QSslError> &errors);
00142 #endif
00143 
00144 public Q_SLOTS:
00145     virtual void ignoreSslErrors();
00146 
00147 Q_SIGNALS:
00148     void metaDataChanged();
00149     void finished();
00150     void error(QNetworkReply::NetworkError);
00151 #ifndef QT_NO_OPENSSL
00152     void sslErrors(const QList<QSslError> &errors);
00153 #endif
00154 
00155     void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
00156     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
00157 
00158 protected:
00159     QNetworkReply(QObject *parent = 0);
00160     QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent);
00161     virtual qint64 writeData(const char *data, qint64 len);
00162 
00163     void setOperation(QNetworkAccessManager::Operation operation);
00164     void setRequest(const QNetworkRequest &request);
00165     void setError(NetworkError errorCode, const QString &errorString);
00166     void setUrl(const QUrl &url);
00167     void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
00168     void setRawHeader(const QByteArray &headerName, const QByteArray &value);
00169     void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
00170 
00171 private:
00172     Q_DECLARE_PRIVATE(QNetworkReply)
00173 };
00174 
00175 QT_END_NAMESPACE
00176 
00177 QT_END_HEADER
00178 
00179 #endif