access/qhttpnetworkconnectionchannel.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtNetwork module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qhttpnetworkconnectionchannel_p.h" -
43#include "qhttpnetworkconnection_p.h" -
44#include "private/qnoncontiguousbytedevice_p.h" -
45 -
46#include <qpair.h> -
47#include <qdebug.h> -
48 -
49#ifndef QT_NO_HTTP -
50 -
51#ifndef QT_NO_SSL -
52# include <QtNetwork/qsslkey.h> -
53# include <QtNetwork/qsslcipher.h> -
54# include <QtNetwork/qsslconfiguration.h> -
55#endif -
56 -
57#ifndef QT_NO_BEARERMANAGEMENT -
58#include "private/qnetworksession_p.h" -
59#endif -
60 -
61QT_BEGIN_NAMESPACE -
62 -
63// TODO: Put channel specific stuff here so it does not polute qhttpnetworkconnection.cpp -
64 -
65QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() -
66 : socket(0) -
67 , ssl(false) -
68 , isInitialized(false) -
69 , state(IdleState) -
70 , reply(0) -
71 , written(0) -
72 , bytesTotal(0) -
73 , resendCurrent(false) -
74 , lastStatus(0) -
75 , pendingEncrypt(false) -
76 , reconnectAttempts(2) -
77 , authMethod(QAuthenticatorPrivate::None) -
78 , proxyAuthMethod(QAuthenticatorPrivate::None) -
79 , authenticationCredentialsSent(false) -
80 , proxyCredentialsSent(false) -
81#ifndef QT_NO_SSL -
82 , ignoreAllSslErrors(false) -
83#endif -
84 , pipeliningSupported(PipeliningSupportUnknown) -
85 , networkLayerPreference(QAbstractSocket::AnyIPProtocol) -
86 , connection(0) -
87{ -
88 // Inlining this function in the header leads to compiler error on -
89 // release-armv5, on at least timebox 9.2 and 10.1. -
90}
executed: }
Execution Count:3042
3042
91 -
92void QHttpNetworkConnectionChannel::init() -
93{ -
94#ifndef QT_NO_SSL -
95 if (connection->d_func()->encrypt)
evaluated: connection->d_func()->encrypt
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:459
72-459
96 socket = new QSslSocket;
executed: socket = new QSslSocket;
Execution Count:72
72
97 else -
98 socket = new QTcpSocket;
executed: socket = new QTcpSocket;
Execution Count:459
459
99#else -
100 socket = new QTcpSocket; -
101#endif -
102#ifndef QT_NO_BEARERMANAGEMENT -
103 //push session down to socket -
104 if (networkSession)
evaluated: networkSession
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:528
3-528
105 socket->setProperty("_q_networksession", QVariant::fromValue(networkSession));
executed: socket->setProperty("_q_networksession", QVariant::fromValue(networkSession));
Execution Count:3
3
106#endif -
107#ifndef QT_NO_NETWORKPROXY -
108 // Set by QNAM anyway, but let's be safe here -
109 socket->setProxy(QNetworkProxy::NoProxy);
executed (the execution status of this line is deduced): socket->setProxy(QNetworkProxy::NoProxy);
-
110#endif -
111 -
112 QObject::connect(socket, SIGNAL(bytesWritten(qint64)),
executed (the execution status of this line is deduced): QObject::connect(socket, "2""bytesWritten(qint64)",
-
113 this, SLOT(_q_bytesWritten(qint64)),
executed (the execution status of this line is deduced): this, "1""_q_bytesWritten(qint64)",
-
114 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
115 QObject::connect(socket, SIGNAL(connected()),
executed (the execution status of this line is deduced): QObject::connect(socket, "2""connected()",
-
116 this, SLOT(_q_connected()),
executed (the execution status of this line is deduced): this, "1""_q_connected()",
-
117 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
118 QObject::connect(socket, SIGNAL(readyRead()),
executed (the execution status of this line is deduced): QObject::connect(socket, "2""readyRead()",
-
119 this, SLOT(_q_readyRead()),
executed (the execution status of this line is deduced): this, "1""_q_readyRead()",
-
120 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
121 -
122 // The disconnected() and error() signals may already come -
123 // while calling connectToHost(). -
124 // In case of a cached hostname or an IP this -
125 // will then emit a signal to the user of QNetworkReply -
126 // but cannot be caught because the user did not have a chance yet -
127 // to connect to QNetworkReply's signals. -
128 qRegisterMetaType<QAbstractSocket::SocketError>();
executed (the execution status of this line is deduced): qRegisterMetaType<QAbstractSocket::SocketError>();
-
129 QObject::connect(socket, SIGNAL(disconnected()),
executed (the execution status of this line is deduced): QObject::connect(socket, "2""disconnected()",
-
130 this, SLOT(_q_disconnected()),
executed (the execution status of this line is deduced): this, "1""_q_disconnected()",
-
131 Qt::QueuedConnection);
executed (the execution status of this line is deduced): Qt::QueuedConnection);
-
132 QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
executed (the execution status of this line is deduced): QObject::connect(socket, "2""error(QAbstractSocket::SocketError)",
-
133 this, SLOT(_q_error(QAbstractSocket::SocketError)),
executed (the execution status of this line is deduced): this, "1""_q_error(QAbstractSocket::SocketError)",
-
134 Qt::QueuedConnection);
executed (the execution status of this line is deduced): Qt::QueuedConnection);
-
135 -
136 -
137#ifndef QT_NO_NETWORKPROXY -
138 QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
executed (the execution status of this line is deduced): QObject::connect(socket, "2""proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)",
-
139 this, SLOT(_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
executed (the execution status of this line is deduced): this, "1""_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)",
-
140 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
141#endif -
142 -
143#ifndef QT_NO_SSL -
144 QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
executed (the execution status of this line is deduced): QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
-
145 if (sslSocket) {
evaluated: sslSocket
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:459
72-459
146 // won't be a sslSocket if encrypt is false -
147 QObject::connect(sslSocket, SIGNAL(encrypted()),
executed (the execution status of this line is deduced): QObject::connect(sslSocket, "2""encrypted()",
-
148 this, SLOT(_q_encrypted()),
executed (the execution status of this line is deduced): this, "1""_q_encrypted()",
-
149 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
150 QObject::connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)),
executed (the execution status of this line is deduced): QObject::connect(sslSocket, "2""sslErrors(QList<QSslError>)",
-
151 this, SLOT(_q_sslErrors(QList<QSslError>)),
executed (the execution status of this line is deduced): this, "1""_q_sslErrors(QList<QSslError>)",
-
152 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
153 QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)),
executed (the execution status of this line is deduced): QObject::connect(sslSocket, "2""encryptedBytesWritten(qint64)",
-
154 this, SLOT(_q_encryptedBytesWritten(qint64)),
executed (the execution status of this line is deduced): this, "1""_q_encryptedBytesWritten(qint64)",
-
155 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
156 -
157 if (ignoreAllSslErrors)
partially evaluated: ignoreAllSslErrors
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:72
0-72
158 sslSocket->ignoreSslErrors();
never executed: sslSocket->ignoreSslErrors();
0
159 -
160 if (!ignoreSslErrorsList.isEmpty())
partially evaluated: !ignoreSslErrorsList.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:72
0-72
161 sslSocket->ignoreSslErrors(ignoreSslErrorsList);
never executed: sslSocket->ignoreSslErrors(ignoreSslErrorsList);
0
162 -
163 if (!sslConfiguration.isNull())
evaluated: !sslConfiguration.isNull()
TRUEFALSE
yes
Evaluation Count:42
yes
Evaluation Count:30
30-42
164 sslSocket->setSslConfiguration(sslConfiguration);
executed: sslSocket->setSslConfiguration(sslConfiguration);
Execution Count:42
42
165 }
executed: }
Execution Count:72
72
166 -
167#endif -
168 -
169#ifndef QT_NO_NETWORKPROXY -
170 if (proxy.type() != QNetworkProxy::NoProxy)
evaluated: proxy.type() != QNetworkProxy::NoProxy
TRUEFALSE
yes
Evaluation Count:49
yes
Evaluation Count:482
49-482
171 socket->setProxy(proxy);
executed: socket->setProxy(proxy);
Execution Count:49
49
172#endif -
173 isInitialized = true;
executed (the execution status of this line is deduced): isInitialized = true;
-
174}
executed: }
Execution Count:531
531
175 -
176 -
177void QHttpNetworkConnectionChannel::close() -
178{ -
179 if (!socket)
evaluated: !socket
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:332
1-332
180 state = QHttpNetworkConnectionChannel::IdleState;
executed: state = QHttpNetworkConnectionChannel::IdleState;
Execution Count:1
1
181 else if (socket->state() == QAbstractSocket::UnconnectedState)
evaluated: socket->state() == QAbstractSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:132
yes
Evaluation Count:200
132-200
182 state = QHttpNetworkConnectionChannel::IdleState;
executed: state = QHttpNetworkConnectionChannel::IdleState;
Execution Count:132
132
183 else -
184 state = QHttpNetworkConnectionChannel::ClosingState;
executed: state = QHttpNetworkConnectionChannel::ClosingState;
Execution Count:200
200
185 -
186 if (socket)
evaluated: socket
TRUEFALSE
yes
Evaluation Count:332
yes
Evaluation Count:1
1-332
187 socket->close();
executed: socket->close();
Execution Count:332
332
188}
executed: }
Execution Count:333
333
189 -
190 -
191bool QHttpNetworkConnectionChannel::sendRequest() -
192{ -
193 if (!reply) {
partially evaluated: !reply
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6812
0-6812
194 // heh, how should that happen! -
195 qWarning() << "QHttpNetworkConnectionChannel::sendRequest() called without QHttpNetworkReply";
never executed (the execution status of this line is deduced): QMessageLogger("access/qhttpnetworkconnectionchannel.cpp", 195, __PRETTY_FUNCTION__).warning() << "QHttpNetworkConnectionChannel::sendRequest() called without QHttpNetworkReply";
-
196 state = QHttpNetworkConnectionChannel::IdleState;
never executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::IdleState;
-
197 return false;
never executed: return false;
0
198 } -
199 -
200 switch (state) { -
201 case QHttpNetworkConnectionChannel::IdleState: { // write the header -
202 if (!ensureConnection()) {
evaluated: !ensureConnection()
TRUEFALSE
yes
Evaluation Count:92
yes
Evaluation Count:849
92-849
203 // wait for the connection (and encryption) to be done -
204 // sendRequest will be called again from either -
205 // _q_connected or _q_encrypted -
206 return false;
executed: return false;
Execution Count:92
92
207 } -
208 written = 0; // excluding the header
executed (the execution status of this line is deduced): written = 0;
-
209 bytesTotal = 0;
executed (the execution status of this line is deduced): bytesTotal = 0;
-
210 -
211 QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
executed (the execution status of this line is deduced): QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
-
212 replyPrivate->clear();
executed (the execution status of this line is deduced): replyPrivate->clear();
-
213 replyPrivate->connection = connection;
executed (the execution status of this line is deduced): replyPrivate->connection = connection;
-
214 replyPrivate->connectionChannel = this;
executed (the execution status of this line is deduced): replyPrivate->connectionChannel = this;
-
215 replyPrivate->autoDecompress = request.d->autoDecompress;
executed (the execution status of this line is deduced): replyPrivate->autoDecompress = request.d->autoDecompress;
-
216 replyPrivate->pipeliningUsed = false;
executed (the execution status of this line is deduced): replyPrivate->pipeliningUsed = false;
-
217 -
218 // if the url contains authentication parameters, use the new ones -
219 // both channels will use the new authentication parameters -
220 if (!request.url().userInfo().isEmpty() && request.withCredentials()) {
evaluated: !request.url().userInfo().isEmpty()
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:823
partially evaluated: request.withCredentials()
TRUEFALSE
yes
Evaluation Count:26
no
Evaluation Count:0
0-823
221 QUrl url = request.url();
executed (the execution status of this line is deduced): QUrl url = request.url();
-
222 QAuthenticator &auth = authenticator;
executed (the execution status of this line is deduced): QAuthenticator &auth = authenticator;
-
223 if (url.userName() != auth.user()
evaluated: url.userName() != auth.user()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:10
10-16
224 || (!url.password().isEmpty() && url.password() != auth.password())) {
partially evaluated: !url.password().isEmpty()
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
evaluated: url.password() != auth.password()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8
0-10
225 auth.setUser(url.userName());
executed (the execution status of this line is deduced): auth.setUser(url.userName());
-
226 auth.setPassword(url.password());
executed (the execution status of this line is deduced): auth.setPassword(url.password());
-
227 connection->d_func()->copyCredentials(connection->d_func()->indexOf(socket), &auth, false);
executed (the execution status of this line is deduced): connection->d_func()->copyCredentials(connection->d_func()->indexOf(socket), &auth, false);
-
228 }
executed: }
Execution Count:18
18
229 // clear the userinfo, since we use the same request for resending -
230 // userinfo in url can conflict with the one in the authenticator -
231 url.setUserInfo(QString());
executed (the execution status of this line is deduced): url.setUserInfo(QString());
-
232 request.setUrl(url);
executed (the execution status of this line is deduced): request.setUrl(url);
-
233 }
executed: }
Execution Count:26
26
234 // Will only be false if Qt WebKit is performing a cross-origin XMLHttpRequest -
235 // and withCredentials has not been set to true. -
236 if (request.withCredentials())
evaluated: request.withCredentials()
TRUEFALSE
yes
Evaluation Count:848
yes
Evaluation Count:1
1-848
237 connection->d_func()->createAuthorization(socket, request);
executed: connection->d_func()->createAuthorization(socket, request);
Execution Count:848
848
238#ifndef QT_NO_NETWORKPROXY -
239 QByteArray header = QHttpNetworkRequestPrivate::header(request,
executed (the execution status of this line is deduced): QByteArray header = QHttpNetworkRequestPrivate::header(request,
-
240 (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy));
executed (the execution status of this line is deduced): (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy));
-
241#else -
242 QByteArray header = QHttpNetworkRequestPrivate::header(request, false); -
243#endif -
244 socket->write(header);
executed (the execution status of this line is deduced): socket->write(header);
-
245 // flushing is dangerous (QSslSocket calls transmit which might read or error) -
246// socket->flush(); -
247 QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
executed (the execution status of this line is deduced): QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
-
248 if (uploadByteDevice) {
evaluated: uploadByteDevice
TRUEFALSE
yes
Evaluation Count:225
yes
Evaluation Count:624
225-624
249 // connect the signals so this function gets called again -
250 QObject::connect(uploadByteDevice, SIGNAL(readyRead()),this, SLOT(_q_uploadDataReadyRead()));
executed (the execution status of this line is deduced): QObject::connect(uploadByteDevice, "2""readyRead()",this, "1""_q_uploadDataReadyRead()");
-
251 -
252 bytesTotal = request.contentLength();
executed (the execution status of this line is deduced): bytesTotal = request.contentLength();
-
253 -
254 state = QHttpNetworkConnectionChannel::WritingState; // start writing data
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::WritingState;
-
255 sendRequest(); //recurse
executed (the execution status of this line is deduced): sendRequest();
-
256 } else {
executed: }
Execution Count:225
225
257 state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::WaitingState;
-
258 sendRequest(); //recurse
executed (the execution status of this line is deduced): sendRequest();
-
259 }
executed: }
Execution Count:624
624
260 -
261 break;
executed: break;
Execution Count:849
849
262 } -
263 case QHttpNetworkConnectionChannel::WritingState: -
264 { -
265 // write the data -
266 QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
executed (the execution status of this line is deduced): QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
-
267 if (!uploadByteDevice || bytesTotal == written) {
partially evaluated: !uploadByteDevice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5023
evaluated: bytesTotal == written
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:4992
0-5023
268 if (uploadByteDevice)
partially evaluated: uploadByteDevice
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
0-31
269 emit reply->dataSendProgress(written, bytesTotal);
executed: reply->dataSendProgress(written, bytesTotal);
Execution Count:31
31
270 state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::WaitingState;
-
271 sendRequest(); // recurse
executed (the execution status of this line is deduced): sendRequest();
-
272 break;
executed: break;
Execution Count:31
31
273 } -
274 -
275 // only feed the QTcpSocket buffer when there is less than 32 kB in it -
276 const qint64 socketBufferFill = 32*1024;
executed (the execution status of this line is deduced): const qint64 socketBufferFill = 32*1024;
-
277 const qint64 socketWriteMaxSize = 16*1024;
executed (the execution status of this line is deduced): const qint64 socketWriteMaxSize = 16*1024;
-
278 -
279 -
280#ifndef QT_NO_SSL -
281 QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
executed (the execution status of this line is deduced): QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
-
282 // if it is really an ssl socket, check more than just bytesToWrite() -
283 while ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0))
evaluated: (socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) <= socketBufferFill
TRUEFALSE
yes
Evaluation Count:6309
yes
Evaluation Count:1082
evaluated: sslSocket
TRUEFALSE
yes
Evaluation Count:3758
yes
Evaluation Count:3633
1082-6309
284 <= socketBufferFill && bytesTotal != written)
evaluated: (socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) <= socketBufferFill
TRUEFALSE
yes
Evaluation Count:6309
yes
Evaluation Count:1082
partially evaluated: bytesTotal != written
TRUEFALSE
yes
Evaluation Count:6309
no
Evaluation Count:0
0-6309
285#else -
286 while (socket->bytesToWrite() <= socketBufferFill -
287 && bytesTotal != written) -
288#endif -
289 { -
290 // get pointer to upload data -
291 qint64 currentReadSize = 0;
executed (the execution status of this line is deduced): qint64 currentReadSize = 0;
-
292 qint64 desiredReadSize = qMin(socketWriteMaxSize, bytesTotal - written);
executed (the execution status of this line is deduced): qint64 desiredReadSize = qMin(socketWriteMaxSize, bytesTotal - written);
-
293 const char *readPointer = uploadByteDevice->readPointer(desiredReadSize, currentReadSize);
executed (the execution status of this line is deduced): const char *readPointer = uploadByteDevice->readPointer(desiredReadSize, currentReadSize);
-
294 -
295 if (currentReadSize == -1) {
partially evaluated: currentReadSize == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6309
0-6309
296 // premature eof happened -
297 connection->d_func()->emitReplyError(socket, reply, QNetworkReply::UnknownNetworkError);
never executed (the execution status of this line is deduced): connection->d_func()->emitReplyError(socket, reply, QNetworkReply::UnknownNetworkError);
-
298 return false;
never executed: return false;
0
299 } else if (readPointer == 0 || currentReadSize == 0) {
evaluated: readPointer == 0
TRUEFALSE
yes
Evaluation Count:3717
yes
Evaluation Count:2592
partially evaluated: currentReadSize == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2592
0-3717
300 // nothing to read currently, break the loop -
301 break;
executed: break;
Execution Count:3717
3717
302 } else { -
303 qint64 currentWriteSize = socket->write(readPointer, currentReadSize);
executed (the execution status of this line is deduced): qint64 currentWriteSize = socket->write(readPointer, currentReadSize);
-
304 if (currentWriteSize == -1 || currentWriteSize != currentReadSize) {
partially evaluated: currentWriteSize == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2592
partially evaluated: currentWriteSize != currentReadSize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2592
0-2592
305 // socket broke down -
306 connection->d_func()->emitReplyError(socket, reply, QNetworkReply::UnknownNetworkError);
never executed (the execution status of this line is deduced): connection->d_func()->emitReplyError(socket, reply, QNetworkReply::UnknownNetworkError);
-
307 return false;
never executed: return false;
0
308 } else { -
309 written += currentWriteSize;
executed (the execution status of this line is deduced): written += currentWriteSize;
-
310 uploadByteDevice->advanceReadPointer(currentWriteSize);
executed (the execution status of this line is deduced): uploadByteDevice->advanceReadPointer(currentWriteSize);
-
311 -
312 emit reply->dataSendProgress(written, bytesTotal);
executed (the execution status of this line is deduced): reply->dataSendProgress(written, bytesTotal);
-
313 -
314 if (written == bytesTotal) {
evaluated: written == bytesTotal
TRUEFALSE
yes
Evaluation Count:193
yes
Evaluation Count:2399
193-2399
315 // make sure this function is called once again -
316 state = QHttpNetworkConnectionChannel::WaitingState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::WaitingState;
-
317 sendRequest();
executed (the execution status of this line is deduced): sendRequest();
-
318 break;
executed: break;
Execution Count:193
193
319 } -
320 }
executed: }
Execution Count:2399
2399
321 } -
322 } -
323 break;
executed: break;
Execution Count:4992
4992
324 } -
325 -
326 case QHttpNetworkConnectionChannel::WaitingState: -
327 { -
328 QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
executed (the execution status of this line is deduced): QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
-
329 if (uploadByteDevice) {
evaluated: uploadByteDevice
TRUEFALSE
yes
Evaluation Count:224
yes
Evaluation Count:624
224-624
330 QObject::disconnect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(_q_uploadDataReadyRead()));
executed (the execution status of this line is deduced): QObject::disconnect(uploadByteDevice, "2""readyRead()", this, "1""_q_uploadDataReadyRead()");
-
331 }
executed: }
Execution Count:224
224
332 -
333 // HTTP pipelining -
334 //connection->d_func()->fillPipeline(socket); -
335 //socket->flush(); -
336 -
337 // ensure we try to receive a reply in all cases, even if _q_readyRead_ hat not been called -
338 // this is needed if the sends an reply before we have finished sending the request. In that -
339 // case receiveReply had been called before but ignored the server reply -
340 if (socket->bytesAvailable())
evaluated: socket->bytesAvailable()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:841
7-841
341 QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection);
Execution Count:7
7
342 break;
executed: break;
Execution Count:848
848
343 } -
344 case QHttpNetworkConnectionChannel::ReadingState: -
345 // ignore _q_bytesWritten in these states -
346 // fall through -
347 default: -
348 break;
never executed: break;
0
349 } -
350 return true;
executed: return true;
Execution Count:6720
6720
351} -
352 -
353 -
354void QHttpNetworkConnectionChannel::_q_receiveReply() -
355{ -
356 Q_ASSERT(socket);
executed (the execution status of this line is deduced): qt_noop();
-
357 -
358 if (!reply) {
partially evaluated: !reply
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10173
0-10173
359 if (socket->bytesAvailable() > 0)
never evaluated: socket->bytesAvailable() > 0
0
360 qWarning() << "QHttpNetworkConnectionChannel::_q_receiveReply() called without QHttpNetworkReply,"
never executed: QMessageLogger("access/qhttpnetworkconnectionchannel.cpp", 360, __PRETTY_FUNCTION__).warning() << "QHttpNetworkConnectionChannel::_q_receiveReply() called without QHttpNetworkReply," << socket->bytesAvailable() << "bytes on socket.";
0
361 << socket->bytesAvailable() << "bytes on socket.";
never executed: QMessageLogger("access/qhttpnetworkconnectionchannel.cpp", 360, __PRETTY_FUNCTION__).warning() << "QHttpNetworkConnectionChannel::_q_receiveReply() called without QHttpNetworkReply," << socket->bytesAvailable() << "bytes on socket.";
0
362 close();
never executed (the execution status of this line is deduced): close();
-
363 return;
never executed: return;
0
364 } -
365 -
366 // only run when the QHttpNetworkConnection is not currently being destructed, e.g. -
367 // this function is called from _q_disconnected which is called because -
368 // of ~QHttpNetworkConnectionPrivate -
369 if (!qobject_cast<QHttpNetworkConnection*>(connection)) {
partially evaluated: !qobject_cast<QHttpNetworkConnection*>(connection)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10173
0-10173
370 return;
never executed: return;
0
371 } -
372 -
373 QAbstractSocket::SocketState socketState = socket->state();
executed (the execution status of this line is deduced): QAbstractSocket::SocketState socketState = socket->state();
-
374 -
375 // connection might be closed to signal the end of data -
376 if (socketState == QAbstractSocket::UnconnectedState) {
evaluated: socketState == QAbstractSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:10155
18-10155
377 if (socket->bytesAvailable() <= 0) {
evaluated: socket->bytesAvailable() <= 0
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:1
1-17
378 if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) {
evaluated: reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:7
7-10
379 // finish this reply. this case happens when the server did not send a content length -
380 reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState;
executed (the execution status of this line is deduced): reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState;
-
381 allDone();
executed (the execution status of this line is deduced): allDone();
-
382 return;
executed: return;
Execution Count:10
10
383 } else { -
384 handleUnexpectedEOF();
executed (the execution status of this line is deduced): handleUnexpectedEOF();
-
385 return;
executed: return;
Execution Count:7
7
386 } -
387 } else { -
388 // socket not connected but still bytes for reading.. just continue in this function -
389 }
executed: }
Execution Count:1
1
390 } -
391 -
392 // read loop for the response -
393 qint64 bytes = 0;
executed (the execution status of this line is deduced): qint64 bytes = 0;
-
394 qint64 lastBytes = bytes;
executed (the execution status of this line is deduced): qint64 lastBytes = bytes;
-
395 do { -
396 lastBytes = bytes;
executed (the execution status of this line is deduced): lastBytes = bytes;
-
397 -
398 QHttpNetworkReplyPrivate::ReplyState state = reply->d_func()->state;
executed (the execution status of this line is deduced): QHttpNetworkReplyPrivate::ReplyState state = reply->d_func()->state;
-
399 switch (state) { -
400 case QHttpNetworkReplyPrivate::NothingDoneState: { -
401 state = reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
executed (the execution status of this line is deduced): state = reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
-
402 // fallthrough -
403 } -
404 case QHttpNetworkReplyPrivate::ReadingStatusState: { -
405 qint64 statusBytes = reply->d_func()->readStatus(socket);
executed (the execution status of this line is deduced): qint64 statusBytes = reply->d_func()->readStatus(socket);
-
406 if (statusBytes == -1) {
evaluated: statusBytes == -1
TRUEFALSE
yes
Evaluation Count:52
yes
Evaluation Count:844
52-844
407 // connection broke while reading status. also handled if later _q_disconnected is called -
408 handleUnexpectedEOF();
executed (the execution status of this line is deduced): handleUnexpectedEOF();
-
409 return;
executed: return;
Execution Count:52
52
410 } -
411 bytes += statusBytes;
executed (the execution status of this line is deduced): bytes += statusBytes;
-
412 lastStatus = reply->d_func()->statusCode;
executed (the execution status of this line is deduced): lastStatus = reply->d_func()->statusCode;
-
413 break;
executed: break;
Execution Count:844
844
414 } -
415 case QHttpNetworkReplyPrivate::ReadingHeaderState: { -
416 QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
executed (the execution status of this line is deduced): QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
-
417 qint64 headerBytes = replyPrivate->readHeader(socket);
executed (the execution status of this line is deduced): qint64 headerBytes = replyPrivate->readHeader(socket);
-
418 if (headerBytes == -1) {
evaluated: headerBytes == -1
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:867
5-867
419 // connection broke while reading headers. also handled if later _q_disconnected is called -
420 handleUnexpectedEOF();
executed (the execution status of this line is deduced): handleUnexpectedEOF();
-
421 return;
executed: return;
Execution Count:5
5
422 } -
423 bytes += headerBytes;
executed (the execution status of this line is deduced): bytes += headerBytes;
-
424 // If headers were parsed successfully now it is the ReadingDataState -
425 if (replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState) {
evaluated: replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState
TRUEFALSE
yes
Evaluation Count:796
yes
Evaluation Count:71
71-796
426 if (replyPrivate->isCompressed() && replyPrivate->autoDecompress) {
evaluated: replyPrivate->isCompressed()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:786
partially evaluated: replyPrivate->autoDecompress
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-786
427 // remove the Content-Length from header -
428 replyPrivate->removeAutoDecompressHeader();
executed (the execution status of this line is deduced): replyPrivate->removeAutoDecompressHeader();
-
429 } else {
executed: }
Execution Count:10
10
430 replyPrivate->autoDecompress = false;
executed (the execution status of this line is deduced): replyPrivate->autoDecompress = false;
-
431 }
executed: }
Execution Count:786
786
432 if (replyPrivate->statusCode == 100) {
evaluated: replyPrivate->statusCode == 100
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:789
7-789
433 replyPrivate->clearHttpLayerInformation();
executed (the execution status of this line is deduced): replyPrivate->clearHttpLayerInformation();
-
434 replyPrivate->state = QHttpNetworkReplyPrivate::ReadingStatusState;
executed (the execution status of this line is deduced): replyPrivate->state = QHttpNetworkReplyPrivate::ReadingStatusState;
-
435 break; // ignore
executed: break;
Execution Count:7
7
436 } -
437 if (replyPrivate->shouldEmitSignals())
evaluated: replyPrivate->shouldEmitSignals()
TRUEFALSE
yes
Evaluation Count:604
yes
Evaluation Count:185
185-604
438 emit reply->headerChanged();
executed: reply->headerChanged();
Execution Count:604
604
439 // After headerChanged had been emitted -
440 // we can suddenly have a replyPrivate->userProvidedDownloadBuffer -
441 // this is handled in the ReadingDataState however -
442 -
443 if (!replyPrivate->expectContent()) {
evaluated: !replyPrivate->expectContent()
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:714
75-714
444 replyPrivate->state = QHttpNetworkReplyPrivate::AllDoneState;
executed (the execution status of this line is deduced): replyPrivate->state = QHttpNetworkReplyPrivate::AllDoneState;
-
445 allDone();
executed (the execution status of this line is deduced): allDone();
-
446 break;
executed: break;
Execution Count:75
75
447 } -
448 }
executed: }
Execution Count:714
714
449 break;
executed: break;
Execution Count:785
785
450 } -
451 case QHttpNetworkReplyPrivate::ReadingDataState: { -
452 QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
executed (the execution status of this line is deduced): QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
-
453 if (socket->state() == QAbstractSocket::ConnectedState &&
evaluated: socket->state() == QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:18886
yes
Evaluation Count:1
1-18886
454 replyPrivate->downstreamLimited && !replyPrivate->responseData.isEmpty() && replyPrivate->shouldEmitSignals()) {
evaluated: replyPrivate->downstreamLimited
TRUEFALSE
yes
Evaluation Count:4380
yes
Evaluation Count:14506
evaluated: !replyPrivate->responseData.isEmpty()
TRUEFALSE
yes
Evaluation Count:2068
yes
Evaluation Count:2312
partially evaluated: replyPrivate->shouldEmitSignals()
TRUEFALSE
yes
Evaluation Count:2068
no
Evaluation Count:0
0-14506
455 // (only do the following when still connected, not when we have already been disconnected and there is still data) -
456 // We already have some HTTP body data. We don't read more from the socket until -
457 // this is fetched by QHttpNetworkAccessHttpBackend. If we would read more, -
458 // we could not limit our read buffer usage. -
459 // We only do this when shouldEmitSignals==true because our HTTP parsing -
460 // always needs to parse the 401/407 replies. Therefore they don't really obey -
461 // to the read buffer maximum size, but we don't care since they should be small. -
462 return;
executed: return;
Execution Count:2068
2068
463 } -
464 -
465 if (replyPrivate->userProvidedDownloadBuffer) {
evaluated: replyPrivate->userProvidedDownloadBuffer
TRUEFALSE
yes
Evaluation Count:5138
yes
Evaluation Count:11681
5138-11681
466 // the user provided a direct buffer where we should put all our data in. -
467 // this only works when we can tell the user the content length and he/she can allocate -
468 // the buffer in that size. -
469 // note that this call will read only from the still buffered data -
470 qint64 haveRead = replyPrivate->readBodyVeryFast(socket, replyPrivate->userProvidedDownloadBuffer + replyPrivate->totalProgress);
executed (the execution status of this line is deduced): qint64 haveRead = replyPrivate->readBodyVeryFast(socket, replyPrivate->userProvidedDownloadBuffer + replyPrivate->totalProgress);
-
471 if (haveRead > 0) {
evaluated: haveRead > 0
TRUEFALSE
yes
Evaluation Count:3163
yes
Evaluation Count:1975
1975-3163
472 bytes += haveRead;
executed (the execution status of this line is deduced): bytes += haveRead;
-
473 replyPrivate->totalProgress += haveRead;
executed (the execution status of this line is deduced): replyPrivate->totalProgress += haveRead;
-
474 // the user will get notified of it via progress signal -
475 emit reply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
executed (the execution status of this line is deduced): reply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
-
476 } else if (haveRead == 0) {
executed: }
Execution Count:3163
evaluated: haveRead == 0
TRUEFALSE
yes
Evaluation Count:1973
yes
Evaluation Count:2
2-3163
477 // Happens since this called in a loop. Currently no bytes available. -
478 } else if (haveRead < 0) {
executed: }
Execution Count:1973
partially evaluated: haveRead < 0
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-1973
479 connection->d_func()->emitReplyError(socket, reply, QNetworkReply::RemoteHostClosedError);
executed (the execution status of this line is deduced): connection->d_func()->emitReplyError(socket, reply, QNetworkReply::RemoteHostClosedError);
-
480 break;
executed: break;
Execution Count:2
2
481 } -
482 } else if (!replyPrivate->isChunked() && !replyPrivate->autoDecompress
evaluated: !replyPrivate->isChunked()
TRUEFALSE
yes
Evaluation Count:11308
yes
Evaluation Count:373
evaluated: !replyPrivate->autoDecompress
TRUEFALSE
yes
Evaluation Count:11253
yes
Evaluation Count:55
55-11308
483 && replyPrivate->bodyLength > 0) {
evaluated: replyPrivate->bodyLength > 0
TRUEFALSE
yes
Evaluation Count:11240
yes
Evaluation Count:13
13-11240
484 // bulk files like images should fulfill these properties and -
485 // we can therefore save on memory copying -
486 qint64 haveRead = replyPrivate->readBodyFast(socket, &replyPrivate->responseData);
executed (the execution status of this line is deduced): qint64 haveRead = replyPrivate->readBodyFast(socket, &replyPrivate->responseData);
-
487 bytes += haveRead;
executed (the execution status of this line is deduced): bytes += haveRead;
-
488 replyPrivate->totalProgress += haveRead;
executed (the execution status of this line is deduced): replyPrivate->totalProgress += haveRead;
-
489 if (replyPrivate->shouldEmitSignals()) {
evaluated: replyPrivate->shouldEmitSignals()
TRUEFALSE
yes
Evaluation Count:11010
yes
Evaluation Count:230
230-11010
490 emit reply->readyRead();
executed (the execution status of this line is deduced): reply->readyRead();
-
491 emit reply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
executed (the execution status of this line is deduced): reply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
-
492 }
executed: }
Execution Count:11010
11010
493 }
executed: }
Execution Count:11240
11240
494 else -
495 { -
496 // use the traditional slower reading (for compressed encoding, chunked encoding, -
497 // no content-length etc) -
498 qint64 haveRead = replyPrivate->readBody(socket, &replyPrivate->responseData);
executed (the execution status of this line is deduced): qint64 haveRead = replyPrivate->readBody(socket, &replyPrivate->responseData);
-
499 if (haveRead > 0) {
evaluated: haveRead > 0
TRUEFALSE
yes
Evaluation Count:276
yes
Evaluation Count:165
165-276
500 bytes += haveRead;
executed (the execution status of this line is deduced): bytes += haveRead;
-
501 replyPrivate->totalProgress += haveRead;
executed (the execution status of this line is deduced): replyPrivate->totalProgress += haveRead;
-
502 if (replyPrivate->shouldEmitSignals()) {
evaluated: replyPrivate->shouldEmitSignals()
TRUEFALSE
yes
Evaluation Count:272
yes
Evaluation Count:4
4-272
503 emit reply->readyRead();
executed (the execution status of this line is deduced): reply->readyRead();
-
504 emit reply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
executed (the execution status of this line is deduced): reply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
-
505 }
executed: }
Execution Count:272
272
506 } else if (haveRead == -1) {
executed: }
Execution Count:276
evaluated: haveRead == -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:164
1-276
507 // Some error occurred -
508 connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolFailure);
executed (the execution status of this line is deduced): connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolFailure);
-
509 break;
executed: break;
Execution Count:1
1
510 } -
511 } -
512 // still in ReadingDataState? This function will be called again by the socket's readyRead -
513 if (replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState)
evaluated: replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState
TRUEFALSE
yes
Evaluation Count:16117
yes
Evaluation Count:699
699-16117
514 break;
executed: break;
Execution Count:16117
16117
515 -
516 // everything done, fall through -
517 } -
518 case QHttpNetworkReplyPrivate::AllDoneState:
code before this statement executed: case QHttpNetworkReplyPrivate::AllDoneState:
Execution Count:699
699
519 allDone();
executed (the execution status of this line is deduced): allDone();
-
520 break;
executed: break;
Execution Count:849
849
521 default: -
522 break;
never executed: break;
0
523 } -
524 } while (bytes != lastBytes && reply);
executed: }
Execution Count:18680
evaluated: bytes != lastBytes
TRUEFALSE
yes
Evaluation Count:11263
yes
Evaluation Count:7417
evaluated: reply
TRUEFALSE
yes
Evaluation Count:10649
yes
Evaluation Count:614
614-18680
525}
executed: }
Execution Count:8031
8031
526 -
527// called when unexpectedly reading a -1 or when data is expected but socket is closed -
528void QHttpNetworkConnectionChannel::handleUnexpectedEOF() -
529{ -
530 Q_ASSERT(reply);
executed (the execution status of this line is deduced): qt_noop();
-
531 if (reconnectAttempts <= 0) {
evaluated: reconnectAttempts <= 0
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:45
19-45
532 // too many errors reading/receiving/parsing the status, close the socket and emit error -
533 requeueCurrentlyPipelinedRequests();
executed (the execution status of this line is deduced): requeueCurrentlyPipelinedRequests();
-
534 close();
executed (the execution status of this line is deduced): close();
-
535 reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket);
executed (the execution status of this line is deduced): reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket);
-
536 emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString);
executed (the execution status of this line is deduced): reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString);
-
537 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
538 } else {
executed: }
Execution Count:19
19
539 reconnectAttempts--;
executed (the execution status of this line is deduced): reconnectAttempts--;
-
540 reply->d_func()->clear();
executed (the execution status of this line is deduced): reply->d_func()->clear();
-
541 reply->d_func()->connection = connection;
executed (the execution status of this line is deduced): reply->d_func()->connection = connection;
-
542 reply->d_func()->connectionChannel = this;
executed (the execution status of this line is deduced): reply->d_func()->connectionChannel = this;
-
543 closeAndResendCurrentRequest();
executed (the execution status of this line is deduced): closeAndResendCurrentRequest();
-
544 }
executed: }
Execution Count:45
45
545} -
546 -
547bool QHttpNetworkConnectionChannel::ensureConnection() -
548{ -
549 if (!isInitialized)
evaluated: !isInitialized
TRUEFALSE
yes
Evaluation Count:531
yes
Evaluation Count:972
531-972
550 init();
executed: init();
Execution Count:531
531
551 -
552 QAbstractSocket::SocketState socketState = socket->state();
executed (the execution status of this line is deduced): QAbstractSocket::SocketState socketState = socket->state();
-
553 -
554 // resend this request after we receive the disconnected signal -
555 if (socketState == QAbstractSocket::ClosingState) {
partially evaluated: socketState == QAbstractSocket::ClosingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1503
0-1503
556 if (reply)
never evaluated: reply
0
557 resendCurrent = true;
never executed: resendCurrent = true;
0
558 return false;
never executed: return false;
0
559 } -
560 -
561 // already trying to connect? -
562 if (socketState == QAbstractSocket::HostLookupState ||
partially evaluated: socketState == QAbstractSocket::HostLookupState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1503
0-1503
563 socketState == QAbstractSocket::ConnectingState) {
partially evaluated: socketState == QAbstractSocket::ConnectingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1503
0-1503
564 return false;
never executed: return false;
0
565 } -
566 -
567 // make sure that this socket is in a connected state, if not initiate -
568 // connection to the host. -
569 if (socketState != QAbstractSocket::ConnectedState) {
evaluated: socketState != QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:654
yes
Evaluation Count:849
654-849
570 // connect to the host if not already connected. -
571 state = QHttpNetworkConnectionChannel::ConnectingState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::ConnectingState;
-
572 pendingEncrypt = ssl;
executed (the execution status of this line is deduced): pendingEncrypt = ssl;
-
573 -
574 // reset state -
575 pipeliningSupported = PipeliningSupportUnknown;
executed (the execution status of this line is deduced): pipeliningSupported = PipeliningSupportUnknown;
-
576 authenticationCredentialsSent = false;
executed (the execution status of this line is deduced): authenticationCredentialsSent = false;
-
577 proxyCredentialsSent = false;
executed (the execution status of this line is deduced): proxyCredentialsSent = false;
-
578 authenticator.detach();
executed (the execution status of this line is deduced): authenticator.detach();
-
579 QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator);
executed (the execution status of this line is deduced): QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator);
-
580 priv->hasFailed = false;
executed (the execution status of this line is deduced): priv->hasFailed = false;
-
581 proxyAuthenticator.detach();
executed (the execution status of this line is deduced): proxyAuthenticator.detach();
-
582 priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
executed (the execution status of this line is deduced): priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
-
583 priv->hasFailed = false;
executed (the execution status of this line is deduced): priv->hasFailed = false;
-
584 -
585 // This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done" -
586 // is the usual criteria for emitting authentication signals. The "phase" is set to "Done" when the -
587 // last header for Authorization is generated by the QAuthenticator. Basic & Digest logic does not -
588 // check the "phase" for generating the Authorization header. NTLM authentication is a two stage -
589 // process & needs the "phase". To make sure the QAuthenticator uses the current username/password -
590 // the phase is reset to Start. -
591 priv = QAuthenticatorPrivate::getPrivate(authenticator);
executed (the execution status of this line is deduced): priv = QAuthenticatorPrivate::getPrivate(authenticator);
-
592 if (priv && priv->phase == QAuthenticatorPrivate::Done)
partially evaluated: priv
TRUEFALSE
yes
Evaluation Count:654
no
Evaluation Count:0
partially evaluated: priv->phase == QAuthenticatorPrivate::Done
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:654
0-654
593 priv->phase = QAuthenticatorPrivate::Start;
never executed: priv->phase = QAuthenticatorPrivate::Start;
0
594 priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
executed (the execution status of this line is deduced): priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
-
595 if (priv && priv->phase == QAuthenticatorPrivate::Done)
partially evaluated: priv
TRUEFALSE
yes
Evaluation Count:654
no
Evaluation Count:0
partially evaluated: priv->phase == QAuthenticatorPrivate::Done
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:654
0-654
596 priv->phase = QAuthenticatorPrivate::Start;
never executed: priv->phase = QAuthenticatorPrivate::Start;
0
597 -
598 QString connectHost = connection->d_func()->hostName;
executed (the execution status of this line is deduced): QString connectHost = connection->d_func()->hostName;
-
599 qint16 connectPort = connection->d_func()->port;
executed (the execution status of this line is deduced): qint16 connectPort = connection->d_func()->port;
-
600 -
601#ifndef QT_NO_NETWORKPROXY -
602 // HTTPS always use transparent proxy. -
603 if (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy && !ssl) {
evaluated: connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy
TRUEFALSE
yes
Evaluation Count:100
yes
Evaluation Count:554
partially evaluated: !ssl
TRUEFALSE
yes
Evaluation Count:100
no
Evaluation Count:0
0-554
604 connectHost = connection->d_func()->networkProxy.hostName();
executed (the execution status of this line is deduced): connectHost = connection->d_func()->networkProxy.hostName();
-
605 connectPort = connection->d_func()->networkProxy.port();
executed (the execution status of this line is deduced): connectPort = connection->d_func()->networkProxy.port();
-
606 }
executed: }
Execution Count:100
100
607 if (socket->proxy().type() == QNetworkProxy::HttpProxy) {
evaluated: socket->proxy().type() == QNetworkProxy::HttpProxy
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:637
17-637
608 // Make user-agent field available to HTTP proxy socket engine (QTBUG-17223) -
609 QByteArray value;
executed (the execution status of this line is deduced): QByteArray value;
-
610 // ensureConnection is called before any request has been assigned, but can also be called again if reconnecting -
611 if (request.url().isEmpty())
evaluated: request.url().isEmpty()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:2
2-15
612 value = connection->d_func()->predictNextRequest().headerField("user-agent");
executed: value = connection->d_func()->predictNextRequest().headerField("user-agent");
Execution Count:15
15
613 else -
614 value = request.headerField("user-agent");
executed: value = request.headerField("user-agent");
Execution Count:2
2
615 if (!value.isEmpty()) {
evaluated: !value.isEmpty()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:12
5-12
616 QNetworkProxy proxy(socket->proxy());
executed (the execution status of this line is deduced): QNetworkProxy proxy(socket->proxy());
-
617 proxy.setRawHeader("User-Agent", value); //detaches
executed (the execution status of this line is deduced): proxy.setRawHeader("User-Agent", value);
-
618 socket->setProxy(proxy);
executed (the execution status of this line is deduced): socket->setProxy(proxy);
-
619 }
executed: }
Execution Count:5
5
620 }
executed: }
Execution Count:17
17
621#endif -
622 if (ssl) {
evaluated: ssl
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:567
87-567
623#ifndef QT_NO_SSL -
624 QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
executed (the execution status of this line is deduced): QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
-
625 sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference);
executed (the execution status of this line is deduced): sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference);
-
626 if (ignoreAllSslErrors)
evaluated: ignoreAllSslErrors
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:79
8-79
627 sslSocket->ignoreSslErrors();
executed: sslSocket->ignoreSslErrors();
Execution Count:8
8
628 sslSocket->ignoreSslErrors(ignoreSslErrorsList);
executed (the execution status of this line is deduced): sslSocket->ignoreSslErrors(ignoreSslErrorsList);
-
629 -
630 // limit the socket read buffer size. we will read everything into -
631 // the QHttpNetworkReply anyway, so let's grow only that and not -
632 // here and there. -
633 socket->setReadBufferSize(64*1024);
executed (the execution status of this line is deduced): socket->setReadBufferSize(64*1024);
-
634#else -
635 // Need to dequeue the request so that we can emit the error. -
636 if (!reply) -
637 connection->d_func()->dequeueRequest(socket); -
638 connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); -
639#endif -
640 } else {
executed: }
Execution Count:87
87
641 // In case of no proxy we can use the Unbuffered QTcpSocket -
642#ifndef QT_NO_NETWORKPROXY -
643 if (connection->d_func()->networkProxy.type() == QNetworkProxy::NoProxy
evaluated: connection->d_func()->networkProxy.type() == QNetworkProxy::NoProxy
TRUEFALSE
yes
Evaluation Count:467
yes
Evaluation Count:100
100-467
644 && connection->cacheProxy().type() == QNetworkProxy::NoProxy
partially evaluated: connection->cacheProxy().type() == QNetworkProxy::NoProxy
TRUEFALSE
yes
Evaluation Count:467
no
Evaluation Count:0
0-467
645 && connection->transparentProxy().type() == QNetworkProxy::NoProxy) {
evaluated: connection->transparentProxy().type() == QNetworkProxy::NoProxy
TRUEFALSE
yes
Evaluation Count:425
yes
Evaluation Count:42
42-425
646#endif -
647 socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered, networkLayerPreference);
executed (the execution status of this line is deduced): socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered, networkLayerPreference);
-
648 // For an Unbuffered QTcpSocket, the read buffer size has a special meaning. -
649 socket->setReadBufferSize(1*1024);
executed (the execution status of this line is deduced): socket->setReadBufferSize(1*1024);
-
650#ifndef QT_NO_NETWORKPROXY -
651 } else {
executed: }
Execution Count:425
425
652 socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference);
executed (the execution status of this line is deduced): socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference);
-
653 -
654 // limit the socket read buffer size. we will read everything into -
655 // the QHttpNetworkReply anyway, so let's grow only that and not -
656 // here and there. -
657 socket->setReadBufferSize(64*1024);
executed (the execution status of this line is deduced): socket->setReadBufferSize(64*1024);
-
658 }
executed: }
Execution Count:142
142
659#endif -
660 } -
661 return false;
executed: return false;
Execution Count:654
654
662 } -
663 return true;
executed: return true;
Execution Count:849
849
664} -
665 -
666void QHttpNetworkConnectionChannel::allDone() -
667{ -
668 Q_ASSERT(reply);
executed (the execution status of this line is deduced): qt_noop();
-
669 -
670 if (!reply) {
partially evaluated: !reply
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:934
0-934
671 qWarning() << "QHttpNetworkConnectionChannel::allDone() called without reply. Please report at http://bugreports.qt-project.org/";
never executed (the execution status of this line is deduced): QMessageLogger("access/qhttpnetworkconnectionchannel.cpp", 671, __PRETTY_FUNCTION__).warning() << "QHttpNetworkConnectionChannel::allDone() called without reply. Please report at http://bugreports.qt-project.org/";
-
672 return;
never executed: return;
0
673 } -
674 -
675 // while handling 401 & 407, we might reset the status code, so save this. -
676 bool emitFinished = reply->d_func()->shouldEmitSignals();
executed (the execution status of this line is deduced): bool emitFinished = reply->d_func()->shouldEmitSignals();
-
677 bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled();
executed (the execution status of this line is deduced): bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled();
-
678 detectPipeliningSupport();
executed (the execution status of this line is deduced): detectPipeliningSupport();
-
679 -
680 handleStatus();
executed (the execution status of this line is deduced): handleStatus();
-
681 // handleStatus() might have removed the reply because it already called connection->emitReplyError() -
682 -
683 // queue the finished signal, this is required since we might send new requests from -
684 // slot connected to it. The socket will not fire readyRead signal, if we are already -
685 // in the slot connected to readyRead -
686 if (reply && emitFinished)
evaluated: reply
TRUEFALSE
yes
Evaluation Count:933
yes
Evaluation Count:1
evaluated: emitFinished
TRUEFALSE
yes
Evaluation Count:599
yes
Evaluation Count:334
1-933
687 QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection);
Execution Count:599
599
688 -
689 -
690 // reset the reconnection attempts after we receive a complete reply. -
691 // in case of failures, each channel will attempt two reconnects before emitting error. -
692 reconnectAttempts = 2;
executed (the execution status of this line is deduced): reconnectAttempts = 2;
-
693 -
694 // now the channel can be seen as free/idle again, all signal emissions for the reply have been done -
695 if (state != QHttpNetworkConnectionChannel::ClosingState)
evaluated: state != QHttpNetworkConnectionChannel::ClosingState
TRUEFALSE
yes
Evaluation Count:853
yes
Evaluation Count:81
81-853
696 state = QHttpNetworkConnectionChannel::IdleState;
executed: state = QHttpNetworkConnectionChannel::IdleState;
Execution Count:853
853
697 -
698 // if it does not need to be sent again we can set it to 0 -
699 // the previous code did not do that and we had problems with accidental re-sending of a -
700 // finished request. -
701 // Note that this may trigger a segfault at some other point. But then we can fix the underlying -
702 // problem. -
703 if (!resendCurrent) {
evaluated: !resendCurrent
TRUEFALSE
yes
Evaluation Count:632
yes
Evaluation Count:302
302-632
704 request = QHttpNetworkRequest();
executed (the execution status of this line is deduced): request = QHttpNetworkRequest();
-
705 reply = 0;
executed (the execution status of this line is deduced): reply = 0;
-
706 }
executed: }
Execution Count:632
632
707 -
708 // move next from pipeline to current request -
709 if (!alreadyPipelinedRequests.isEmpty()) {
evaluated: !alreadyPipelinedRequests.isEmpty()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:924
10-924
710 if (resendCurrent || connectionCloseEnabled || socket->state() != QAbstractSocket::ConnectedState) {
partially evaluated: resendCurrent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
partially evaluated: connectionCloseEnabled
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
partially evaluated: socket->state() != QAbstractSocket::ConnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
711 // move the pipelined ones back to the main queue -
712 requeueCurrentlyPipelinedRequests();
never executed (the execution status of this line is deduced): requeueCurrentlyPipelinedRequests();
-
713 close();
never executed (the execution status of this line is deduced): close();
-
714 } else {
never executed: }
0
715 // there were requests pipelined in and we can continue -
716 HttpMessagePair messagePair = alreadyPipelinedRequests.takeFirst();
executed (the execution status of this line is deduced): HttpMessagePair messagePair = alreadyPipelinedRequests.takeFirst();
-
717 -
718 request = messagePair.first;
executed (the execution status of this line is deduced): request = messagePair.first;
-
719 reply = messagePair.second;
executed (the execution status of this line is deduced): reply = messagePair.second;
-
720 state = QHttpNetworkConnectionChannel::ReadingState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::ReadingState;
-
721 resendCurrent = false;
executed (the execution status of this line is deduced): resendCurrent = false;
-
722 -
723 written = 0; // message body, excluding the header, irrelevant here
executed (the execution status of this line is deduced): written = 0;
-
724 bytesTotal = 0; // message body total, excluding the header, irrelevant here
executed (the execution status of this line is deduced): bytesTotal = 0;
-
725 -
726 // pipeline even more -
727 connection->d_func()->fillPipeline(socket);
executed (the execution status of this line is deduced): connection->d_func()->fillPipeline(socket);
-
728 -
729 // continue reading -
730 //_q_receiveReply(); -
731 // this was wrong, allDone gets called from that function anyway. -
732 }
executed: }
Execution Count:10
10
733 } else if (alreadyPipelinedRequests.isEmpty() && socket->bytesAvailable() > 0) {
partially evaluated: alreadyPipelinedRequests.isEmpty()
TRUEFALSE
yes
Evaluation Count:924
no
Evaluation Count:0
partially evaluated: socket->bytesAvailable() > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:924
0-924
734 // this is weird. we had nothing pipelined but still bytes available. better close it. -
735 close();
never executed (the execution status of this line is deduced): close();
-
736 -
737 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
never executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
738 } else if (alreadyPipelinedRequests.isEmpty()) {
never executed: }
partially evaluated: alreadyPipelinedRequests.isEmpty()
TRUEFALSE
yes
Evaluation Count:924
no
Evaluation Count:0
0-924
739 if (connectionCloseEnabled)
evaluated: connectionCloseEnabled
TRUEFALSE
yes
Evaluation Count:189
yes
Evaluation Count:735
189-735
740 if (socket->state() != QAbstractSocket::UnconnectedState)
evaluated: socket->state() != QAbstractSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:127
yes
Evaluation Count:62
62-127
741 close();
executed: close();
Execution Count:127
127
742 if (qobject_cast<QHttpNetworkConnection*>(connection))
partially evaluated: qobject_cast<QHttpNetworkConnection*>(connection)
TRUEFALSE
yes
Evaluation Count:924
no
Evaluation Count:0
0-924
743 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
Execution Count:924
924
744 }
executed: }
Execution Count:924
924
745} -
746 -
747void QHttpNetworkConnectionChannel::detectPipeliningSupport() -
748{ -
749 Q_ASSERT(reply);
executed (the execution status of this line is deduced): qt_noop();
-
750 // detect HTTP Pipelining support -
751 QByteArray serverHeaderField;
executed (the execution status of this line is deduced): QByteArray serverHeaderField;
-
752 if ( -
753 // check for HTTP/1.1 -
754 (reply->d_func()->majorVersion == 1 && reply->d_func()->minorVersion == 1)
partially evaluated: reply->d_func()->majorVersion == 1
TRUEFALSE
yes
Evaluation Count:934
no
Evaluation Count:0
evaluated: reply->d_func()->minorVersion == 1
TRUEFALSE
yes
Evaluation Count:685
yes
Evaluation Count:249
0-934
755 // check for not having connection close
executed (the execution status of this line is deduced):
-
756 && (!reply->d_func()->isConnectionCloseEnabled())
evaluated: (!reply->d_func()->isConnectionCloseEnabled())
TRUEFALSE
yes
Evaluation Count:683
yes
Evaluation Count:2
2-683
757 // check if it is still connected
executed (the execution status of this line is deduced):
-
758 && (socket->state() == QAbstractSocket::ConnectedState)
evaluated: (socket->state() == QAbstractSocket::ConnectedState)
TRUEFALSE
yes
Evaluation Count:679
yes
Evaluation Count:4
4-679
759 // check for broken servers in server reply header
executed (the execution status of this line is deduced):
-
760 // this is adapted from http://mxr.mozilla.org/firefox/ident?i=SupportsPipelining
executed (the execution status of this line is deduced):
-
761 && (serverHeaderField = reply->headerField("Server"), !serverHeaderField.contains("Microsoft-IIS/4."))
partially evaluated: (serverHeaderField = reply->headerField("Server"), !serverHeaderField.contains("Microsoft-IIS/4."))
TRUEFALSE
yes
Evaluation Count:679
no
Evaluation Count:0
0-679
762 && (!serverHeaderField.contains("Microsoft-IIS/5."))
partially evaluated: (!serverHeaderField.contains("Microsoft-IIS/5."))
TRUEFALSE
yes
Evaluation Count:679
no
Evaluation Count:0
0-679
763 && (!serverHeaderField.contains("Netscape-Enterprise/3."))
partially evaluated: (!serverHeaderField.contains("Netscape-Enterprise/3."))
TRUEFALSE
yes
Evaluation Count:679
no
Evaluation Count:0
0-679
764 // this is adpoted from the knowledge of the Nokia 7.x browser team (DEF143319)
executed (the execution status of this line is deduced):
-
765 && (!serverHeaderField.contains("WebLogic"))
partially evaluated: (!serverHeaderField.contains("WebLogic"))
TRUEFALSE
yes
Evaluation Count:679
no
Evaluation Count:0
0-679
766 && (!serverHeaderField.startsWith("Rocket")) // a Python Web Server, see Web2py.com
partially evaluated: (!serverHeaderField.startsWith("Rocket"))
TRUEFALSE
yes
Evaluation Count:679
no
Evaluation Count:0
0-679
767 ) { -
768 pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningProbablySupported;
executed (the execution status of this line is deduced): pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningProbablySupported;
-
769 } else {
executed: }
Execution Count:679
679
770 pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown;
executed (the execution status of this line is deduced): pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown;
-
771 }
executed: }
Execution Count:255
255
772} -
773 -
774// called when the connection broke and we need to queue some pipelined requests again -
775void QHttpNetworkConnectionChannel::requeueCurrentlyPipelinedRequests() -
776{ -
777 for (int i = 0; i < alreadyPipelinedRequests.length(); i++)
partially evaluated: i < alreadyPipelinedRequests.length()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:98
0-98
778 connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i));
never executed: connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i));
0
779 alreadyPipelinedRequests.clear();
executed (the execution status of this line is deduced): alreadyPipelinedRequests.clear();
-
780 -
781 // only run when the QHttpNetworkConnection is not currently being destructed, e.g. -
782 // this function is called from _q_disconnected which is called because -
783 // of ~QHttpNetworkConnectionPrivate -
784 if (qobject_cast<QHttpNetworkConnection*>(connection))
partially evaluated: qobject_cast<QHttpNetworkConnection*>(connection)
TRUEFALSE
yes
Evaluation Count:98
no
Evaluation Count:0
0-98
785 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
Execution Count:98
98
786}
executed: }
Execution Count:98
98
787 -
788void QHttpNetworkConnectionChannel::handleStatus() -
789{ -
790 Q_ASSERT(socket);
executed (the execution status of this line is deduced): qt_noop();
-
791 Q_ASSERT(reply);
executed (the execution status of this line is deduced): qt_noop();
-
792 -
793 int statusCode = reply->statusCode();
executed (the execution status of this line is deduced): int statusCode = reply->statusCode();
-
794 bool resend = false;
executed (the execution status of this line is deduced): bool resend = false;
-
795 -
796 switch (statusCode) { -
797 case 401: // auth required -
798 case 407: // proxy auth required -
799 if (connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) {
evaluated: connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)
TRUEFALSE
yes
Evaluation Count:332
yes
Evaluation Count:3
3-332
800 if (resend) {
evaluated: resend
TRUEFALSE
yes
Evaluation Count:301
yes
Evaluation Count:31
31-301
801 if (!resetUploadData())
evaluated: !resetUploadData()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:300
1-300
802 break;
executed: break;
Execution Count:1
1
803 -
804 reply->d_func()->eraseData();
executed (the execution status of this line is deduced): reply->d_func()->eraseData();
-
805 -
806 if (alreadyPipelinedRequests.isEmpty()) {
partially evaluated: alreadyPipelinedRequests.isEmpty()
TRUEFALSE
yes
Evaluation Count:300
no
Evaluation Count:0
0-300
807 // this does a re-send without closing the connection -
808 resendCurrent = true;
executed (the execution status of this line is deduced): resendCurrent = true;
-
809 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
810 } else {
executed: }
Execution Count:300
300
811 // we had requests pipelined.. better close the connection in closeAndResendCurrentRequest -
812 closeAndResendCurrentRequest();
never executed (the execution status of this line is deduced): closeAndResendCurrentRequest();
-
813 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
never executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
814 }
never executed: }
0
815 } else { -
816 //authentication cancelled, close the channel. -
817 close();
executed (the execution status of this line is deduced): close();
-
818 }
executed: }
Execution Count:31
31
819 } else { -
820 emit reply->headerChanged();
executed (the execution status of this line is deduced): reply->headerChanged();
-
821 emit reply->readyRead();
executed (the execution status of this line is deduced): reply->readyRead();
-
822 QNetworkReply::NetworkError errorCode = (statusCode == 407)
evaluated: (statusCode == 407)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
823 ? QNetworkReply::ProxyAuthenticationRequiredError
executed (the execution status of this line is deduced): ? QNetworkReply::ProxyAuthenticationRequiredError
-
824 : QNetworkReply::AuthenticationRequiredError;
executed (the execution status of this line is deduced): : QNetworkReply::AuthenticationRequiredError;
-
825 reply->d_func()->errorString = connection->d_func()->errorDetail(errorCode, socket);
executed (the execution status of this line is deduced): reply->d_func()->errorString = connection->d_func()->errorDetail(errorCode, socket);
-
826 emit reply->finishedWithError(errorCode, reply->d_func()->errorString);
executed (the execution status of this line is deduced): reply->finishedWithError(errorCode, reply->d_func()->errorString);
-
827 }
executed: }
Execution Count:3
3
828 break;
executed: break;
Execution Count:334
334
829 default: -
830 if (qobject_cast<QHttpNetworkConnection*>(connection))
partially evaluated: qobject_cast<QHttpNetworkConnection*>(connection)
TRUEFALSE
yes
Evaluation Count:599
no
Evaluation Count:0
0-599
831 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
Execution Count:599
599
832 }
executed: }
Execution Count:599
599
833}
executed: }
Execution Count:934
934
834 -
835bool QHttpNetworkConnectionChannel::resetUploadData() -
836{ -
837 if (!reply) {
partially evaluated: !reply
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:494
0-494
838 //this happens if server closes connection while QHttpNetworkConnectionPrivate::_q_startNextRequest is pending -
839 return false;
never executed: return false;
0
840 } -
841 QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
executed (the execution status of this line is deduced): QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
-
842 if (!uploadByteDevice)
evaluated: !uploadByteDevice
TRUEFALSE
yes
Evaluation Count:357
yes
Evaluation Count:137
137-357
843 return true;
executed: return true;
Execution Count:357
357
844 -
845 if (uploadByteDevice->reset()) {
evaluated: uploadByteDevice->reset()
TRUEFALSE
yes
Evaluation Count:136
yes
Evaluation Count:1
1-136
846 written = 0;
executed (the execution status of this line is deduced): written = 0;
-
847 return true;
executed: return true;
Execution Count:136
136
848 } else { -
849 connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError);
executed (the execution status of this line is deduced): connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError);
-
850 return false;
executed: return false;
Execution Count:1
1
851 } -
852} -
853 -
854#ifndef QT_NO_NETWORKPROXY -
855 -
856void QHttpNetworkConnectionChannel::setProxy(const QNetworkProxy &networkProxy) -
857{ -
858 if (socket)
partially evaluated: socket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3042
0-3042
859 socket->setProxy(networkProxy);
never executed: socket->setProxy(networkProxy);
0
860 -
861 proxy = networkProxy;
executed (the execution status of this line is deduced): proxy = networkProxy;
-
862}
executed: }
Execution Count:3042
3042
863 -
864#endif -
865 -
866#ifndef QT_NO_SSL -
867 -
868void QHttpNetworkConnectionChannel::ignoreSslErrors() -
869{ -
870 if (socket)
evaluated: socket
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:105
21-105
871 static_cast<QSslSocket *>(socket)->ignoreSslErrors();
executed: static_cast<QSslSocket *>(socket)->ignoreSslErrors();
Execution Count:21
21
872 -
873 ignoreAllSslErrors = true;
executed (the execution status of this line is deduced): ignoreAllSslErrors = true;
-
874}
executed: }
Execution Count:126
126
875 -
876 -
877void QHttpNetworkConnectionChannel::ignoreSslErrors(const QList<QSslError> &errors) -
878{ -
879 if (socket)
evaluated: socket
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:30
6-30
880 static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors);
executed: static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors);
Execution Count:6
6
881 -
882 ignoreSslErrorsList = errors;
executed (the execution status of this line is deduced): ignoreSslErrorsList = errors;
-
883}
executed: }
Execution Count:36
36
884 -
885void QHttpNetworkConnectionChannel::setSslConfiguration(const QSslConfiguration &config) -
886{ -
887 if (socket)
partially evaluated: socket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:258
0-258
888 static_cast<QSslSocket *>(socket)->setSslConfiguration(config);
never executed: static_cast<QSslSocket *>(socket)->setSslConfiguration(config);
0
889 -
890 sslConfiguration = config;
executed (the execution status of this line is deduced): sslConfiguration = config;
-
891}
executed: }
Execution Count:258
258
892 -
893#endif -
894 -
895void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) -
896{ -
897 // this is only called for simple GET -
898 -
899 QHttpNetworkRequest &request = pair.first;
executed (the execution status of this line is deduced): QHttpNetworkRequest &request = pair.first;
-
900 QHttpNetworkReply *reply = pair.second;
executed (the execution status of this line is deduced): QHttpNetworkReply *reply = pair.second;
-
901 reply->d_func()->clear();
executed (the execution status of this line is deduced): reply->d_func()->clear();
-
902 reply->d_func()->connection = connection;
executed (the execution status of this line is deduced): reply->d_func()->connection = connection;
-
903 reply->d_func()->connectionChannel = this;
executed (the execution status of this line is deduced): reply->d_func()->connectionChannel = this;
-
904 reply->d_func()->autoDecompress = request.d->autoDecompress;
executed (the execution status of this line is deduced): reply->d_func()->autoDecompress = request.d->autoDecompress;
-
905 reply->d_func()->pipeliningUsed = true;
executed (the execution status of this line is deduced): reply->d_func()->pipeliningUsed = true;
-
906 -
907#ifndef QT_NO_NETWORKPROXY -
908 pipeline.append(QHttpNetworkRequestPrivate::header(request,
executed (the execution status of this line is deduced): pipeline.append(QHttpNetworkRequestPrivate::header(request,
-
909 (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy)));
executed (the execution status of this line is deduced): (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy)));
-
910#else -
911 pipeline.append(QHttpNetworkRequestPrivate::header(request, false)); -
912#endif -
913 -
914 alreadyPipelinedRequests.append(pair);
executed (the execution status of this line is deduced): alreadyPipelinedRequests.append(pair);
-
915 -
916 // pipelineFlush() needs to be called at some point afterwards -
917}
executed: }
Execution Count:10
10
918 -
919void QHttpNetworkConnectionChannel::pipelineFlush() -
920{ -
921 if (pipeline.isEmpty())
partially evaluated: pipeline.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
922 return;
never executed: return;
0
923 -
924 // The goal of this is so that we have everything in one TCP packet. -
925 // For the Unbuffered QTcpSocket this is manually needed, the buffered -
926 // QTcpSocket does it automatically. -
927 // Also, sometimes the OS does it for us (Nagle's algorithm) but that -
928 // happens only sometimes. -
929 socket->write(pipeline);
executed (the execution status of this line is deduced): socket->write(pipeline);
-
930 pipeline.clear();
executed (the execution status of this line is deduced): pipeline.clear();
-
931}
executed: }
Execution Count:4
4
932 -
933 -
934void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest() -
935{ -
936 requeueCurrentlyPipelinedRequests();
executed (the execution status of this line is deduced): requeueCurrentlyPipelinedRequests();
-
937 close();
executed (the execution status of this line is deduced): close();
-
938 if (reply)
evaluated: reply
TRUEFALSE
yes
Evaluation Count:54
yes
Evaluation Count:4
4-54
939 resendCurrent = true;
executed: resendCurrent = true;
Execution Count:54
54
940 if (qobject_cast<QHttpNetworkConnection*>(connection))
partially evaluated: qobject_cast<QHttpNetworkConnection*>(connection)
TRUEFALSE
yes
Evaluation Count:58
no
Evaluation Count:0
0-58
941 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
Execution Count:58
58
942}
executed: }
Execution Count:58
58
943 -
944bool QHttpNetworkConnectionChannel::isSocketBusy() const -
945{ -
946 return (state & QHttpNetworkConnectionChannel::BusyState);
executed: return (state & QHttpNetworkConnectionChannel::BusyState);
Execution Count:276
276
947} -
948 -
949bool QHttpNetworkConnectionChannel::isSocketWriting() const -
950{ -
951 return (state & QHttpNetworkConnectionChannel::WritingState);
executed: return (state & QHttpNetworkConnectionChannel::WritingState);
Execution Count:3470
3470
952} -
953 -
954bool QHttpNetworkConnectionChannel::isSocketWaiting() const -
955{ -
956 return (state & QHttpNetworkConnectionChannel::WaitingState);
executed: return (state & QHttpNetworkConnectionChannel::WaitingState);
Execution Count:10173
10173
957} -
958 -
959bool QHttpNetworkConnectionChannel::isSocketReading() const -
960{ -
961 return (state & QHttpNetworkConnectionChannel::ReadingState);
executed: return (state & QHttpNetworkConnectionChannel::ReadingState);
Execution Count:9344
9344
962} -
963 -
964//private slots -
965void QHttpNetworkConnectionChannel::_q_readyRead() -
966{ -
967 if (socket->state() == QAbstractSocket::ConnectedState && socket->bytesAvailable() == 0) {
evaluated: socket->state() == QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:10198
yes
Evaluation Count:1
evaluated: socket->bytesAvailable() == 0
TRUEFALSE
yes
Evaluation Count:591
yes
Evaluation Count:9607
1-10198
968 // We got a readyRead but no bytes are available.. -
969 // This happens for the Unbuffered QTcpSocket -
970 // Also check if socket is in ConnectedState since -
971 // this function may also be invoked via the event loop. -
972 char c;
executed (the execution status of this line is deduced): char c;
-
973 qint64 ret = socket->peek(&c, 1);
executed (the execution status of this line is deduced): qint64 ret = socket->peek(&c, 1);
-
974 if (ret < 0) {
evaluated: ret < 0
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:548
43-548
975 _q_error(socket->error());
executed (the execution status of this line is deduced): _q_error(socket->error());
-
976 // We still need to handle the reply so it emits its signals etc. -
977 if (reply)
evaluated: reply
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:26
17-26
978 _q_receiveReply();
executed: _q_receiveReply();
Execution Count:17
17
979 return;
executed: return;
Execution Count:43
43
980 } -
981 }
executed: }
Execution Count:548
548
982 -
983 if (isSocketWaiting() || isSocketReading()) {
evaluated: isSocketWaiting()
TRUEFALSE
yes
Evaluation Count:829
yes
Evaluation Count:9327
evaluated: isSocketReading()
TRUEFALSE
yes
Evaluation Count:9319
yes
Evaluation Count:8
8-9327
984 state = QHttpNetworkConnectionChannel::ReadingState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::ReadingState;
-
985 if (reply)
partially evaluated: reply
TRUEFALSE
yes
Evaluation Count:10148
no
Evaluation Count:0
0-10148
986 _q_receiveReply();
executed: _q_receiveReply();
Execution Count:10148
10148
987 }
executed: }
Execution Count:10148
10148
988}
executed: }
Execution Count:10156
10156
989 -
990void QHttpNetworkConnectionChannel::_q_bytesWritten(qint64 bytes) -
991{ -
992 Q_UNUSED(bytes);
executed (the execution status of this line is deduced): (void)bytes;;
-
993 // bytes have been written to the socket. write even more of them :) -
994 if (isSocketWriting())
evaluated: isSocketWriting()
TRUEFALSE
yes
Evaluation Count:2091
yes
Evaluation Count:297
297-2091
995 sendRequest();
executed: sendRequest();
Execution Count:2091
2091
996 // otherwise we do nothing -
997}
executed: }
Execution Count:2388
2388
998 -
999void QHttpNetworkConnectionChannel::_q_disconnected() -
1000{ -
1001 if (state == QHttpNetworkConnectionChannel::ClosingState) {
evaluated: state == QHttpNetworkConnectionChannel::ClosingState
TRUEFALSE
yes
Evaluation Count:195
yes
Evaluation Count:17
17-195
1002 state = QHttpNetworkConnectionChannel::IdleState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::IdleState;
-
1003 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
1004 return;
executed: return;
Execution Count:195
195
1005 } -
1006 -
1007 // read the available data before closing -
1008 if (isSocketWaiting() || isSocketReading()) {
partially evaluated: isSocketWaiting()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
partially evaluated: isSocketReading()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
1009 if (reply) {
never evaluated: reply
0
1010 state = QHttpNetworkConnectionChannel::ReadingState;
never executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::ReadingState;
-
1011 _q_receiveReply();
never executed (the execution status of this line is deduced): _q_receiveReply();
-
1012 }
never executed: }
0
1013 } else if (state == QHttpNetworkConnectionChannel::IdleState && resendCurrent) {
never executed: }
partially evaluated: state == QHttpNetworkConnectionChannel::IdleState
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
partially evaluated: resendCurrent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
1014 // re-sending request because the socket was in ClosingState -
1015 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
never executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
1016 }
never executed: }
0
1017 state = QHttpNetworkConnectionChannel::IdleState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::IdleState;
-
1018 -
1019 requeueCurrentlyPipelinedRequests();
executed (the execution status of this line is deduced): requeueCurrentlyPipelinedRequests();
-
1020 close();
executed (the execution status of this line is deduced): close();
-
1021}
executed: }
Execution Count:17
17
1022 -
1023 -
1024void QHttpNetworkConnectionChannel::_q_connected() -
1025{ -
1026 // For the Happy Eyeballs we need to check if this is the first channel to connect. -
1027 if (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::InProgress) {
evaluated: connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::InProgress
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:643
1-643
1028 if (connection->d_func()->delayedConnectionTimer.isActive())
partially evaluated: connection->d_func()->delayedConnectionTimer.isActive()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1029 connection->d_func()->delayedConnectionTimer.stop();
executed: connection->d_func()->delayedConnectionTimer.stop();
Execution Count:1
1
1030 if (networkLayerPreference == QAbstractSocket::IPv4Protocol)
partially evaluated: networkLayerPreference == QAbstractSocket::IPv4Protocol
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1031 connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
Execution Count:1
1
1032 else if (networkLayerPreference == QAbstractSocket::IPv6Protocol)
never evaluated: networkLayerPreference == QAbstractSocket::IPv6Protocol
0
1033 connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
0
1034 else { -
1035 if (socket->peerAddress().protocol() == QAbstractSocket::IPv4Protocol)
never evaluated: socket->peerAddress().protocol() == QAbstractSocket::IPv4Protocol
0
1036 connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
0
1037 else -
1038 connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
0
1039 } -
1040 connection->d_func()->networkLayerDetected(networkLayerPreference);
executed (the execution status of this line is deduced): connection->d_func()->networkLayerDetected(networkLayerPreference);
-
1041 } else {
executed: }
Execution Count:1
1
1042 if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol))
evaluated: (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4)
TRUEFALSE
yes
Evaluation Count:642
yes
Evaluation Count:1
partially evaluated: (networkLayerPreference != QAbstractSocket::IPv4Protocol)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:642
0-642
1043 || ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) {
evaluated: (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:642
partially evaluated: (networkLayerPreference != QAbstractSocket::IPv6Protocol)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-642
1044 close();
never executed (the execution status of this line is deduced): close();
-
1045 // This is the second connection so it has to be closed and we can schedule it for another request. -
1046 QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
never executed (the execution status of this line is deduced): QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
-
1047 return;
never executed: return;
0
1048 } -
1049 //The connections networkLayerState had already been decided. -
1050 }
executed: }
Execution Count:643
643
1051 -
1052 // improve performance since we get the request sent by the kernel ASAP -
1053 //socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); -
1054 // We have this commented out now. It did not have the effect we wanted. If we want to -
1055 // do this properly, Qt has to combine multiple HTTP requests into one buffer -
1056 // and send this to the kernel in one syscall and then the kernel immediately sends -
1057 // it as one TCP packet because of TCP_NODELAY. -
1058 // However, this code is currently not in Qt, so we rely on the kernel combining -
1059 // the requests into one TCP packet. -
1060 -
1061 // not sure yet if it helps, but it makes sense -
1062 socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
executed (the execution status of this line is deduced): socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
-
1063 -
1064 pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown;
executed (the execution status of this line is deduced): pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown;
-
1065 -
1066 // ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again! -
1067 //channels[i].reconnectAttempts = 2; -
1068 if (!pendingEncrypt) {
evaluated: !pendingEncrypt
TRUEFALSE
yes
Evaluation Count:561
yes
Evaluation Count:83
83-561
1069 state = QHttpNetworkConnectionChannel::IdleState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::IdleState;
-
1070 if (!reply)
evaluated: !reply
TRUEFALSE
yes
Evaluation Count:452
yes
Evaluation Count:109
109-452
1071 connection->d_func()->dequeueRequest(socket);
executed: connection->d_func()->dequeueRequest(socket);
Execution Count:452
452
1072 if (reply)
evaluated: reply
TRUEFALSE
yes
Evaluation Count:560
yes
Evaluation Count:1
1-560
1073 sendRequest();
executed: sendRequest();
Execution Count:560
560
1074 }
executed: }
Execution Count:561
561
1075}
executed: }
Execution Count:644
644
1076 -
1077 -
1078void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socketError) -
1079{ -
1080 if (!socket)
partially evaluated: !socket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:68
0-68
1081 return;
never executed: return;
0
1082 QNetworkReply::NetworkError errorCode = QNetworkReply::UnknownNetworkError;
executed (the execution status of this line is deduced): QNetworkReply::NetworkError errorCode = QNetworkReply::UnknownNetworkError;
-
1083 -
1084 switch (socketError) { -
1085 case QAbstractSocket::HostNotFoundError: -
1086 errorCode = QNetworkReply::HostNotFoundError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::HostNotFoundError;
-
1087 break;
executed: break;
Execution Count:2
2
1088 case QAbstractSocket::ConnectionRefusedError: -
1089 errorCode = QNetworkReply::ConnectionRefusedError;
never executed (the execution status of this line is deduced): errorCode = QNetworkReply::ConnectionRefusedError;
-
1090 break;
never executed: break;
0
1091 case QAbstractSocket::RemoteHostClosedError: -
1092 // try to reconnect/resend before sending an error. -
1093 // while "Reading" the _q_disconnected() will handle this. -
1094 if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
evaluated: state != QHttpNetworkConnectionChannel::IdleState
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:23
evaluated: state != QHttpNetworkConnectionChannel::ReadingState
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:10
10-27
1095 if (reconnectAttempts-- > 0) {
evaluated: reconnectAttempts-- > 0
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:4
4-13
1096 closeAndResendCurrentRequest();
executed (the execution status of this line is deduced): closeAndResendCurrentRequest();
-
1097 return;
executed: return;
Execution Count:13
13
1098 } else { -
1099 errorCode = QNetworkReply::RemoteHostClosedError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::RemoteHostClosedError;
-
1100 }
executed: }
Execution Count:4
4
1101 } else if (state == QHttpNetworkConnectionChannel::ReadingState) {
evaluated: state == QHttpNetworkConnectionChannel::ReadingState
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:23
10-23
1102 if (!reply->d_func()->expectContent()) {
partially evaluated: !reply->d_func()->expectContent()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
1103 // No content expected, this is a valid way to have the connection closed by the server -
1104 return;
never executed: return;
0
1105 } -
1106 if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) {
evaluated: reply->contentLength() == -1
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:1
evaluated: !reply->d_func()->isChunked()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1
1-9
1107 // There was no content-length header and it's not chunked encoding, -
1108 // so this is a valid way to have the connection closed by the server -
1109 return;
executed: return;
Execution Count:8
8
1110 } -
1111 // ok, we got a disconnect even though we did not expect it -
1112 // Try to read everything from the socket before we emit the error. -
1113 if (socket->bytesAvailable()) {
evaluated: socket->bytesAvailable()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
1114 // Read everything from the socket into the reply buffer. -
1115 // we can ignore the readbuffersize as the data is already -
1116 // in memory and we will not receive more data on the socket. -
1117 reply->setReadBufferSize(0);
executed (the execution status of this line is deduced): reply->setReadBufferSize(0);
-
1118 _q_receiveReply();
executed (the execution status of this line is deduced): _q_receiveReply();
-
1119#ifndef QT_NO_SSL -
1120 if (ssl) {
partially evaluated: ssl
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1121 // QT_NO_OPENSSL. The QSslSocket can still have encrypted bytes in the plainsocket. -
1122 // So we need to check this if the socket is a QSslSocket. When the socket is flushed -
1123 // it will force a decrypt of the encrypted data in the plainsocket. -
1124 QSslSocket *sslSocket = static_cast<QSslSocket*>(socket);
executed (the execution status of this line is deduced): QSslSocket *sslSocket = static_cast<QSslSocket*>(socket);
-
1125 qint64 beforeFlush = sslSocket->encryptedBytesAvailable();
executed (the execution status of this line is deduced): qint64 beforeFlush = sslSocket->encryptedBytesAvailable();
-
1126 while (sslSocket->encryptedBytesAvailable()) {
partially evaluated: sslSocket->encryptedBytesAvailable()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1127 sslSocket->flush();
never executed (the execution status of this line is deduced): sslSocket->flush();
-
1128 _q_receiveReply();
never executed (the execution status of this line is deduced): _q_receiveReply();
-
1129 qint64 afterFlush = sslSocket->encryptedBytesAvailable();
never executed (the execution status of this line is deduced): qint64 afterFlush = sslSocket->encryptedBytesAvailable();
-
1130 if (afterFlush == beforeFlush)
never evaluated: afterFlush == beforeFlush
0
1131 break;
never executed: break;
0
1132 beforeFlush = afterFlush;
never executed (the execution status of this line is deduced): beforeFlush = afterFlush;
-
1133 }
never executed: }
0
1134 }
executed: }
Execution Count:1
1
1135#endif -
1136 }
executed: }
Execution Count:1
1
1137 -
1138 errorCode = QNetworkReply::RemoteHostClosedError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::RemoteHostClosedError;
-
1139 } else {
executed: }
Execution Count:2
2
1140 errorCode = QNetworkReply::RemoteHostClosedError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::RemoteHostClosedError;
-
1141 }
executed: }
Execution Count:23
23
1142 break;
executed: break;
Execution Count:29
29
1143 case QAbstractSocket::SocketTimeoutError: -
1144 // try to reconnect/resend before sending an error. -
1145 if (state == QHttpNetworkConnectionChannel::WritingState && (reconnectAttempts-- > 0)) {
never evaluated: state == QHttpNetworkConnectionChannel::WritingState
never evaluated: (reconnectAttempts-- > 0)
0
1146 closeAndResendCurrentRequest();
never executed (the execution status of this line is deduced): closeAndResendCurrentRequest();
-
1147 return;
never executed: return;
0
1148 } -
1149 errorCode = QNetworkReply::TimeoutError;
never executed (the execution status of this line is deduced): errorCode = QNetworkReply::TimeoutError;
-
1150 break;
never executed: break;
0
1151 case QAbstractSocket::ProxyAuthenticationRequiredError: -
1152 errorCode = QNetworkReply::ProxyAuthenticationRequiredError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::ProxyAuthenticationRequiredError;
-
1153 break;
executed: break;
Execution Count:4
4
1154 case QAbstractSocket::SslHandshakeFailedError: -
1155 errorCode = QNetworkReply::SslHandshakeFailedError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::SslHandshakeFailedError;
-
1156 break;
executed: break;
Execution Count:10
10
1157 default: -
1158 // all other errors are treated as NetworkError -
1159 errorCode = QNetworkReply::UnknownNetworkError;
executed (the execution status of this line is deduced): errorCode = QNetworkReply::UnknownNetworkError;
-
1160 break;
executed: break;
Execution Count:2
2
1161 } -
1162 QPointer<QHttpNetworkConnection> that = connection;
executed (the execution status of this line is deduced): QPointer<QHttpNetworkConnection> that = connection;
-
1163 QString errorString = connection->d_func()->errorDetail(errorCode, socket, socket->errorString());
executed (the execution status of this line is deduced): QString errorString = connection->d_func()->errorDetail(errorCode, socket, socket->errorString());
-
1164 -
1165 // In the InProgress state the channel should not emit the error. -
1166 // This will instead be handled by the connection. -
1167 if (!connection->d_func()->shouldEmitChannelError(socket))
partially evaluated: !connection->d_func()->shouldEmitChannelError(socket)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:47
0-47
1168 return;
never executed: return;
0
1169 -
1170 // Need to dequeu the request so that we can emit the error. -
1171 if (!reply)
evaluated: !reply
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:18
18-29
1172 connection->d_func()->dequeueRequest(socket);
executed: connection->d_func()->dequeueRequest(socket);
Execution Count:29
29
1173 if (reply) {
evaluated: reply
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:24
23-24
1174 reply->d_func()->errorString = errorString;
executed (the execution status of this line is deduced): reply->d_func()->errorString = errorString;
-
1175 emit reply->finishedWithError(errorCode, errorString);
executed (the execution status of this line is deduced): reply->finishedWithError(errorCode, errorString);
-
1176 reply = 0;
executed (the execution status of this line is deduced): reply = 0;
-
1177 }
executed: }
Execution Count:23
23
1178 // send the next request -
1179 QMetaObject::invokeMethod(that, "_q_startNextRequest", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(that, "_q_startNextRequest", Qt::QueuedConnection);
-
1180 -
1181 if (that) //signal emission triggered event loop
partially evaluated: that
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
1182 close();
executed: close();
Execution Count:47
47
1183}
executed: }
Execution Count:47
47
1184 -
1185#ifndef QT_NO_NETWORKPROXY -
1186void QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator* auth) -
1187{ -
1188 // Need to dequeue the request before we can emit the error. -
1189 if (!reply)
evaluated: !reply
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:2
2-31
1190 connection->d_func()->dequeueRequest(socket);
executed: connection->d_func()->dequeueRequest(socket);
Execution Count:31
31
1191 if (reply)
partially evaluated: reply
TRUEFALSE
yes
Evaluation Count:33
no
Evaluation Count:0
0-33
1192 connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth);
executed: connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth);
Execution Count:33
33
1193}
executed: }
Execution Count:33
33
1194#endif -
1195 -
1196void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead() -
1197{ -
1198 sendRequest();
executed (the execution status of this line is deduced): sendRequest();
-
1199}
executed: }
Execution Count:1876
1876
1200 -
1201#ifndef QT_NO_SSL -
1202void QHttpNetworkConnectionChannel::_q_encrypted() -
1203{ -
1204 if (!socket)
partially evaluated: !socket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67
0-67
1205 return; // ### error
never executed: return;
0
1206 state = QHttpNetworkConnectionChannel::IdleState;
executed (the execution status of this line is deduced): state = QHttpNetworkConnectionChannel::IdleState;
-
1207 pendingEncrypt = false;
executed (the execution status of this line is deduced): pendingEncrypt = false;
-
1208 if (!reply)
evaluated: !reply
TRUEFALSE
yes
Evaluation Count:42
yes
Evaluation Count:25
25-42
1209 connection->d_func()->dequeueRequest(socket);
executed: connection->d_func()->dequeueRequest(socket);
Execution Count:42
42
1210 if (reply)
partially evaluated: reply
TRUEFALSE
yes
Evaluation Count:67
no
Evaluation Count:0
0-67
1211 sendRequest();
executed: sendRequest();
Execution Count:67
67
1212}
executed: }
Execution Count:67
67
1213 -
1214void QHttpNetworkConnectionChannel::_q_sslErrors(const QList<QSslError> &errors) -
1215{ -
1216 if (!socket)
partially evaluated: !socket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:34
0-34
1217 return;
never executed: return;
0
1218 //QNetworkReply::NetworkError errorCode = QNetworkReply::ProtocolFailure; -
1219 // Also pause the connection because socket notifiers may fire while an user -
1220 // dialog is displaying -
1221 connection->d_func()->pauseConnection();
executed (the execution status of this line is deduced): connection->d_func()->pauseConnection();
-
1222 if (pendingEncrypt && !reply)
partially evaluated: pendingEncrypt
TRUEFALSE
yes
Evaluation Count:34
no
Evaluation Count:0
evaluated: !reply
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:7
0-34
1223 connection->d_func()->dequeueRequest(socket);
executed: connection->d_func()->dequeueRequest(socket);
Execution Count:27
27
1224 if (reply)
partially evaluated: reply
TRUEFALSE
yes
Evaluation Count:34
no
Evaluation Count:0
0-34
1225 emit reply->sslErrors(errors);
executed: reply->sslErrors(errors);
Execution Count:34
34
1226 connection->d_func()->resumeConnection();
executed (the execution status of this line is deduced): connection->d_func()->resumeConnection();
-
1227}
executed: }
Execution Count:34
34
1228 -
1229void QHttpNetworkConnectionChannel::_q_encryptedBytesWritten(qint64 bytes) -
1230{ -
1231 Q_UNUSED(bytes);
executed (the execution status of this line is deduced): (void)bytes;;
-
1232 // bytes have been written to the socket. write even more of them :) -
1233 if (isSocketWriting())
evaluated: isSocketWriting()
TRUEFALSE
yes
Evaluation Count:831
yes
Evaluation Count:251
251-831
1234 sendRequest();
executed: sendRequest();
Execution Count:831
831
1235 // otherwise we do nothing -
1236}
executed: }
Execution Count:1082
1082
1237 -
1238#endif -
1239 -
1240void QHttpNetworkConnectionChannel::setConnection(QHttpNetworkConnection *c) -
1241{ -
1242 // Inlining this function in the header leads to compiler error on -
1243 // release-armv5, on at least timebox 9.2 and 10.1. -
1244 connection = c;
executed (the execution status of this line is deduced): connection = c;
-
1245}
executed: }
Execution Count:3042
3042
1246 -
1247QT_END_NAMESPACE -
1248 -
1249#include "moc_qhttpnetworkconnectionchannel_p.cpp" -
1250 -
1251#endif // QT_NO_HTTP -
1252 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial