source: trunk/src/network/access/qhttpnetworkconnection_p.h@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtNetwork module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QHTTPNETWORKCONNECTION_H
43#define QHTTPNETWORKCONNECTION_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 <QtNetwork/qnetworkrequest.h>
56#include <QtNetwork/qnetworkreply.h>
57#include <QtNetwork/qabstractsocket.h>
58
59#include <private/qobject_p.h>
60#include <qauthenticator.h>
61#include <qnetworkproxy.h>
62#include <qbuffer.h>
63
64#include <private/qhttpnetworkheader_p.h>
65#include <private/qhttpnetworkrequest_p.h>
66#include <private/qhttpnetworkreply_p.h>
67
68#include <private/qhttpnetworkconnectionchannel_p.h>
69
70#ifndef QT_NO_HTTP
71
72#ifndef QT_NO_OPENSSL
73# include <QtNetwork/qsslsocket.h>
74# include <QtNetwork/qsslerror.h>
75#else
76# include <QtNetwork/qtcpsocket.h>
77#endif
78
79QT_BEGIN_NAMESPACE
80
81class QHttpNetworkRequest;
82class QHttpNetworkReply;
83class QByteArray;
84
85class QHttpNetworkConnectionPrivate;
86class Q_AUTOTEST_EXPORT QHttpNetworkConnection : public QObject
87{
88 Q_OBJECT
89public:
90
91 QHttpNetworkConnection(const QString &hostName, quint16 port = 80, bool encrypt = false, QObject *parent = 0);
92 QHttpNetworkConnection(quint16 channelCount, const QString &hostName, quint16 port = 80, bool encrypt = false, QObject *parent = 0);
93 ~QHttpNetworkConnection();
94
95 //The hostname to which this is connected to.
96 QString hostName() const;
97 //The HTTP port in use.
98 quint16 port() const;
99
100 //add a new HTTP request through this connection
101 QHttpNetworkReply* sendRequest(const QHttpNetworkRequest &request);
102
103#ifndef QT_NO_NETWORKPROXY
104 //set the proxy for this connection
105 void setCacheProxy(const QNetworkProxy &networkProxy);
106 QNetworkProxy cacheProxy() const;
107 void setTransparentProxy(const QNetworkProxy &networkProxy);
108 QNetworkProxy transparentProxy() const;
109#endif
110
111 bool isSsl() const;
112
113 QHttpNetworkConnectionChannel *channels() const;
114
115#ifndef QT_NO_OPENSSL
116 void setSslConfiguration(const QSslConfiguration &config);
117 void ignoreSslErrors(int channel = -1);
118 void ignoreSslErrors(const QList<QSslError> &errors, int channel = -1);
119#endif
120
121private:
122 Q_DECLARE_PRIVATE(QHttpNetworkConnection)
123 Q_DISABLE_COPY(QHttpNetworkConnection)
124 friend class QHttpNetworkReply;
125 friend class QHttpNetworkReplyPrivate;
126 friend class QHttpNetworkConnectionChannel;
127
128 Q_PRIVATE_SLOT(d_func(), void _q_startNextRequest())
129};
130
131
132// private classes
133typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
134
135
136class QHttpNetworkConnectionPrivate : public QObjectPrivate
137{
138 Q_DECLARE_PUBLIC(QHttpNetworkConnection)
139public:
140 static const int defaultChannelCount;
141 static const int defaultPipelineLength;
142 static const int defaultRePipelineLength;
143
144 enum ConnectionState {
145 RunningState = 0,
146 PausedState = 1,
147 };
148
149 QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt);
150 QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt);
151 ~QHttpNetworkConnectionPrivate();
152 void init();
153
154 void pauseConnection();
155 void resumeConnection();
156 ConnectionState state;
157
158 enum { ChunkSize = 4096 };
159
160 int indexOf(QAbstractSocket *socket) const;
161
162 QHttpNetworkReply *queueRequest(const QHttpNetworkRequest &request);
163 void requeueRequest(const HttpMessagePair &pair); // e.g. after pipeline broke
164 void dequeueAndSendRequest(QAbstractSocket *socket);
165 void prepareRequest(HttpMessagePair &request);
166
167 void fillPipeline(QAbstractSocket *socket);
168 bool fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel);
169
170 // read more HTTP body after the next event loop spin
171 void readMoreLater(QHttpNetworkReply *reply);
172
173 void copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy);
174
175 // private slots
176 void _q_startNextRequest(); // send the next request from the queue
177
178 void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request);
179
180 QString errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket,
181 const QString &extraDetail = QString());
182
183#ifndef QT_NO_COMPRESS
184 bool expand(QAbstractSocket *socket, QHttpNetworkReply *reply, bool dataComplete);
185#endif
186 void removeReply(QHttpNetworkReply *reply);
187
188 QString hostName;
189 quint16 port;
190 bool encrypt;
191
192 const int channelCount;
193 QHttpNetworkConnectionChannel *channels; // parallel connections to the server
194
195 qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const;
196 qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const;
197
198
199 void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode);
200 bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend);
201
202#ifndef QT_NO_NETWORKPROXY
203 QNetworkProxy networkProxy;
204 void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth);
205#endif
206
207 //The request queues
208 QList<HttpMessagePair> highPriorityQueue;
209 QList<HttpMessagePair> lowPriorityQueue;
210
211 friend class QHttpNetworkConnectionChannel;
212};
213
214
215
216QT_END_NAMESPACE
217
218#endif // QT_NO_HTTP
219
220#endif
Note: See TracBrowser for help on using the repository browser.