socket/qhttpsocketengine.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 "qhttpsocketengine_p.h" -
43#include "qtcpsocket.h" -
44#include "qhostaddress.h" -
45#include "qurl.h" -
46#include "private/qhttpnetworkreply_p.h" -
47#include "qelapsedtimer.h" -
48#include "qnetworkinterface.h" -
49 -
50#if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP) -
51#include <qdebug.h> -
52 -
53QT_BEGIN_NAMESPACE -
54 -
55#define DEBUG -
56 -
57QHttpSocketEngine::QHttpSocketEngine(QObject *parent) -
58 : QAbstractSocketEngine(*new QHttpSocketEnginePrivate, parent) -
59{ -
60}
executed: }
Execution Count:17
17
61 -
62QHttpSocketEngine::~QHttpSocketEngine() -
63{ -
64} -
65 -
66bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol) -
67{ -
68 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
69 if (type != QAbstractSocket::TcpSocket)
partially evaluated: type != QAbstractSocket::TcpSocket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
70 return false;
never executed: return false;
0
71 -
72 setProtocol(protocol);
executed (the execution status of this line is deduced): setProtocol(protocol);
-
73 setSocketType(type);
executed (the execution status of this line is deduced): setSocketType(type);
-
74 d->socket = new QTcpSocket(this);
executed (the execution status of this line is deduced): d->socket = new QTcpSocket(this);
-
75 d->reply = new QHttpNetworkReply(QUrl(), this);
executed (the execution status of this line is deduced): d->reply = new QHttpNetworkReply(QUrl(), this);
-
76#ifndef QT_NO_BEARERMANAGEMENT -
77 d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
executed (the execution status of this line is deduced): d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
-
78#endif -
79 -
80 // Explicitly disable proxying on the proxy socket itself to avoid -
81 // unwanted recursion. -
82 d->socket->setProxy(QNetworkProxy::NoProxy);
executed (the execution status of this line is deduced): d->socket->setProxy(QNetworkProxy::NoProxy);
-
83 -
84 // Intercept all the signals. -
85 connect(d->socket, SIGNAL(connected()),
executed (the execution status of this line is deduced): connect(d->socket, "2""connected()",
-
86 this, SLOT(slotSocketConnected()),
executed (the execution status of this line is deduced): this, "1""slotSocketConnected()",
-
87 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
88 connect(d->socket, SIGNAL(disconnected()),
executed (the execution status of this line is deduced): connect(d->socket, "2""disconnected()",
-
89 this, SLOT(slotSocketDisconnected()),
executed (the execution status of this line is deduced): this, "1""slotSocketDisconnected()",
-
90 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
91 connect(d->socket, SIGNAL(readyRead()),
executed (the execution status of this line is deduced): connect(d->socket, "2""readyRead()",
-
92 this, SLOT(slotSocketReadNotification()),
executed (the execution status of this line is deduced): this, "1""slotSocketReadNotification()",
-
93 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
94 connect(d->socket, SIGNAL(bytesWritten(qint64)),
executed (the execution status of this line is deduced): connect(d->socket, "2""bytesWritten(qint64)",
-
95 this, SLOT(slotSocketBytesWritten()),
executed (the execution status of this line is deduced): this, "1""slotSocketBytesWritten()",
-
96 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
97 connect(d->socket, SIGNAL(error(QAbstractSocket::SocketError)),
executed (the execution status of this line is deduced): connect(d->socket, "2""error(QAbstractSocket::SocketError)",
-
98 this, SLOT(slotSocketError(QAbstractSocket::SocketError)),
executed (the execution status of this line is deduced): this, "1""slotSocketError(QAbstractSocket::SocketError)",
-
99 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
100 connect(d->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
executed (the execution status of this line is deduced): connect(d->socket, "2""stateChanged(QAbstractSocket::SocketState)",
-
101 this, SLOT(slotSocketStateChanged(QAbstractSocket::SocketState)),
executed (the execution status of this line is deduced): this, "1""slotSocketStateChanged(QAbstractSocket::SocketState)",
-
102 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
103 -
104 return true;
executed: return true;
Execution Count:17
17
105} -
106 -
107bool QHttpSocketEngine::initialize(qintptr, QAbstractSocket::SocketState) -
108{ -
109 return false;
never executed: return false;
0
110} -
111 -
112void QHttpSocketEngine::setProxy(const QNetworkProxy &proxy) -
113{ -
114 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
115 d->proxy = proxy;
executed (the execution status of this line is deduced): d->proxy = proxy;
-
116 QString user = proxy.user();
executed (the execution status of this line is deduced): QString user = proxy.user();
-
117 if (!user.isEmpty())
partially evaluated: !user.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
118 d->authenticator.setUser(user);
never executed: d->authenticator.setUser(user);
0
119 QString password = proxy.password();
executed (the execution status of this line is deduced): QString password = proxy.password();
-
120 if (!password.isEmpty())
partially evaluated: !password.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
121 d->authenticator.setPassword(password);
never executed: d->authenticator.setPassword(password);
0
122}
executed: }
Execution Count:17
17
123 -
124qintptr QHttpSocketEngine::socketDescriptor() const -
125{ -
126 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
127 return d->socket ? d->socket->socketDescriptor() : 0;
executed: return d->socket ? d->socket->socketDescriptor() : 0;
Execution Count:32
32
128} -
129 -
130bool QHttpSocketEngine::isValid() const -
131{ -
132 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
133 return d->socket;
executed: return d->socket;
Execution Count:368
368
134} -
135 -
136bool QHttpSocketEngine::connectInternal() -
137{ -
138 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
139 -
140 d->credentialsSent = false;
executed (the execution status of this line is deduced): d->credentialsSent = false;
-
141 -
142 // If the handshake is done, enter ConnectedState state and return true. -
143 if (d->state == Connected) {
partially evaluated: d->state == Connected
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
144 qWarning("QHttpSocketEngine::connectToHost: called when already connected");
never executed (the execution status of this line is deduced): QMessageLogger("socket/qhttpsocketengine.cpp", 144, __PRETTY_FUNCTION__).warning("QHttpSocketEngine::connectToHost: called when already connected");
-
145 setState(QAbstractSocket::ConnectedState);
never executed (the execution status of this line is deduced): setState(QAbstractSocket::ConnectedState);
-
146 return true;
never executed: return true;
0
147 } -
148 -
149 if (d->state == ConnectSent && d->socketState != QAbstractSocket::ConnectedState)
partially evaluated: d->state == ConnectSent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
never evaluated: d->socketState != QAbstractSocket::ConnectedState
0-17
150 setState(QAbstractSocket::UnconnectedState);
never executed: setState(QAbstractSocket::UnconnectedState);
0
151 -
152 // Handshake isn't done. If unconnected, start connecting. -
153 if (d->state == None && d->socket->state() == QAbstractSocket::UnconnectedState) {
partially evaluated: d->state == None
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
partially evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
154 setState(QAbstractSocket::ConnectingState);
executed (the execution status of this line is deduced): setState(QAbstractSocket::ConnectingState);
-
155 //limit buffer in internal socket, data is buffered in the external socket under application control -
156 d->socket->setReadBufferSize(65536);
executed (the execution status of this line is deduced): d->socket->setReadBufferSize(65536);
-
157 d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
executed (the execution status of this line is deduced): d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
-
158 }
executed: }
Execution Count:17
17
159 -
160 // If connected (might happen right away, at least for localhost services -
161 // on some BSD systems), there might already be bytes available. -
162 if (bytesAvailable())
partially evaluated: bytesAvailable()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
163 slotSocketReadNotification();
never executed: slotSocketReadNotification();
0
164 -
165 return d->socketState == QAbstractSocket::ConnectedState;
executed: return d->socketState == QAbstractSocket::ConnectedState;
Execution Count:17
17
166} -
167 -
168bool QHttpSocketEngine::connectToHost(const QHostAddress &address, quint16 port) -
169{ -
170 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
171 -
172 setPeerAddress(address);
executed (the execution status of this line is deduced): setPeerAddress(address);
-
173 setPeerPort(port);
executed (the execution status of this line is deduced): setPeerPort(port);
-
174 d->peerName.clear();
executed (the execution status of this line is deduced): d->peerName.clear();
-
175 -
176 return connectInternal();
executed: return connectInternal();
Execution Count:6
6
177} -
178 -
179bool QHttpSocketEngine::connectToHostByName(const QString &hostname, quint16 port) -
180{ -
181 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
182 -
183 setPeerAddress(QHostAddress());
executed (the execution status of this line is deduced): setPeerAddress(QHostAddress());
-
184 setPeerPort(port);
executed (the execution status of this line is deduced): setPeerPort(port);
-
185 d->peerName = hostname;
executed (the execution status of this line is deduced): d->peerName = hostname;
-
186 -
187 return connectInternal();
executed: return connectInternal();
Execution Count:11
11
188} -
189 -
190bool QHttpSocketEngine::bind(const QHostAddress &, quint16) -
191{ -
192 return false;
never executed: return false;
0
193} -
194 -
195bool QHttpSocketEngine::listen() -
196{ -
197 return false;
never executed: return false;
0
198} -
199 -
200int QHttpSocketEngine::accept() -
201{ -
202 return 0;
never executed: return 0;
0
203} -
204 -
205void QHttpSocketEngine::close() -
206{ -
207 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
208 if (d->socket) {
partially evaluated: d->socket
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
209 d->socket->close();
executed (the execution status of this line is deduced): d->socket->close();
-
210 delete d->socket;
executed (the execution status of this line is deduced): delete d->socket;
-
211 d->socket = 0;
executed (the execution status of this line is deduced): d->socket = 0;
-
212 }
executed: }
Execution Count:17
17
213}
executed: }
Execution Count:17
17
214 -
215qint64 QHttpSocketEngine::bytesAvailable() const -
216{ -
217 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
218 return d->socket ? d->socket->bytesAvailable() : 0;
executed: return d->socket ? d->socket->bytesAvailable() : 0;
Execution Count:108
108
219} -
220 -
221qint64 QHttpSocketEngine::read(char *data, qint64 maxlen) -
222{ -
223 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
224 qint64 bytesRead = d->socket->read(data, maxlen);
executed (the execution status of this line is deduced): qint64 bytesRead = d->socket->read(data, maxlen);
-
225 -
226 if (d->socket->state() == QAbstractSocket::UnconnectedState
partially evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:55
0-55
227 && d->socket->bytesAvailable() == 0) {
never evaluated: d->socket->bytesAvailable() == 0
0
228 emitReadNotification();
never executed (the execution status of this line is deduced): emitReadNotification();
-
229 }
never executed: }
0
230 -
231 if (bytesRead == -1) {
partially evaluated: bytesRead == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:55
0-55
232 // If nothing has been read so far, and the direct socket read -
233 // failed, return the socket's error. Otherwise, fall through and -
234 // return as much as we read so far. -
235 close();
never executed (the execution status of this line is deduced): close();
-
236 setError(QAbstractSocket::RemoteHostClosedError,
never executed (the execution status of this line is deduced): setError(QAbstractSocket::RemoteHostClosedError,
-
237 QLatin1String("Remote host closed"));
never executed (the execution status of this line is deduced): QLatin1String("Remote host closed"));
-
238 setState(QAbstractSocket::UnconnectedState);
never executed (the execution status of this line is deduced): setState(QAbstractSocket::UnconnectedState);
-
239 return -1;
never executed: return -1;
0
240 } -
241 return bytesRead;
executed: return bytesRead;
Execution Count:55
55
242} -
243 -
244qint64 QHttpSocketEngine::write(const char *data, qint64 len) -
245{ -
246 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
247 return d->socket->write(data, len);
executed: return d->socket->write(data, len);
Execution Count:58
58
248} -
249 -
250#ifndef QT_NO_UDPSOCKET -
251#ifndef QT_NO_NETWORKINTERFACE -
252bool QHttpSocketEngine::joinMulticastGroup(const QHostAddress &, -
253 const QNetworkInterface &) -
254{ -
255 setError(QAbstractSocket::UnsupportedSocketOperationError,
never executed (the execution status of this line is deduced): setError(QAbstractSocket::UnsupportedSocketOperationError,
-
256 QLatin1String("Operation on socket is not supported"));
never executed (the execution status of this line is deduced): QLatin1String("Operation on socket is not supported"));
-
257 return false;
never executed: return false;
0
258} -
259 -
260bool QHttpSocketEngine::leaveMulticastGroup(const QHostAddress &, -
261 const QNetworkInterface &) -
262{ -
263 setError(QAbstractSocket::UnsupportedSocketOperationError,
never executed (the execution status of this line is deduced): setError(QAbstractSocket::UnsupportedSocketOperationError,
-
264 QLatin1String("Operation on socket is not supported"));
never executed (the execution status of this line is deduced): QLatin1String("Operation on socket is not supported"));
-
265 return false;
never executed: return false;
0
266} -
267 -
268QNetworkInterface QHttpSocketEngine::multicastInterface() const -
269{ -
270 return QNetworkInterface();
never executed: return QNetworkInterface();
0
271} -
272 -
273bool QHttpSocketEngine::setMulticastInterface(const QNetworkInterface &) -
274{ -
275 setError(QAbstractSocket::UnsupportedSocketOperationError,
never executed (the execution status of this line is deduced): setError(QAbstractSocket::UnsupportedSocketOperationError,
-
276 QLatin1String("Operation on socket is not supported"));
never executed (the execution status of this line is deduced): QLatin1String("Operation on socket is not supported"));
-
277 return false;
never executed: return false;
0
278} -
279#endif // QT_NO_NETWORKINTERFACE -
280 -
281qint64 QHttpSocketEngine::readDatagram(char *, qint64, QHostAddress *, -
282 quint16 *) -
283{ -
284 return 0;
never executed: return 0;
0
285} -
286 -
287qint64 QHttpSocketEngine::writeDatagram(const char *, qint64, const QHostAddress &, -
288 quint16) -
289{ -
290 return 0;
never executed: return 0;
0
291} -
292 -
293bool QHttpSocketEngine::hasPendingDatagrams() const -
294{ -
295 return false;
never executed: return false;
0
296} -
297 -
298qint64 QHttpSocketEngine::pendingDatagramSize() const -
299{ -
300 return 0;
never executed: return 0;
0
301} -
302#endif // QT_NO_UDPSOCKET -
303 -
304qint64 QHttpSocketEngine::bytesToWrite() const -
305{ -
306 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
307 if (d->socket) {
partially evaluated: d->socket
TRUEFALSE
yes
Evaluation Count:192
no
Evaluation Count:0
0-192
308 return d->socket->bytesToWrite();
executed: return d->socket->bytesToWrite();
Execution Count:192
192
309 } else { -
310 return 0;
never executed: return 0;
0
311 } -
312} -
313 -
314int QHttpSocketEngine::option(SocketOption option) const -
315{ -
316 Q_D(const QHttpSocketEngine);
never executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
317 if (d->socket) {
never evaluated: d->socket
0
318 // convert the enum and call the real socket -
319 if (option == QAbstractSocketEngine::LowDelayOption)
never evaluated: option == QAbstractSocketEngine::LowDelayOption
0
320 return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
never executed: return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
0
321 if (option == QAbstractSocketEngine::KeepAliveOption)
never evaluated: option == QAbstractSocketEngine::KeepAliveOption
0
322 return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
never executed: return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
0
323 }
never executed: }
0
324 return -1;
never executed: return -1;
0
325} -
326 -
327bool QHttpSocketEngine::setOption(SocketOption option, int value) -
328{ -
329 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
330 if (d->socket) {
partially evaluated: d->socket
TRUEFALSE
yes
Evaluation Count:15
no
Evaluation Count:0
0-15
331 // convert the enum and call the real socket -
332 if (option == QAbstractSocketEngine::LowDelayOption)
partially evaluated: option == QAbstractSocketEngine::LowDelayOption
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
333 d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
never executed: d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
0
334 if (option == QAbstractSocketEngine::KeepAliveOption)
partially evaluated: option == QAbstractSocketEngine::KeepAliveOption
TRUEFALSE
yes
Evaluation Count:15
no
Evaluation Count:0
0-15
335 d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
executed: d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
Execution Count:15
15
336 return true;
executed: return true;
Execution Count:15
15
337 } -
338 return false;
never executed: return false;
0
339} -
340 -
341/* -
342 Returns the difference between msecs and elapsed. If msecs is -1, -
343 however, -1 is returned. -
344*/ -
345static int qt_timeout_value(int msecs, int elapsed) -
346{ -
347 if (msecs == -1)
never evaluated: msecs == -1
0
348 return -1;
never executed: return -1;
0
349 -
350 int timeout = msecs - elapsed;
never executed (the execution status of this line is deduced): int timeout = msecs - elapsed;
-
351 return timeout < 0 ? 0 : timeout;
never executed: return timeout < 0 ? 0 : timeout;
0
352} -
353 -
354bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut) -
355{ -
356 Q_D(const QHttpSocketEngine);
never executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
357 -
358 if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState)
never evaluated: !d->socket
never evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
0
359 return false;
never executed: return false;
0
360 -
361 QElapsedTimer stopWatch;
never executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
362 stopWatch.start();
never executed (the execution status of this line is deduced): stopWatch.start();
-
363 -
364 // Wait for more data if nothing is available. -
365 if (!d->socket->bytesAvailable()) {
never evaluated: !d->socket->bytesAvailable()
0
366 if (!d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
never evaluated: !d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))
0
367 if (d->socket->state() == QAbstractSocket::UnconnectedState)
never evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
0
368 return true;
never executed: return true;
0
369 setError(d->socket->error(), d->socket->errorString());
never executed (the execution status of this line is deduced): setError(d->socket->error(), d->socket->errorString());
-
370 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
never evaluated: timedOut
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
0
371 *timedOut = true;
never executed: *timedOut = true;
0
372 return false;
never executed: return false;
0
373 } -
374 }
never executed: }
0
375 -
376 // If we're not connected yet, wait until we are, or until an error -
377 // occurs. -
378 while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
never evaluated: d->state != Connected
never evaluated: d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))
0
379 // Loop while the protocol handshake is taking place. -
380 }
never executed: }
0
381 -
382 // Report any error that may occur. -
383 if (d->state != Connected) {
never evaluated: d->state != Connected
0
384 setError(d->socket->error(), d->socket->errorString());
never executed (the execution status of this line is deduced): setError(d->socket->error(), d->socket->errorString());
-
385 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
never evaluated: timedOut
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
0
386 *timedOut = true;
never executed: *timedOut = true;
0
387 return false;
never executed: return false;
0
388 } -
389 return true;
never executed: return true;
0
390} -
391 -
392bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut) -
393{ -
394 Q_D(const QHttpSocketEngine);
never executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
395 -
396 // If we're connected, just forward the call. -
397 if (d->state == Connected) {
never evaluated: d->state == Connected
0
398 if (d->socket->bytesToWrite()) {
never evaluated: d->socket->bytesToWrite()
0
399 if (!d->socket->waitForBytesWritten(msecs)) {
never evaluated: !d->socket->waitForBytesWritten(msecs)
0
400 if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
never evaluated: timedOut
0
401 *timedOut = true;
never executed: *timedOut = true;
0
402 return false;
never executed: return false;
0
403 } -
404 }
never executed: }
0
405 return true;
never executed: return true;
0
406 } -
407 -
408 QElapsedTimer stopWatch;
never executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
409 stopWatch.start();
never executed (the execution status of this line is deduced): stopWatch.start();
-
410 -
411 // If we're not connected yet, wait until we are, and until bytes have -
412 // been received (i.e., the socket has connected, we have sent the -
413 // greeting, and then received the response). -
414 while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
never evaluated: d->state != Connected
never evaluated: d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))
0
415 // Loop while the protocol handshake is taking place. -
416 }
never executed: }
0
417 -
418 // Report any error that may occur. -
419 if (d->state != Connected) {
never evaluated: d->state != Connected
0
420// setError(d->socket->error(), d->socket->errorString()); -
421 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
never evaluated: timedOut
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
0
422 *timedOut = true;
never executed: *timedOut = true;
0
423 }
never executed: }
0
424 -
425 return true;
never executed: return true;
0
426} -
427 -
428bool QHttpSocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, -
429 bool checkRead, bool checkWrite, -
430 int msecs, bool *timedOut) -
431{ -
432 Q_UNUSED(checkRead);
never executed (the execution status of this line is deduced): (void)checkRead;;
-
433 -
434 if (!checkWrite) {
never evaluated: !checkWrite
0
435 // Not interested in writing? Then we wait for read notifications. -
436 bool canRead = waitForRead(msecs, timedOut);
never executed (the execution status of this line is deduced): bool canRead = waitForRead(msecs, timedOut);
-
437 if (readyToRead)
never evaluated: readyToRead
0
438 *readyToRead = canRead;
never executed: *readyToRead = canRead;
0
439 return canRead;
never executed: return canRead;
0
440 } -
441 -
442 // Interested in writing? Then we wait for write notifications. -
443 bool canWrite = waitForWrite(msecs, timedOut);
never executed (the execution status of this line is deduced): bool canWrite = waitForWrite(msecs, timedOut);
-
444 if (readyToWrite)
never evaluated: readyToWrite
0
445 *readyToWrite = canWrite;
never executed: *readyToWrite = canWrite;
0
446 return canWrite;
never executed: return canWrite;
0
447} -
448 -
449bool QHttpSocketEngine::isReadNotificationEnabled() const -
450{ -
451 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
452 return d->readNotificationEnabled;
executed: return d->readNotificationEnabled;
Execution Count:141
141
453} -
454 -
455void QHttpSocketEngine::setReadNotificationEnabled(bool enable) -
456{ -
457 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
458 if (d->readNotificationEnabled == enable)
evaluated: d->readNotificationEnabled == enable
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:72
20-72
459 return;
executed: return;
Execution Count:20
20
460 -
461 d->readNotificationEnabled = enable;
executed (the execution status of this line is deduced): d->readNotificationEnabled = enable;
-
462 if (enable) {
evaluated: enable
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:36
36
463 // Enabling read notification can trigger a notification. -
464 if (bytesAvailable())
partially evaluated: bytesAvailable()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
465 slotSocketReadNotification();
never executed: slotSocketReadNotification();
0
466 }
executed: }
Execution Count:36
36
467}
executed: }
Execution Count:72
72
468 -
469bool QHttpSocketEngine::isWriteNotificationEnabled() const -
470{ -
471 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
472 return d->writeNotificationEnabled;
executed: return d->writeNotificationEnabled;
Execution Count:83
83
473} -
474 -
475void QHttpSocketEngine::setWriteNotificationEnabled(bool enable) -
476{ -
477 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
478 d->writeNotificationEnabled = enable;
executed (the execution status of this line is deduced): d->writeNotificationEnabled = enable;
-
479 if (enable && d->state == Connected && d->socket->state() == QAbstractSocket::ConnectedState)
evaluated: enable
TRUEFALSE
yes
Evaluation Count:62
yes
Evaluation Count:97
evaluated: d->state == Connected
TRUEFALSE
yes
Evaluation Count:56
yes
Evaluation Count:6
partially evaluated: d->socket->state() == QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:56
no
Evaluation Count:0
0-97
480 QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
Execution Count:56
56
481}
executed: }
Execution Count:159
159
482 -
483bool QHttpSocketEngine::isExceptionNotificationEnabled() const -
484{ -
485 Q_D(const QHttpSocketEngine);
executed (the execution status of this line is deduced): const QHttpSocketEnginePrivate * const d = d_func();
-
486 return d->exceptNotificationEnabled;
executed: return d->exceptNotificationEnabled;
Execution Count:31
31
487} -
488 -
489void QHttpSocketEngine::setExceptionNotificationEnabled(bool enable) -
490{ -
491 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
492 d->exceptNotificationEnabled = enable;
executed (the execution status of this line is deduced): d->exceptNotificationEnabled = enable;
-
493}
executed: }
Execution Count:62
62
494 -
495void QHttpSocketEngine::slotSocketConnected() -
496{ -
497 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
498 -
499 // Send the greeting. -
500 const char method[] = "CONNECT ";
executed (the execution status of this line is deduced): const char method[] = "CONNECT ";
-
501 QByteArray peerAddress = d->peerName.isEmpty() ?
evaluated: d->peerName.isEmpty()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:19
6-19
502 d->peerAddress.toString().toLatin1() :
executed (the execution status of this line is deduced): d->peerAddress.toString().toLatin1() :
-
503 QUrl::toAce(d->peerName);
executed (the execution status of this line is deduced): QUrl::toAce(d->peerName);
-
504 QByteArray path = peerAddress + ':' + QByteArray::number(d->peerPort);
executed (the execution status of this line is deduced): QByteArray path = peerAddress + ':' + QByteArray::number(d->peerPort);
-
505 QByteArray data = method;
executed (the execution status of this line is deduced): QByteArray data = method;
-
506 data += path;
executed (the execution status of this line is deduced): data += path;
-
507 data += " HTTP/1.1\r\n";
executed (the execution status of this line is deduced): data += " HTTP/1.1\r\n";
-
508 data += "Proxy-Connection: keep-alive\r\n";
executed (the execution status of this line is deduced): data += "Proxy-Connection: keep-alive\r\n";
-
509 data += "Host: " + peerAddress + "\r\n";
executed (the execution status of this line is deduced): data += "Host: " + peerAddress + "\r\n";
-
510 if (!d->proxy.hasRawHeader("User-Agent"))
evaluated: !d->proxy.hasRawHeader("User-Agent")
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:12
12-13
511 data += "User-Agent: Mozilla/5.0\r\n";
executed: data += "User-Agent: Mozilla/5.0\r\n";
Execution Count:13
13
512 foreach (const QByteArray &header, d->proxy.rawHeaderList()) {
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(d->proxy.rawHeaderList())> _container_(d->proxy.rawHeaderList()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QByteArray &header = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
513 data += header + ": " + d->proxy.rawHeader(header) + "\r\n";
executed (the execution status of this line is deduced): data += header + ": " + d->proxy.rawHeader(header) + "\r\n";
-
514 }
executed: }
Execution Count:12
12
515 QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
executed (the execution status of this line is deduced): QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
-
516 //qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1); -
517 if (priv && priv->method != QAuthenticatorPrivate::None) {
evaluated: priv
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:17
partially evaluated: priv->method != QAuthenticatorPrivate::None
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-17
518 d->credentialsSent = true;
executed (the execution status of this line is deduced): d->credentialsSent = true;
-
519 data += "Proxy-Authorization: " + priv->calculateResponse(method, path);
executed (the execution status of this line is deduced): data += "Proxy-Authorization: " + priv->calculateResponse(method, path);
-
520 data += "\r\n";
executed (the execution status of this line is deduced): data += "\r\n";
-
521 }
executed: }
Execution Count:8
8
522 data += "\r\n";
executed (the execution status of this line is deduced): data += "\r\n";
-
523// qDebug() << ">>>>>>>> sending request" << this; -
524// qDebug() << data; -
525// qDebug() << ">>>>>>>"; -
526 d->socket->write(data);
executed (the execution status of this line is deduced): d->socket->write(data);
-
527 d->state = ConnectSent;
executed (the execution status of this line is deduced): d->state = ConnectSent;
-
528}
executed: }
Execution Count:25
25
529 -
530void QHttpSocketEngine::slotSocketDisconnected() -
531{ -
532} -
533 -
534void QHttpSocketEngine::slotSocketReadNotification() -
535{ -
536 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
537 if (d->state != Connected && d->socket->bytesAvailable() == 0)
evaluated: d->state != Connected
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:55
partially evaluated: d->socket->bytesAvailable() == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-55
538 return;
never executed: return;
0
539 -
540 if (d->state == Connected) {
evaluated: d->state == Connected
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:25
25-55
541 // Forward as a read notification. -
542 if (d->readNotificationEnabled)
partially evaluated: d->readNotificationEnabled
TRUEFALSE
yes
Evaluation Count:55
no
Evaluation Count:0
0-55
543 emitReadNotification();
executed: emitReadNotification();
Execution Count:55
55
544 return;
executed: return;
Execution Count:55
55
545 } -
546 -
547 readResponseContent:
code before this statement executed: readResponseContent:
Execution Count:25
25
548 if (d->state == ReadResponseContent) {
partially evaluated: d->state == ReadResponseContent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
549 char dummybuffer[4096];
never executed (the execution status of this line is deduced): char dummybuffer[4096];
-
550 while (d->pendingResponseData) {
never evaluated: d->pendingResponseData
0
551 int read = d->socket->read(dummybuffer, qMin(sizeof(dummybuffer), (size_t)d->pendingResponseData));
never executed (the execution status of this line is deduced): int read = d->socket->read(dummybuffer, qMin(sizeof(dummybuffer), (size_t)d->pendingResponseData));
-
552 if (read >= 0)
never evaluated: read >= 0
0
553 dummybuffer[read] = 0;
never executed: dummybuffer[read] = 0;
0
554 -
555 if (read == 0)
never evaluated: read == 0
0
556 return;
never executed: return;
0
557 if (read == -1) {
never evaluated: read == -1
0
558 d->socket->disconnectFromHost();
never executed (the execution status of this line is deduced): d->socket->disconnectFromHost();
-
559 emitWriteNotification();
never executed (the execution status of this line is deduced): emitWriteNotification();
-
560 return;
never executed: return;
0
561 } -
562 d->pendingResponseData -= read;
never executed (the execution status of this line is deduced): d->pendingResponseData -= read;
-
563 }
never executed: }
0
564 if (d->pendingResponseData > 0)
never evaluated: d->pendingResponseData > 0
0
565 return;
never executed: return;
0
566 d->state = SendAuthentication;
never executed (the execution status of this line is deduced): d->state = SendAuthentication;
-
567 slotSocketConnected();
never executed (the execution status of this line is deduced): slotSocketConnected();
-
568 return;
never executed: return;
0
569 } -
570 -
571 bool ok = true;
executed (the execution status of this line is deduced): bool ok = true;
-
572 if (d->reply->d_func()->state == QHttpNetworkReplyPrivate::NothingDoneState)
partially evaluated: d->reply->d_func()->state == QHttpNetworkReplyPrivate::NothingDoneState
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
0-25
573 d->reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
executed: d->reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
Execution Count:25
25
574 if (d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingStatusState) {
partially evaluated: d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingStatusState
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
0-25
575 ok = d->reply->d_func()->readStatus(d->socket) != -1;
executed (the execution status of this line is deduced): ok = d->reply->d_func()->readStatus(d->socket) != -1;
-
576 if (ok && d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingStatusState)
partially evaluated: ok
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
partially evaluated: d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingStatusState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
577 return; //Not done parsing headers yet, wait for more data
never executed: return;
0
578 }
executed: }
Execution Count:25
25
579 if (ok && d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingHeaderState) {
partially evaluated: ok
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
partially evaluated: d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingHeaderState
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
0-25
580 ok = d->reply->d_func()->readHeader(d->socket) != -1;
executed (the execution status of this line is deduced): ok = d->reply->d_func()->readHeader(d->socket) != -1;
-
581 if (ok && d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingHeaderState)
partially evaluated: ok
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
partially evaluated: d->reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingHeaderState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
582 return; //Not done parsing headers yet, wait for more data
never executed: return;
0
583 }
executed: }
Execution Count:25
25
584 if (!ok) {
partially evaluated: !ok
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
585 // protocol error, this isn't HTTP -
586 d->socket->close();
never executed (the execution status of this line is deduced): d->socket->close();
-
587 setState(QAbstractSocket::UnconnectedState);
never executed (the execution status of this line is deduced): setState(QAbstractSocket::UnconnectedState);
-
588 setError(QAbstractSocket::ProxyProtocolError, tr("Did not receive HTTP response from proxy"));
never executed (the execution status of this line is deduced): setError(QAbstractSocket::ProxyProtocolError, tr("Did not receive HTTP response from proxy"));
-
589 emitConnectionNotification();
never executed (the execution status of this line is deduced): emitConnectionNotification();
-
590 return;
never executed: return;
0
591 } -
592 -
593 int statusCode = d->reply->statusCode();
executed (the execution status of this line is deduced): int statusCode = d->reply->statusCode();
-
594 QAuthenticatorPrivate *priv = 0;
executed (the execution status of this line is deduced): QAuthenticatorPrivate *priv = 0;
-
595 if (statusCode == 200) {
evaluated: statusCode == 200
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:10
10-15
596 d->state = Connected;
executed (the execution status of this line is deduced): d->state = Connected;
-
597 setLocalAddress(d->socket->localAddress());
executed (the execution status of this line is deduced): setLocalAddress(d->socket->localAddress());
-
598 setLocalPort(d->socket->localPort());
executed (the execution status of this line is deduced): setLocalPort(d->socket->localPort());
-
599 setState(QAbstractSocket::ConnectedState);
executed (the execution status of this line is deduced): setState(QAbstractSocket::ConnectedState);
-
600 d->authenticator.detach();
executed (the execution status of this line is deduced): d->authenticator.detach();
-
601 priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
executed (the execution status of this line is deduced): priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
-
602 priv->hasFailed = false;
executed (the execution status of this line is deduced): priv->hasFailed = false;
-
603 } else if (statusCode == 407) {
executed: }
Execution Count:15
partially evaluated: statusCode == 407
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-15
604 if (d->credentialsSent) {
evaluated: d->credentialsSent
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8
2-8
605 //407 response again means the provided username/password were invalid. -
606 d->authenticator = QAuthenticator(); //this is needed otherwise parseHttpResponse won't set the state, and then signal isn't emitted.
executed (the execution status of this line is deduced): d->authenticator = QAuthenticator();
-
607 d->authenticator.detach();
executed (the execution status of this line is deduced): d->authenticator.detach();
-
608 priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
executed (the execution status of this line is deduced): priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
-
609 priv->hasFailed = true;
executed (the execution status of this line is deduced): priv->hasFailed = true;
-
610 }
executed: }
Execution Count:2
2
611 else if (d->authenticator.isNull())
partially evaluated: d->authenticator.isNull()
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
612 d->authenticator.detach();
executed: d->authenticator.detach();
Execution Count:8
8
613 priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
executed (the execution status of this line is deduced): priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
-
614 -
615 priv->parseHttpResponse(d->reply->header(), true);
executed (the execution status of this line is deduced): priv->parseHttpResponse(d->reply->header(), true);
-
616 -
617 if (priv->phase == QAuthenticatorPrivate::Invalid) {
partially evaluated: priv->phase == QAuthenticatorPrivate::Invalid
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
618 // problem parsing the reply -
619 d->socket->close();
never executed (the execution status of this line is deduced): d->socket->close();
-
620 setState(QAbstractSocket::UnconnectedState);
never executed (the execution status of this line is deduced): setState(QAbstractSocket::UnconnectedState);
-
621 setError(QAbstractSocket::ProxyProtocolError, tr("Error parsing authentication request from proxy"));
never executed (the execution status of this line is deduced): setError(QAbstractSocket::ProxyProtocolError, tr("Error parsing authentication request from proxy"));
-
622 emitConnectionNotification();
never executed (the execution status of this line is deduced): emitConnectionNotification();
-
623 return;
never executed: return;
0
624 } -
625 -
626 bool willClose;
executed (the execution status of this line is deduced): bool willClose;
-
627 QByteArray proxyConnectionHeader = d->reply->headerField("Proxy-Connection");
executed (the execution status of this line is deduced): QByteArray proxyConnectionHeader = d->reply->headerField("Proxy-Connection");
-
628 // Although most proxies use the unofficial Proxy-Connection header, the Connection header -
629 // from http spec is also allowed. -
630 if (proxyConnectionHeader.isEmpty())
partially evaluated: proxyConnectionHeader.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
631 proxyConnectionHeader = d->reply->headerField("Connection");
never executed: proxyConnectionHeader = d->reply->headerField("Connection");
0
632 proxyConnectionHeader = proxyConnectionHeader.toLower();
never executed (the execution status of this line is deduced): proxyConnectionHeader = proxyConnectionHeader.toLower();
-
633 if (proxyConnectionHeader == "close") {
partially evaluated: proxyConnectionHeader == "close"
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
634 willClose = true;
executed (the execution status of this line is deduced): willClose = true;
-
635 } else if (proxyConnectionHeader == "keep-alive") {
executed: }
Execution Count:10
never evaluated: proxyConnectionHeader == "keep-alive"
0-10
636 willClose = false;
never executed (the execution status of this line is deduced): willClose = false;
-
637 } else {
never executed: }
0
638 // no Proxy-Connection header, so use the default -
639 // HTTP 1.1's default behaviour is to keep persistent connections -
640 // HTTP 1.0 or earlier, so we expect the server to close -
641 willClose = (d->reply->majorVersion() * 0x100 + d->reply->minorVersion()) <= 0x0100;
never executed (the execution status of this line is deduced): willClose = (d->reply->majorVersion() * 0x100 + d->reply->minorVersion()) <= 0x0100;
-
642 }
never executed: }
0
643 -
644 if (willClose) {
partially evaluated: willClose
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
645 // the server will disconnect, so let's avoid receiving an error -
646 // especially since the signal below may trigger a new event loop -
647 d->socket->disconnectFromHost();
executed (the execution status of this line is deduced): d->socket->disconnectFromHost();
-
648 d->socket->readAll();
executed (the execution status of this line is deduced): d->socket->readAll();
-
649 //We're done with the reply and need to reset it for the next connection -
650 delete d->reply;
executed (the execution status of this line is deduced): delete d->reply;
-
651 d->reply = new QHttpNetworkReply;
executed (the execution status of this line is deduced): d->reply = new QHttpNetworkReply;
-
652 }
executed: }
Execution Count:10
10
653 -
654 if (priv->phase == QAuthenticatorPrivate::Done)
partially evaluated: priv->phase == QAuthenticatorPrivate::Done
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
655 emit proxyAuthenticationRequired(d->proxy, &d->authenticator);
executed: proxyAuthenticationRequired(d->proxy, &d->authenticator);
Execution Count:10
10
656 // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above. -
657 if (priv->phase == QAuthenticatorPrivate::Done) {
evaluated: priv->phase == QAuthenticatorPrivate::Done
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8
2-8
658 setError(QAbstractSocket::ProxyAuthenticationRequiredError, tr("Authentication required"));
executed (the execution status of this line is deduced): setError(QAbstractSocket::ProxyAuthenticationRequiredError, tr("Authentication required"));
-
659 d->socket->disconnectFromHost();
executed (the execution status of this line is deduced): d->socket->disconnectFromHost();
-
660 } else {
executed: }
Execution Count:2
2
661 // close the connection if it isn't already and reconnect using the chosen authentication method -
662 d->state = SendAuthentication;
executed (the execution status of this line is deduced): d->state = SendAuthentication;
-
663 if (willClose) {
partially evaluated: willClose
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
664 d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
executed (the execution status of this line is deduced): d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
-
665 } else {
executed: }
Execution Count:8
8
666 bool ok;
never executed (the execution status of this line is deduced): bool ok;
-
667 int contentLength = d->reply->headerField("Content-Length").toInt(&ok);
never executed (the execution status of this line is deduced): int contentLength = d->reply->headerField("Content-Length").toInt(&ok);
-
668 if (ok && contentLength > 0) {
never evaluated: ok
never evaluated: contentLength > 0
0
669 d->state = ReadResponseContent;
never executed (the execution status of this line is deduced): d->state = ReadResponseContent;
-
670 d->pendingResponseData = contentLength;
never executed (the execution status of this line is deduced): d->pendingResponseData = contentLength;
-
671 goto readResponseContent;
never executed: goto readResponseContent;
0
672 } else { -
673 d->state = SendAuthentication;
never executed (the execution status of this line is deduced): d->state = SendAuthentication;
-
674 slotSocketConnected();
never executed (the execution status of this line is deduced): slotSocketConnected();
-
675 }
never executed: }
0
676 } -
677 return;
executed: return;
Execution Count:8
8
678 } -
679 } else { -
680 d->socket->close();
never executed (the execution status of this line is deduced): d->socket->close();
-
681 setState(QAbstractSocket::UnconnectedState);
never executed (the execution status of this line is deduced): setState(QAbstractSocket::UnconnectedState);
-
682 if (statusCode == 403 || statusCode == 405) {
never evaluated: statusCode == 403
never evaluated: statusCode == 405
0
683 // 403 Forbidden -
684 // 405 Method Not Allowed -
685 setError(QAbstractSocket::SocketAccessError, tr("Proxy denied connection"));
never executed (the execution status of this line is deduced): setError(QAbstractSocket::SocketAccessError, tr("Proxy denied connection"));
-
686 } else if (statusCode == 404) {
never executed: }
never evaluated: statusCode == 404
0
687 // 404 Not Found: host lookup error -
688 setError(QAbstractSocket::HostNotFoundError, QAbstractSocket::tr("Host not found"));
never executed (the execution status of this line is deduced): setError(QAbstractSocket::HostNotFoundError, QAbstractSocket::tr("Host not found"));
-
689 } else if (statusCode == 503) {
never executed: }
never evaluated: statusCode == 503
0
690 // 503 Service Unavailable: Connection Refused -
691 setError(QAbstractSocket::ConnectionRefusedError, QAbstractSocket::tr("Connection refused"));
never executed (the execution status of this line is deduced): setError(QAbstractSocket::ConnectionRefusedError, QAbstractSocket::tr("Connection refused"));
-
692 } else {
never executed: }
0
693 // Some other reply -
694 //qWarning("UNEXPECTED RESPONSE: [%s]", responseHeader.toString().toLatin1().data()); -
695 setError(QAbstractSocket::ProxyProtocolError, tr("Error communicating with HTTP proxy"));
never executed (the execution status of this line is deduced): setError(QAbstractSocket::ProxyProtocolError, tr("Error communicating with HTTP proxy"));
-
696 }
never executed: }
0
697 } -
698 -
699 // The handshake is done; notify that we're connected (or failed to connect) -
700 emitConnectionNotification();
executed (the execution status of this line is deduced): emitConnectionNotification();
-
701}
executed: }
Execution Count:17
17
702 -
703void QHttpSocketEngine::slotSocketBytesWritten() -
704{ -
705 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
706 if (d->state == Connected && d->writeNotificationEnabled)
evaluated: d->state == Connected
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:25
partially evaluated: d->writeNotificationEnabled
TRUEFALSE
yes
Evaluation Count:35
no
Evaluation Count:0
0-35
707 emitWriteNotification();
executed: emitWriteNotification();
Execution Count:35
35
708}
executed: }
Execution Count:60
60
709 -
710void QHttpSocketEngine::slotSocketError(QAbstractSocket::SocketError error) -
711{ -
712 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
713 -
714 if (d->state != Connected) {
partially evaluated: d->state != Connected
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
715 // we are in proxy handshaking stages -
716 if (error == QAbstractSocket::HostNotFoundError)
never evaluated: error == QAbstractSocket::HostNotFoundError
0
717 setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
never executed: setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
0
718 else if (error == QAbstractSocket::ConnectionRefusedError)
never evaluated: error == QAbstractSocket::ConnectionRefusedError
0
719 setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
never executed: setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
0
720 else if (error == QAbstractSocket::SocketTimeoutError)
never evaluated: error == QAbstractSocket::SocketTimeoutError
0
721 setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
never executed: setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
0
722 else if (error == QAbstractSocket::RemoteHostClosedError)
never evaluated: error == QAbstractSocket::RemoteHostClosedError
0
723 setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
never executed: setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
0
724 else -
725 setError(error, d->socket->errorString());
never executed: setError(error, d->socket->errorString());
0
726 emitConnectionNotification();
never executed (the execution status of this line is deduced): emitConnectionNotification();
-
727 return;
never executed: return;
0
728 } -
729 -
730 // We're connected -
731 if (error == QAbstractSocket::SocketTimeoutError)
partially evaluated: error == QAbstractSocket::SocketTimeoutError
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
732 return; // ignore this error
never executed: return;
0
733 -
734 d->state = None;
executed (the execution status of this line is deduced): d->state = None;
-
735 setError(error, d->socket->errorString());
executed (the execution status of this line is deduced): setError(error, d->socket->errorString());
-
736 if (error != QAbstractSocket::RemoteHostClosedError)
partially evaluated: error != QAbstractSocket::RemoteHostClosedError
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
737 qDebug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
never executed: QMessageLogger("socket/qhttpsocketengine.cpp", 737, __PRETTY_FUNCTION__).debug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
0
738 //read notification needs to always be emitted, otherwise the higher layer doesn't get the disconnected signal -
739 emitReadNotification();
executed (the execution status of this line is deduced): emitReadNotification();
-
740}
executed: }
Execution Count:6
6
741 -
742void QHttpSocketEngine::slotSocketStateChanged(QAbstractSocket::SocketState state) -
743{ -
744 Q_UNUSED(state);
executed (the execution status of this line is deduced): (void)state;;
-
745}
executed: }
Execution Count:125
125
746 -
747void QHttpSocketEngine::emitPendingReadNotification() -
748{ -
749 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
750 d->readNotificationPending = false;
executed (the execution status of this line is deduced): d->readNotificationPending = false;
-
751 if (d->readNotificationEnabled)
partially evaluated: d->readNotificationEnabled
TRUEFALSE
yes
Evaluation Count:55
no
Evaluation Count:0
0-55
752 emit readNotification();
executed: readNotification();
Execution Count:55
55
753}
executed: }
Execution Count:55
55
754 -
755void QHttpSocketEngine::emitPendingWriteNotification() -
756{ -
757 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
758 d->writeNotificationPending = false;
executed (the execution status of this line is deduced): d->writeNotificationPending = false;
-
759 if (d->writeNotificationEnabled)
partially evaluated: d->writeNotificationEnabled
TRUEFALSE
yes
Evaluation Count:35
no
Evaluation Count:0
0-35
760 emit writeNotification();
executed: writeNotification();
Execution Count:35
35
761}
executed: }
Execution Count:35
35
762 -
763void QHttpSocketEngine::emitPendingConnectionNotification() -
764{ -
765 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
766 d->connectionNotificationPending = false;
executed (the execution status of this line is deduced): d->connectionNotificationPending = false;
-
767 emit connectionNotification();
executed (the execution status of this line is deduced): connectionNotification();
-
768}
executed: }
Execution Count:17
17
769 -
770void QHttpSocketEngine::emitReadNotification() -
771{ -
772 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
773 d->readNotificationActivated = true;
executed (the execution status of this line is deduced): d->readNotificationActivated = true;
-
774 // if there is a connection notification pending we have to emit the readNotification -
775 // incase there is connection error. This is only needed for Windows, but it does not -
776 // hurt in other cases. -
777 if ((d->readNotificationEnabled && !d->readNotificationPending) || d->connectionNotificationPending) {
partially evaluated: d->readNotificationEnabled
TRUEFALSE
yes
Evaluation Count:61
no
Evaluation Count:0
partially evaluated: !d->readNotificationPending
TRUEFALSE
yes
Evaluation Count:61
no
Evaluation Count:0
never evaluated: d->connectionNotificationPending
0-61
778 d->readNotificationPending = true;
executed (the execution status of this line is deduced): d->readNotificationPending = true;
-
779 QMetaObject::invokeMethod(this, "emitPendingReadNotification", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(this, "emitPendingReadNotification", Qt::QueuedConnection);
-
780 }
executed: }
Execution Count:61
61
781}
executed: }
Execution Count:61
61
782 -
783void QHttpSocketEngine::emitWriteNotification() -
784{ -
785 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
786 d->writeNotificationActivated = true;
executed (the execution status of this line is deduced): d->writeNotificationActivated = true;
-
787 if (d->writeNotificationEnabled && !d->writeNotificationPending) {
partially evaluated: d->writeNotificationEnabled
TRUEFALSE
yes
Evaluation Count:35
no
Evaluation Count:0
partially evaluated: !d->writeNotificationPending
TRUEFALSE
yes
Evaluation Count:35
no
Evaluation Count:0
0-35
788 d->writeNotificationPending = true;
executed (the execution status of this line is deduced): d->writeNotificationPending = true;
-
789 QMetaObject::invokeMethod(this, "emitPendingWriteNotification", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(this, "emitPendingWriteNotification", Qt::QueuedConnection);
-
790 }
executed: }
Execution Count:35
35
791}
executed: }
Execution Count:35
35
792 -
793void QHttpSocketEngine::emitConnectionNotification() -
794{ -
795 Q_D(QHttpSocketEngine);
executed (the execution status of this line is deduced): QHttpSocketEnginePrivate * const d = d_func();
-
796 if (!d->connectionNotificationPending) {
partially evaluated: !d->connectionNotificationPending
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
797 d->connectionNotificationPending = true;
executed (the execution status of this line is deduced): d->connectionNotificationPending = true;
-
798 QMetaObject::invokeMethod(this, "emitPendingConnectionNotification", Qt::QueuedConnection);
executed (the execution status of this line is deduced): QMetaObject::invokeMethod(this, "emitPendingConnectionNotification", Qt::QueuedConnection);
-
799 }
executed: }
Execution Count:17
17
800}
executed: }
Execution Count:17
17
801 -
802QHttpSocketEnginePrivate::QHttpSocketEnginePrivate() -
803 : readNotificationEnabled(false) -
804 , writeNotificationEnabled(false) -
805 , exceptNotificationEnabled(false) -
806 , readNotificationActivated(false) -
807 , writeNotificationActivated(false) -
808 , readNotificationPending(false) -
809 , writeNotificationPending(false) -
810 , connectionNotificationPending(false) -
811 , credentialsSent(false) -
812 , pendingResponseData(0) -
813{ -
814 socket = 0;
executed (the execution status of this line is deduced): socket = 0;
-
815 reply = 0;
executed (the execution status of this line is deduced): reply = 0;
-
816 state = QHttpSocketEngine::None;
executed (the execution status of this line is deduced): state = QHttpSocketEngine::None;
-
817}
executed: }
Execution Count:17
17
818 -
819QHttpSocketEnginePrivate::~QHttpSocketEnginePrivate() -
820{ -
821} -
822 -
823QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socketType, -
824 const QNetworkProxy &proxy, -
825 QObject *parent) -
826{ -
827 if (socketType != QAbstractSocket::TcpSocket)
evaluated: socketType != QAbstractSocket::TcpSocket
TRUEFALSE
yes
Evaluation Count:306
yes
Evaluation Count:2600
306-2600
828 return 0;
executed: return 0;
Execution Count:306
306
829 -
830 // proxy type must have been resolved by now -
831 if (proxy.type() != QNetworkProxy::HttpProxy)
evaluated: proxy.type() != QNetworkProxy::HttpProxy
TRUEFALSE
yes
Evaluation Count:2583
yes
Evaluation Count:17
17-2583
832 return 0;
executed: return 0;
Execution Count:2583
2583
833 -
834 // we only accept active sockets -
835 if (!qobject_cast<QAbstractSocket *>(parent))
partially evaluated: !qobject_cast<QAbstractSocket *>(parent)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
836 return 0;
never executed: return 0;
0
837 -
838 QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
executed (the execution status of this line is deduced): QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
-
839 engine->setProxy(proxy);
executed (the execution status of this line is deduced): engine->setProxy(proxy);
-
840 return engine;
executed: return engine;
Execution Count:17
17
841} -
842 -
843QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(qintptr, QObject *) -
844{ -
845 return 0;
executed: return 0;
Execution Count:616
616
846} -
847 -
848QT_END_NAMESPACE -
849 -
850#endif -
851 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial