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

Last change on this file since 659 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 8.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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 //enable encryption
112 void enableEncryption();
113 bool isEncrypted() const;
114
115 //authentication parameters
116 void setProxyAuthentication(QAuthenticator *authenticator);
117 void setAuthentication(const QString &domain, QAuthenticator *authenticator);
118
119#ifndef QT_NO_OPENSSL
120 void setSslConfiguration(const QSslConfiguration &config);
121 void ignoreSslErrors(int channel = -1);
122 void ignoreSslErrors(const QList<QSslError> &errors, int channel = -1);
123
124Q_SIGNALS:
125 void sslErrors(const QList<QSslError> &errors);
126#endif
127
128Q_SIGNALS:
129#ifndef QT_NO_NETWORKPROXY
130 //cannot be used with queued connection.
131 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator,
132 const QHttpNetworkConnection *connection = 0);
133#endif
134 void authenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *authenticator,
135 const QHttpNetworkConnection *connection = 0);
136 void error(QNetworkReply::NetworkError errorCode, const QString &detail = QString());
137
138private:
139 Q_DECLARE_PRIVATE(QHttpNetworkConnection)
140 Q_DISABLE_COPY(QHttpNetworkConnection)
141 friend class QHttpNetworkReply;
142 friend class QHttpNetworkConnectionChannel;
143
144 Q_PRIVATE_SLOT(d_func(), void _q_startNextRequest())
145 Q_PRIVATE_SLOT(d_func(), void _q_restartAuthPendingRequests())
146};
147
148
149// private classes
150typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
151
152
153class QHttpNetworkConnectionPrivate : public QObjectPrivate
154{
155 Q_DECLARE_PUBLIC(QHttpNetworkConnection)
156public:
157 static const int defaultChannelCount;
158 static const int defaultPipelineLength;
159
160 QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt);
161 QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt);
162 ~QHttpNetworkConnectionPrivate();
163 void init();
164
165 enum { ChunkSize = 4096 };
166
167 int indexOf(QAbstractSocket *socket) const;
168
169 QHttpNetworkReply *queueRequest(const QHttpNetworkRequest &request);
170 void requeueRequest(const HttpMessagePair &pair); // e.g. after pipeline broke
171 void dequeueAndSendRequest(QAbstractSocket *socket);
172 void prepareRequest(HttpMessagePair &request);
173
174 void fillPipeline(QAbstractSocket *socket);
175 bool fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel);
176
177 // read more HTTP body after the next event loop spin
178 void readMoreLater(QHttpNetworkReply *reply);
179
180 void copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy);
181
182 // private slots
183 void _q_startNextRequest(); // send the next request from the queue
184 void _q_restartAuthPendingRequests(); // send the currently blocked request
185
186 void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request);
187
188 QString errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket,
189 const QString &extraDetail = QString());
190
191#ifndef QT_NO_COMPRESS
192 bool expand(QAbstractSocket *socket, QHttpNetworkReply *reply, bool dataComplete);
193#endif
194 void removeReply(QHttpNetworkReply *reply);
195
196 QString hostName;
197 quint16 port;
198 bool encrypt;
199
200 const int channelCount;
201 QHttpNetworkConnectionChannel *channels; // parallel connections to the server
202
203 bool pendingAuthSignal; // there is an incomplete authentication signal
204 bool pendingProxyAuthSignal; // there is an incomplete proxy authentication signal
205
206 qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const;
207 qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const;
208
209
210 void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode);
211 bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend);
212
213
214#ifndef QT_NO_OPENSSL
215 QSslConfiguration sslConfiguration(const QHttpNetworkReply &reply) const;
216#endif
217
218#ifndef QT_NO_NETWORKPROXY
219 QNetworkProxy networkProxy;
220 void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth);
221#endif
222
223 //The request queues
224 QList<HttpMessagePair> highPriorityQueue;
225 QList<HttpMessagePair> lowPriorityQueue;
226
227 friend class QHttpNetworkConnectionChannel;
228};
229
230
231
232QT_END_NAMESPACE
233
234#endif // QT_NO_HTTP
235
236#endif
Note: See TracBrowser for help on using the repository browser.