author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QHTTPNETWORKCONNECTIONCHANNEL_H |
|
43 |
#define QHTTPNETWORKCONNECTIONCHANNEL_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 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
68 |
#include "qhttpnetworkconnection_p.h" |
0 | 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 |
||
79 |
QT_BEGIN_NAMESPACE |
|
80 |
||
81 |
class QHttpNetworkRequest; |
|
82 |
class QHttpNetworkReply; |
|
83 |
class QByteArray; |
|
84 |
||
85 |
#ifndef HttpMessagePair |
|
86 |
typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair; |
|
87 |
#endif |
|
88 |
||
89 |
class QHttpNetworkConnectionChannel : public QObject { |
|
90 |
Q_OBJECT |
|
91 |
public: |
|
92 |
enum ChannelState { |
|
93 |
IdleState = 0, // ready to send request |
|
94 |
ConnectingState = 1, // connecting to host |
|
95 |
WritingState = 2, // writing the data |
|
96 |
WaitingState = 4, // waiting for reply |
|
97 |
ReadingState = 8, // reading the reply |
|
98 |
Wait4AuthState = 0x10, // blocked for send till the current authentication slot is done |
|
99 |
BusyState = (ConnectingState|WritingState|WaitingState|ReadingState|Wait4AuthState) |
|
100 |
}; |
|
101 |
QAbstractSocket *socket; |
|
102 |
ChannelState state; |
|
103 |
QHttpNetworkRequest request; // current request |
|
104 |
QHttpNetworkReply *reply; // current reply for this request |
|
105 |
qint64 written; |
|
106 |
qint64 bytesTotal; |
|
107 |
bool resendCurrent; |
|
108 |
int lastStatus; // last status received on this channel |
|
109 |
bool pendingEncrypt; // for https (send after encrypted) |
|
110 |
int reconnectAttempts; // maximum 2 reconnection attempts |
|
111 |
QAuthenticatorPrivate::Method authMehtod; |
|
112 |
QAuthenticatorPrivate::Method proxyAuthMehtod; |
|
113 |
QAuthenticator authenticator; |
|
114 |
QAuthenticator proxyAuthenticator; |
|
115 |
#ifndef QT_NO_OPENSSL |
|
116 |
bool ignoreAllSslErrors; |
|
117 |
QList<QSslError> ignoreSslErrorsList; |
|
118 |
#endif |
|
119 |
||
120 |
// HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining |
|
121 |
enum PipeliningSupport { |
|
122 |
PipeliningSupportUnknown, // default for a new connection |
|
123 |
PipeliningProbablySupported, // after having received a server response that indicates support |
|
124 |
PipeliningNotSupported // currently not used |
|
125 |
}; |
|
126 |
PipeliningSupport pipeliningSupported; |
|
127 |
QList<HttpMessagePair> alreadyPipelinedRequests; |
|
128 |
||
129 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
130 |
QHttpNetworkConnectionChannel(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
131 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
132 |
void setConnection(QHttpNetworkConnection *c); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
133 |
QPointer<QHttpNetworkConnection> connection; |
0 | 134 |
|
135 |
void init(); |
|
136 |
void close(); |
|
137 |
||
138 |
bool sendRequest(); |
|
139 |
||
140 |
bool ensureConnection(); |
|
141 |
||
142 |
bool expand(bool dataComplete); |
|
143 |
void allDone(); // reply header + body have been read |
|
144 |
void handleStatus(); // called from allDone() |
|
145 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
146 |
bool resetUploadData(); // return true if resetting worked or there is no upload data |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
147 |
|
0 | 148 |
void pipelineInto(HttpMessagePair &pair); |
149 |
void requeueCurrentlyPipelinedRequests(); |
|
150 |
void detectPipeliningSupport(); |
|
151 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
152 |
void handleUnexpectedEOF(); |
0 | 153 |
void closeAndResendCurrentRequest(); |
154 |
||
155 |
void eatWhitespace(); |
|
156 |
||
157 |
bool isSocketBusy() const; |
|
158 |
bool isSocketWriting() const; |
|
159 |
bool isSocketWaiting() const; |
|
160 |
bool isSocketReading() const; |
|
161 |
||
162 |
protected slots: |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
void _q_receiveReply(); |
0 | 164 |
void _q_bytesWritten(qint64 bytes); // proceed sending |
165 |
void _q_readyRead(); // pending data to read |
|
166 |
void _q_disconnected(); // disconnected from host |
|
167 |
void _q_connected(); // start sending request |
|
168 |
void _q_error(QAbstractSocket::SocketError); // error from socket |
|
169 |
#ifndef QT_NO_NETWORKPROXY |
|
170 |
void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy |
|
171 |
#endif |
|
172 |
||
173 |
void _q_uploadDataReadyRead(); |
|
174 |
||
175 |
#ifndef QT_NO_OPENSSL |
|
176 |
void _q_encrypted(); // start sending request (https) |
|
177 |
void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket |
|
178 |
void _q_encryptedBytesWritten(qint64 bytes); // proceed sending |
|
179 |
#endif |
|
180 |
}; |
|
181 |
||
182 |
QT_END_NAMESPACE |
|
183 |
||
184 |
#endif // QT_NO_HTTP |
|
185 |
||
186 |
#endif |