choke uploadProgress signals
[profile/ivi/qtbase.git] / src / network / access / qhttpnetworkreply_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QHTTPNETWORKREPLY_H
43 #define QHTTPNETWORKREPLY_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists for the convenience
50 // of the Network Access API.  This header file may change from
51 // version to version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 #include <qplatformdefs.h>
56 #ifndef QT_NO_HTTP
57
58 #ifndef QT_NO_COMPRESS
59 struct z_stream_s;
60 #endif
61
62 #include <QtNetwork/qtcpsocket.h>
63 // it's safe to include these even if SSL support is not enabled
64 #include <QtNetwork/qsslsocket.h>
65 #include <QtNetwork/qsslerror.h>
66
67 #include <QtNetwork/qnetworkrequest.h>
68 #include <QtNetwork/qnetworkreply.h>
69 #include <qbuffer.h>
70
71 #include <private/qobject_p.h>
72 #include <private/qhttpnetworkheader_p.h>
73 #include <private/qhttpnetworkrequest_p.h>
74 #include <private/qauthenticator_p.h>
75 #include <private/qringbuffer_p.h>
76 #include <private/qbytedata_p.h>
77
78 QT_BEGIN_NAMESPACE
79
80 class QHttpNetworkConnection;
81 class QHttpNetworkConnectionChannel;
82 class QHttpNetworkRequest;
83 class QHttpNetworkConnectionPrivate;
84 class QHttpNetworkReplyPrivate;
85 class Q_AUTOTEST_EXPORT QHttpNetworkReply : public QObject, public QHttpNetworkHeader
86 {
87     Q_OBJECT
88 public:
89
90     explicit QHttpNetworkReply(const QUrl &url = QUrl(), QObject *parent = 0);
91     virtual ~QHttpNetworkReply();
92
93     QUrl url() const;
94     void setUrl(const QUrl &url);
95
96     int majorVersion() const;
97     int minorVersion() const;
98
99     qint64 contentLength() const;
100     void setContentLength(qint64 length);
101
102     QList<QPair<QByteArray, QByteArray> > header() const;
103     QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue = QByteArray()) const;
104     void setHeaderField(const QByteArray &name, const QByteArray &data);
105     void parseHeader(const QByteArray &header); // mainly for testing
106
107     QHttpNetworkRequest request() const;
108     void setRequest(const QHttpNetworkRequest &request);
109
110     int statusCode() const;
111     void setStatusCode(int code);
112
113     QString errorString() const;
114     void setErrorString(const QString &error);
115
116     QString reasonPhrase() const;
117
118     qint64 bytesAvailable() const;
119     qint64 bytesAvailableNextBlock() const;
120     bool readAnyAvailable() const;
121     QByteArray readAny();
122     QByteArray readAll();
123     QByteArray read(qint64 amount);
124     qint64 sizeNextBlock();
125     void setDownstreamLimited(bool t);
126     void setReadBufferSize(qint64 size);
127
128     bool supportsUserProvidedDownloadBuffer();
129     void setUserProvidedDownloadBuffer(char*);
130     char* userProvidedDownloadBuffer();
131
132     bool isFinished() const;
133
134     bool isPipeliningUsed() const;
135
136     QHttpNetworkConnection* connection();
137
138 #ifndef QT_NO_SSL
139     QSslConfiguration sslConfiguration() const;
140     void setSslConfiguration(const QSslConfiguration &config);
141     void ignoreSslErrors();
142     void ignoreSslErrors(const QList<QSslError> &errors);
143
144 Q_SIGNALS:
145     void sslErrors(const QList<QSslError> &errors);
146 #endif
147
148 Q_SIGNALS:
149     void readyRead();
150     void finished();
151     void finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail = QString());
152     void headerChanged();
153     void dataReadProgress(qint64 done, qint64 total);
154     void dataSendProgress(qint64 done, qint64 total);
155     void cacheCredentials(const QHttpNetworkRequest &request, QAuthenticator *authenticator);
156 #ifndef QT_NO_NETWORKPROXY
157     void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
158 #endif
159     void authenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *authenticator);
160 private:
161     Q_DECLARE_PRIVATE(QHttpNetworkReply)
162     friend class QHttpSocketEngine;
163     friend class QHttpNetworkConnection;
164     friend class QHttpNetworkConnectionPrivate;
165     friend class QHttpNetworkConnectionChannel;
166 };
167
168
169 class QHttpNetworkReplyPrivate : public QObjectPrivate, public QHttpNetworkHeaderPrivate
170 {
171 public:
172     QHttpNetworkReplyPrivate(const QUrl &newUrl = QUrl());
173     ~QHttpNetworkReplyPrivate();
174     qint64 readStatus(QAbstractSocket *socket);
175     bool parseStatus(const QByteArray &status);
176     qint64 readHeader(QAbstractSocket *socket);
177     void parseHeader(const QByteArray &header);
178     qint64 readBody(QAbstractSocket *socket, QByteDataBuffer *out);
179     qint64 readBodyVeryFast(QAbstractSocket *socket, char *b);
180     qint64 readBodyFast(QAbstractSocket *socket, QByteDataBuffer *rb);
181     bool findChallenge(bool forProxy, QByteArray &challenge) const;
182     QAuthenticatorPrivate::Method authenticationMethod(bool isProxy) const;
183     void clear();
184     void clearHttpLayerInformation();
185
186     qint64 readReplyBodyRaw(QAbstractSocket *in, QByteDataBuffer *out, qint64 size);
187     qint64 readReplyBodyChunked(QAbstractSocket *in, QByteDataBuffer *out);
188     qint64 getChunkSize(QAbstractSocket *in, qint64 *chunkSize);
189
190     bool shouldEmitSignals();
191     bool expectContent();
192     void eraseData();
193
194     qint64 bytesAvailable() const;
195     bool isChunked();
196     bool isConnectionCloseEnabled();
197
198     bool isCompressed();
199     void removeAutoDecompressHeader();
200
201     enum ReplyState {
202         NothingDoneState,
203         ReadingStatusState,
204         ReadingHeaderState,
205         ReadingDataState,
206         AllDoneState
207     } state;
208
209     QHttpNetworkRequest request;
210     bool ssl;
211     int statusCode;
212     int majorVersion;
213     int minorVersion;
214     QString errorString;
215     QString reasonPhrase;
216     qint64 bodyLength;
217     qint64 contentRead;
218     qint64 totalProgress;
219     QByteArray fragment; // used for header, status, chunk header etc, not for reply data
220     bool chunkedTransferEncoding;
221     bool connectionCloseEnabled;
222     bool forceConnectionCloseEnabled;
223     bool lastChunkRead;
224     qint64 currentChunkSize;
225     qint64 currentChunkRead;
226     qint64 readBufferMaxSize;
227     QPointer<QHttpNetworkConnection> connection;
228     QPointer<QHttpNetworkConnectionChannel> connectionChannel;
229
230     bool autoDecompress;
231
232     QByteDataBuffer responseData; // uncompressed body
233     QByteArray compressedData; // compressed body (temporary)
234     bool requestIsPrepared;
235
236     bool pipeliningUsed;
237     bool downstreamLimited;
238
239     char* userProvidedDownloadBuffer;
240
241 #ifndef QT_NO_COMPRESS
242     z_stream_s *inflateStrm;
243     qint64 uncompressBodyData(QByteDataBuffer *in, QByteDataBuffer *out);
244 #endif
245 };
246
247
248
249
250 QT_END_NAMESPACE
251
252 //Q_DECLARE_METATYPE(QHttpNetworkReply)
253
254 #endif // QT_NO_HTTP
255
256
257 #endif // QHTTPNETWORKREPLY_H