socket/qhttpsocketengine.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8QHttpSocketEngine::QHttpSocketEngine(QObject *parent) -
9 : QAbstractSocketEngine(*new QHttpSocketEnginePrivate, parent) -
10{ -
11}
executed: }
Execution Count:17
17
12 -
13QHttpSocketEngine::~QHttpSocketEngine() -
14{ -
15} -
16 -
17bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol) -
18{ -
19 QHttpSocketEnginePrivate * const d = d_func(); -
20 if (type != QAbstractSocket::TcpSocket)
partially evaluated: type != QAbstractSocket::TcpSocket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
21 return false;
never executed: return false;
0
22 -
23 setProtocol(protocol); -
24 setSocketType(type); -
25 d->socket = new QTcpSocket(this); -
26 d->reply = new QHttpNetworkReply(QUrl(), this); -
27 -
28 d->socket->setProperty("_q_networkSession", property("_q_networkSession")); -
29 -
30 -
31 -
32 -
33 d->socket->setProxy(QNetworkProxy::NoProxy); -
34 -
35 -
36 connect(d->socket, "2""connected()", -
37 this, "1""slotSocketConnected()", -
38 Qt::DirectConnection); -
39 connect(d->socket, "2""disconnected()", -
40 this, "1""slotSocketDisconnected()", -
41 Qt::DirectConnection); -
42 connect(d->socket, "2""readyRead()", -
43 this, "1""slotSocketReadNotification()", -
44 Qt::DirectConnection); -
45 connect(d->socket, "2""bytesWritten(qint64)", -
46 this, "1""slotSocketBytesWritten()", -
47 Qt::DirectConnection); -
48 connect(d->socket, "2""error(QAbstractSocket::SocketError)", -
49 this, "1""slotSocketError(QAbstractSocket::SocketError)", -
50 Qt::DirectConnection); -
51 connect(d->socket, "2""stateChanged(QAbstractSocket::SocketState)", -
52 this, "1""slotSocketStateChanged(QAbstractSocket::SocketState)", -
53 Qt::DirectConnection); -
54 -
55 return true;
executed: return true;
Execution Count:17
17
56} -
57 -
58bool QHttpSocketEngine::initialize(qintptr, QAbstractSocket::SocketState) -
59{ -
60 return false;
never executed: return false;
0
61} -
62 -
63void QHttpSocketEngine::setProxy(const QNetworkProxy &proxy) -
64{ -
65 QHttpSocketEnginePrivate * const d = d_func(); -
66 d->proxy = proxy; -
67 QString user = proxy.user(); -
68 if (!user.isEmpty())
partially evaluated: !user.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
69 d->authenticator.setUser(user);
never executed: d->authenticator.setUser(user);
0
70 QString password = proxy.password(); -
71 if (!password.isEmpty())
partially evaluated: !password.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
72 d->authenticator.setPassword(password);
never executed: d->authenticator.setPassword(password);
0
73}
executed: }
Execution Count:17
17
74 -
75qintptr QHttpSocketEngine::socketDescriptor() const -
76{ -
77 const QHttpSocketEnginePrivate * const d = d_func(); -
78 return d->socket ? d->socket->socketDescriptor() : 0;
executed: return d->socket ? d->socket->socketDescriptor() : 0;
Execution Count:32
32
79} -
80 -
81bool QHttpSocketEngine::isValid() const -
82{ -
83 const QHttpSocketEnginePrivate * const d = d_func(); -
84 return d->socket;
executed: return d->socket;
Execution Count:368
368
85} -
86 -
87bool QHttpSocketEngine::connectInternal() -
88{ -
89 QHttpSocketEnginePrivate * const d = d_func(); -
90 -
91 d->credentialsSent = false; -
92 -
93 -
94 if (d->state == Connected) {
partially evaluated: d->state == Connected
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
95 QMessageLogger("socket/qhttpsocketengine.cpp", 144, __PRETTY_FUNCTION__).warning("QHttpSocketEngine::connectToHost: called when already connected"); -
96 setState(QAbstractSocket::ConnectedState); -
97 return true;
never executed: return true;
0
98 } -
99 -
100 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
101 setState(QAbstractSocket::UnconnectedState);
never executed: setState(QAbstractSocket::UnconnectedState);
0
102 -
103 -
104 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
105 setState(QAbstractSocket::ConnectingState); -
106 -
107 d->socket->setReadBufferSize(65536); -
108 d->socket->connectToHost(d->proxy.hostName(), d->proxy.port()); -
109 }
executed: }
Execution Count:17
17
110 -
111 -
112 -
113 if (bytesAvailable())
partially evaluated: bytesAvailable()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
114 slotSocketReadNotification();
never executed: slotSocketReadNotification();
0
115 -
116 return d->socketState == QAbstractSocket::ConnectedState;
executed: return d->socketState == QAbstractSocket::ConnectedState;
Execution Count:17
17
117} -
118 -
119bool QHttpSocketEngine::connectToHost(const QHostAddress &address, quint16 port) -
120{ -
121 QHttpSocketEnginePrivate * const d = d_func(); -
122 -
123 setPeerAddress(address); -
124 setPeerPort(port); -
125 d->peerName.clear(); -
126 -
127 return connectInternal();
executed: return connectInternal();
Execution Count:6
6
128} -
129 -
130bool QHttpSocketEngine::connectToHostByName(const QString &hostname, quint16 port) -
131{ -
132 QHttpSocketEnginePrivate * const d = d_func(); -
133 -
134 setPeerAddress(QHostAddress()); -
135 setPeerPort(port); -
136 d->peerName = hostname; -
137 -
138 return connectInternal();
executed: return connectInternal();
Execution Count:11
11
139} -
140 -
141bool QHttpSocketEngine::bind(const QHostAddress &, quint16) -
142{ -
143 return false;
never executed: return false;
0
144} -
145 -
146bool QHttpSocketEngine::listen() -
147{ -
148 return false;
never executed: return false;
0
149} -
150 -
151int QHttpSocketEngine::accept() -
152{ -
153 return 0;
never executed: return 0;
0
154} -
155 -
156void QHttpSocketEngine::close() -
157{ -
158 QHttpSocketEnginePrivate * const d = d_func(); -
159 if (d->socket) {
partially evaluated: d->socket
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
160 d->socket->close(); -
161 delete d->socket; -
162 d->socket = 0; -
163 }
executed: }
Execution Count:17
17
164}
executed: }
Execution Count:17
17
165 -
166qint64 QHttpSocketEngine::bytesAvailable() const -
167{ -
168 const QHttpSocketEnginePrivate * const d = d_func(); -
169 return d->socket ? d->socket->bytesAvailable() : 0;
executed: return d->socket ? d->socket->bytesAvailable() : 0;
Execution Count:108
108
170} -
171 -
172qint64 QHttpSocketEngine::read(char *data, qint64 maxlen) -
173{ -
174 QHttpSocketEnginePrivate * const d = d_func(); -
175 qint64 bytesRead = d->socket->read(data, maxlen); -
176 -
177 if (d->socket->state() == QAbstractSocket::UnconnectedState
partially evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:55
0-55
178 && d->socket->bytesAvailable() == 0) {
never evaluated: d->socket->bytesAvailable() == 0
0
179 emitReadNotification(); -
180 }
never executed: }
0
181 -
182 if (bytesRead == -1) {
partially evaluated: bytesRead == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:55
0-55
183 -
184 -
185 -
186 close(); -
187 setError(QAbstractSocket::RemoteHostClosedError, -
188 QLatin1String("Remote host closed")); -
189 setState(QAbstractSocket::UnconnectedState); -
190 return -1;
never executed: return -1;
0
191 } -
192 return bytesRead;
executed: return bytesRead;
Execution Count:55
55
193} -
194 -
195qint64 QHttpSocketEngine::write(const char *data, qint64 len) -
196{ -
197 QHttpSocketEnginePrivate * const d = d_func(); -
198 return d->socket->write(data, len);
executed: return d->socket->write(data, len);
Execution Count:58
58
199} -
200 -
201 -
202 -
203bool QHttpSocketEngine::joinMulticastGroup(const QHostAddress &, -
204 const QNetworkInterface &) -
205{ -
206 setError(QAbstractSocket::UnsupportedSocketOperationError, -
207 QLatin1String("Operation on socket is not supported")); -
208 return false;
never executed: return false;
0
209} -
210 -
211bool QHttpSocketEngine::leaveMulticastGroup(const QHostAddress &, -
212 const QNetworkInterface &) -
213{ -
214 setError(QAbstractSocket::UnsupportedSocketOperationError, -
215 QLatin1String("Operation on socket is not supported")); -
216 return false;
never executed: return false;
0
217} -
218 -
219QNetworkInterface QHttpSocketEngine::multicastInterface() const -
220{ -
221 return QNetworkInterface();
never executed: return QNetworkInterface();
0
222} -
223 -
224bool QHttpSocketEngine::setMulticastInterface(const QNetworkInterface &) -
225{ -
226 setError(QAbstractSocket::UnsupportedSocketOperationError, -
227 QLatin1String("Operation on socket is not supported")); -
228 return false;
never executed: return false;
0
229} -
230 -
231 -
232qint64 QHttpSocketEngine::readDatagram(char *, qint64, QHostAddress *, -
233 quint16 *) -
234{ -
235 return 0;
never executed: return 0;
0
236} -
237 -
238qint64 QHttpSocketEngine::writeDatagram(const char *, qint64, const QHostAddress &, -
239 quint16) -
240{ -
241 return 0;
never executed: return 0;
0
242} -
243 -
244bool QHttpSocketEngine::hasPendingDatagrams() const -
245{ -
246 return false;
never executed: return false;
0
247} -
248 -
249qint64 QHttpSocketEngine::pendingDatagramSize() const -
250{ -
251 return 0;
never executed: return 0;
0
252} -
253 -
254 -
255qint64 QHttpSocketEngine::bytesToWrite() const -
256{ -
257 const QHttpSocketEnginePrivate * const d = d_func(); -
258 if (d->socket) {
partially evaluated: d->socket
TRUEFALSE
yes
Evaluation Count:192
no
Evaluation Count:0
0-192
259 return d->socket->bytesToWrite();
executed: return d->socket->bytesToWrite();
Execution Count:192
192
260 } else { -
261 return 0;
never executed: return 0;
0
262 } -
263} -
264 -
265int QHttpSocketEngine::option(SocketOption option) const -
266{ -
267 const QHttpSocketEnginePrivate * const d = d_func(); -
268 if (d->socket) {
never evaluated: d->socket
0
269 -
270 if (option == QAbstractSocketEngine::LowDelayOption)
never evaluated: option == QAbstractSocketEngine::LowDelayOption
0
271 return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
never executed: return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
0
272 if (option == QAbstractSocketEngine::KeepAliveOption)
never evaluated: option == QAbstractSocketEngine::KeepAliveOption
0
273 return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
never executed: return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
0
274 }
never executed: }
0
275 return -1;
never executed: return -1;
0
276} -
277 -
278bool QHttpSocketEngine::setOption(SocketOption option, int value) -
279{ -
280 QHttpSocketEnginePrivate * const d = d_func(); -
281 if (d->socket) {
partially evaluated: d->socket
TRUEFALSE
yes
Evaluation Count:15
no
Evaluation Count:0
0-15
282 -
283 if (option == QAbstractSocketEngine::LowDelayOption)
partially evaluated: option == QAbstractSocketEngine::LowDelayOption
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
284 d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
never executed: d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
0
285 if (option == QAbstractSocketEngine::KeepAliveOption)
partially evaluated: option == QAbstractSocketEngine::KeepAliveOption
TRUEFALSE
yes
Evaluation Count:15
no
Evaluation Count:0
0-15
286 d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
executed: d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
Execution Count:15
15
287 return true;
executed: return true;
Execution Count:15
15
288 } -
289 return false;
never executed: return false;
0
290} -
291 -
292 -
293 -
294 -
295 -
296static int qt_timeout_value(int msecs, int elapsed) -
297{ -
298 if (msecs == -1)
never evaluated: msecs == -1
0
299 return -1;
never executed: return -1;
0
300 -
301 int timeout = msecs - elapsed; -
302 return timeout < 0 ? 0 : timeout;
never executed: return timeout < 0 ? 0 : timeout;
0
303} -
304 -
305bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut) -
306{ -
307 const QHttpSocketEnginePrivate * const d = d_func(); -
308 -
309 if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState)
never evaluated: !d->socket
never evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
0
310 return false;
never executed: return false;
0
311 -
312 QElapsedTimer stopWatch; -
313 stopWatch.start(); -
314 -
315 -
316 if (!d->socket->bytesAvailable()) {
never evaluated: !d->socket->bytesAvailable()
0
317 if (!d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
never evaluated: !d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))
0
318 if (d->socket->state() == QAbstractSocket::UnconnectedState)
never evaluated: d->socket->state() == QAbstractSocket::UnconnectedState
0
319 return true;
never executed: return true;
0
320 setError(d->socket->error(), d->socket->errorString()); -
321 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
never evaluated: timedOut
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
0
322 *timedOut = true;
never executed: *timedOut = true;
0
323 return false;
never executed: return false;
0
324 } -
325 }
never executed: }
0
326 -
327 -
328 -
329 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
330 -
331 }
never executed: }
0
332 -
333 -
334 if (d->state != Connected) {
never evaluated: d->state != Connected
0
335 setError(d->socket->error(), d->socket->errorString()); -
336 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
never evaluated: timedOut
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
0
337 *timedOut = true;
never executed: *timedOut = true;
0
338 return false;
never executed: return false;
0
339 } -
340 return true;
never executed: return true;
0
341} -
342 -
343bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut) -
344{ -
345 const QHttpSocketEnginePrivate * const d = d_func(); -
346 -
347 -
348 if (d->state == Connected) {
never evaluated: d->state == Connected
0
349 if (d->socket->bytesToWrite()) {
never evaluated: d->socket->bytesToWrite()
0
350 if (!d->socket->waitForBytesWritten(msecs)) {
never evaluated: !d->socket->waitForBytesWritten(msecs)
0
351 if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
never evaluated: timedOut
0
352 *timedOut = true;
never executed: *timedOut = true;
0
353 return false;
never executed: return false;
0
354 } -
355 }
never executed: }
0
356 return true;
never executed: return true;
0
357 } -
358 -
359 QElapsedTimer stopWatch; -
360 stopWatch.start(); -
361 -
362 -
363 -
364 -
365 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
366 -
367 }
never executed: }
0
368 -
369 -
370 if (d->state != Connected) {
never evaluated: d->state != Connected
0
371 -
372 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
never evaluated: timedOut
never evaluated: d->socket->error() == QAbstractSocket::SocketTimeoutError
0
373 *timedOut = true;
never executed: *timedOut = true;
0
374 }
never executed: }
0
375 -
376 return true;
never executed: return true;
0
377} -
378 -
379bool QHttpSocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, -
380 bool checkRead, bool checkWrite, -
381 int msecs, bool *timedOut) -
382{ -
383 (void)checkRead;; -
384 -
385 if (!checkWrite) {
never evaluated: !checkWrite
0
386 -
387 bool canRead = waitForRead(msecs, timedOut); -
388 if (readyToRead)
never evaluated: readyToRead
0
389 *readyToRead = canRead;
never executed: *readyToRead = canRead;
0
390 return canRead;
never executed: return canRead;
0
391 } -
392 -
393 -
394 bool canWrite = waitForWrite(msecs, timedOut); -
395 if (readyToWrite)
never evaluated: readyToWrite
0
396 *readyToWrite = canWrite;
never executed: *readyToWrite = canWrite;
0
397 return canWrite;
never executed: return canWrite;
0
398} -
399 -
400bool QHttpSocketEngine::isReadNotificationEnabled() const -
401{ -
402 const QHttpSocketEnginePrivate * const d = d_func(); -
403 return d->readNotificationEnabled;
executed: return d->readNotificationEnabled;
Execution Count:141
141
404} -
405 -
406void QHttpSocketEngine::setReadNotificationEnabled(bool enable) -
407{ -
408 QHttpSocketEnginePrivate * const d = d_func(); -
409 if (d->readNotificationEnabled == enable)
evaluated: d->readNotificationEnabled == enable
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:72
20-72
410 return;
executed: return;
Execution Count:20
20
411 -
412 d->readNotificationEnabled = enable; -
413 if (enable) {
evaluated: enable
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:36
36
414 -
415 if (bytesAvailable())
partially evaluated: bytesAvailable()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
416 slotSocketReadNotification();
never executed: slotSocketReadNotification();
0
417 }
executed: }
Execution Count:36
36
418}
executed: }
Execution Count:72
72
419 -
420bool QHttpSocketEngine::isWriteNotificationEnabled() const -
421{ -
422 const QHttpSocketEnginePrivate * const d = d_func(); -
423 return d->writeNotificationEnabled;
executed: return d->writeNotificationEnabled;
Execution Count:83
83
424} -
425 -
426void QHttpSocketEngine::setWriteNotificationEnabled(bool enable) -
427{ -
428 QHttpSocketEnginePrivate * const d = d_func(); -
429 d->writeNotificationEnabled = enable; -
430 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
431 QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
executed: QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
Execution Count:56
56
432}
executed: }
Execution Count:159
159
433 -
434bool QHttpSocketEngine::isExceptionNotificationEnabled() const -
435{ -
436 const QHttpSocketEnginePrivate * const d = d_func(); -
437 return d->exceptNotificationEnabled;
executed: return d->exceptNotificationEnabled;
Execution Count:31
31
438} -
439 -
440void QHttpSocketEngine::setExceptionNotificationEnabled(bool enable) -
441{ -
442 QHttpSocketEnginePrivate * const d = d_func(); -
443 d->exceptNotificationEnabled = enable; -
444}
executed: }
Execution Count:62
62
445 -
446void QHttpSocketEngine::slotSocketConnected() -
447{ -
448 QHttpSocketEnginePrivate * const d = d_func(); -
449 -
450 -
451 const char method[] = "CONNECT "; -
452 QByteArray peerAddress = d->peerName.isEmpty() ?
evaluated: d->peerName.isEmpty()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:19
6-19
453 d->peerAddress.toString().toLatin1() : -
454 QUrl::toAce(d->peerName); -
455 QByteArray path = peerAddress + ':' + QByteArray::number(d->peerPort); -
456 QByteArray data = method; -
457 data += path; -
458 data += " HTTP/1.1\r\n"; -
459 data += "Proxy-Connection: keep-alive\r\n"; -
460 data += "Host: " + peerAddress + "\r\n"; -
461 if (!d->proxy.hasRawHeader("User-Agent"))
evaluated: !d->proxy.hasRawHeader("User-Agent")
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:12
12-13
462 data += "User-Agent: Mozilla/5.0\r\n";
executed: data += "User-Agent: Mozilla/5.0\r\n";
Execution Count:13
13
463 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;})) { -
464 data += header + ": " + d->proxy.rawHeader(header) + "\r\n"; -
465 }
executed: }
Execution Count:12
12
466 QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator); -
467 -
468 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
469 d->credentialsSent = true; -
470 data += "Proxy-Authorization: " + priv->calculateResponse(method, path); -
471 data += "\r\n"; -
472 }
executed: }
Execution Count:8
8
473 data += "\r\n"; -
474 -
475 -
476 -
477 d->socket->write(data); -
478 d->state = ConnectSent; -
479}
executed: }
Execution Count:25
25
480 -
481void QHttpSocketEngine::slotSocketDisconnected() -
482{ -
483} -
484 -
485void QHttpSocketEngine::slotSocketReadNotification() -
486{ -
487 QHttpSocketEnginePrivate * const d = d_func(); -
488 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
489 return;
never executed: return;
0
490 -
491 if (d->state == Connected) {
evaluated: d->state == Connected
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:25
25-55
492 -
493 if (d->readNotificationEnabled)
partially evaluated: d->readNotificationEnabled
TRUEFALSE
yes
Evaluation Count:55
no
Evaluation Count:0
0-55
494 emitReadNotification();
executed: emitReadNotification();
Execution Count:55
55
495 return;
executed: return;
Execution Count:55
55
496 } -
497 -
498 readResponseContent:
code before this statement executed: readResponseContent:
Execution Count:25
25
499 if (d->state == ReadResponseContent) {
partially evaluated: d->state == ReadResponseContent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
500 char dummybuffer[4096]; -
501 while (d->pendingResponseData) {
never evaluated: d->pendingResponseData
0
502 int read = d->socket->read(dummybuffer, qMin(sizeof(dummybuffer), (size_t)d->pendingResponseData)); -
503 if (read >= 0)
never evaluated: read >= 0
0
504 dummybuffer[read] = 0;
never executed: dummybuffer[read] = 0;
0
505 -
506 if (read == 0)
never evaluated: read == 0
0
507 return;
never executed: return;
0
508 if (read == -1) {
never evaluated: read == -1
0
509 d->socket->disconnectFromHost(); -
510 emitWriteNotification(); -
511 return;
never executed: return;
0
512 } -
513 d->pendingResponseData -= read; -
514 }
never executed: }
0
515 if (d->pendingResponseData > 0)
never evaluated: d->pendingResponseData > 0
0
516 return;
never executed: return;
0
517 d->state = SendAuthentication; -
518 slotSocketConnected(); -
519 return;
never executed: return;
0
520 } -
521 -
522 bool ok = true; -
523 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
524 d->reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
executed: d->reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
Execution Count:25
25
525 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
526 ok = d->reply->d_func()->readStatus(d->socket) != -1; -
527 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
528 return;
never executed: return;
0
529 }
executed: }
Execution Count:25
25
530 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
531 ok = d->reply->d_func()->readHeader(d->socket) != -1; -
532 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
533 return;
never executed: return;
0
534 }
executed: }
Execution Count:25
25
535 if (!ok) {
partially evaluated: !ok
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
536 -
537 d->socket->close(); -
538 setState(QAbstractSocket::UnconnectedState); -
539 setError(QAbstractSocket::ProxyProtocolError, tr("Did not receive HTTP response from proxy")); -
540 emitConnectionNotification(); -
541 return;
never executed: return;
0
542 } -
543 -
544 int statusCode = d->reply->statusCode(); -
545 QAuthenticatorPrivate *priv = 0; -
546 if (statusCode == 200) {
evaluated: statusCode == 200
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:10
10-15
547 d->state = Connected; -
548 setLocalAddress(d->socket->localAddress()); -
549 setLocalPort(d->socket->localPort()); -
550 setState(QAbstractSocket::ConnectedState); -
551 d->authenticator.detach(); -
552 priv = QAuthenticatorPrivate::getPrivate(d->authenticator); -
553 priv->hasFailed = false; -
554 } else if (statusCode == 407) {
partially evaluated: statusCode == 407
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
executed: }
Execution Count:15
0-15
555 if (d->credentialsSent) {
evaluated: d->credentialsSent
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8
2-8
556 -
557 d->authenticator = QAuthenticator(); -
558 d->authenticator.detach(); -
559 priv = QAuthenticatorPrivate::getPrivate(d->authenticator); -
560 priv->hasFailed = true; -
561 }
executed: }
Execution Count:2
2
562 else if (d->authenticator.isNull())
partially evaluated: d->authenticator.isNull()
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
563 d->authenticator.detach();
executed: d->authenticator.detach();
Execution Count:8
8
564 priv = QAuthenticatorPrivate::getPrivate(d->authenticator); -
565 -
566 priv->parseHttpResponse(d->reply->header(), true); -
567 -
568 if (priv->phase == QAuthenticatorPrivate::Invalid) {
partially evaluated: priv->phase == QAuthenticatorPrivate::Invalid
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
569 -
570 d->socket->close(); -
571 setState(QAbstractSocket::UnconnectedState); -
572 setError(QAbstractSocket::ProxyProtocolError, tr("Error parsing authentication request from proxy")); -
573 emitConnectionNotification(); -
574 return;
never executed: return;
0
575 } -
576 -
577 bool willClose; -
578 QByteArray proxyConnectionHeader = d->reply->headerField("Proxy-Connection"); -
579 -
580 -
581 if (proxyConnectionHeader.isEmpty())
partially evaluated: proxyConnectionHeader.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
582 proxyConnectionHeader = d->reply->headerField("Connection");
never executed: proxyConnectionHeader = d->reply->headerField("Connection");
0
583 proxyConnectionHeader = proxyConnectionHeader.toLower(); -
584 if (proxyConnectionHeader == "close") {
partially evaluated: proxyConnectionHeader == "close"
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
585 willClose = true; -
586 } else if (proxyConnectionHeader == "keep-alive") {
executed: }
Execution Count:10
never evaluated: proxyConnectionHeader == "keep-alive"
0-10
587 willClose = false; -
588 } else {
never executed: }
0
589 -
590 -
591 -
592 willClose = (d->reply->majorVersion() * 0x100 + d->reply->minorVersion()) <= 0x0100; -
593 }
never executed: }
0
594 -
595 if (willClose) {
partially evaluated: willClose
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
596 -
597 -
598 d->socket->disconnectFromHost(); -
599 d->socket->readAll(); -
600 -
601 delete d->reply; -
602 d->reply = new QHttpNetworkReply; -
603 }
executed: }
Execution Count:10
10
604 -
605 if (priv->phase == QAuthenticatorPrivate::Done)
partially evaluated: priv->phase == QAuthenticatorPrivate::Done
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
606 proxyAuthenticationRequired(d->proxy, &d->authenticator);
executed: proxyAuthenticationRequired(d->proxy, &d->authenticator);
Execution Count:10
10
607 -
608 if (priv->phase == QAuthenticatorPrivate::Done) {
evaluated: priv->phase == QAuthenticatorPrivate::Done
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8
2-8
609 setError(QAbstractSocket::ProxyAuthenticationRequiredError, tr("Authentication required")); -
610 d->socket->disconnectFromHost(); -
611 } else {
executed: }
Execution Count:2
2
612 -
613 d->state = SendAuthentication; -
614 if (willClose) {
partially evaluated: willClose
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
615 d->socket->connectToHost(d->proxy.hostName(), d->proxy.port()); -
616 } else {
executed: }
Execution Count:8
8
617 bool ok; -
618 int contentLength = d->reply->headerField("Content-Length").toInt(&ok); -
619 if (ok && contentLength > 0) {
never evaluated: ok
never evaluated: contentLength > 0
0
620 d->state = ReadResponseContent; -
621 d->pendingResponseData = contentLength; -
622 goto readResponseContent;
never executed: goto readResponseContent;
0
623 } else { -
624 d->state = SendAuthentication; -
625 slotSocketConnected(); -
626 }
never executed: }
0
627 } -
628 return;
executed: return;
Execution Count:8
8
629 } -
630 } else { -
631 d->socket->close(); -
632 setState(QAbstractSocket::UnconnectedState); -
633 if (statusCode == 403 || statusCode == 405) {
never evaluated: statusCode == 403
never evaluated: statusCode == 405
0
634 -
635 -
636 setError(QAbstractSocket::SocketAccessError, tr("Proxy denied connection")); -
637 } else if (statusCode == 404) {
never executed: }
never evaluated: statusCode == 404
0
638 -
639 setError(QAbstractSocket::HostNotFoundError, QAbstractSocket::tr("Host not found")); -
640 } else if (statusCode == 503) {
never executed: }
never evaluated: statusCode == 503
0
641 -
642 setError(QAbstractSocket::ConnectionRefusedError, QAbstractSocket::tr("Connection refused")); -
643 } else {
never executed: }
0
644 -
645 -
646 setError(QAbstractSocket::ProxyProtocolError, tr("Error communicating with HTTP proxy")); -
647 }
never executed: }
0
648 } -
649 -
650 -
651 emitConnectionNotification(); -
652}
executed: }
Execution Count:17
17
653 -
654void QHttpSocketEngine::slotSocketBytesWritten() -
655{ -
656 QHttpSocketEnginePrivate * const d = d_func(); -
657 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
658 emitWriteNotification();
executed: emitWriteNotification();
Execution Count:35
35
659}
executed: }
Execution Count:60
60
660 -
661void QHttpSocketEngine::slotSocketError(QAbstractSocket::SocketError error) -
662{ -
663 QHttpSocketEnginePrivate * const d = d_func(); -
664 -
665 if (d->state != Connected) {
partially evaluated: d->state != Connected
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
666 -
667 if (error == QAbstractSocket::HostNotFoundError)
never evaluated: error == QAbstractSocket::HostNotFoundError
0
668 setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
never executed: setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
0
669 else if (error == QAbstractSocket::ConnectionRefusedError)
never evaluated: error == QAbstractSocket::ConnectionRefusedError
0
670 setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
never executed: setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
0
671 else if (error == QAbstractSocket::SocketTimeoutError)
never evaluated: error == QAbstractSocket::SocketTimeoutError
0
672 setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
never executed: setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
0
673 else if (error == QAbstractSocket::RemoteHostClosedError)
never evaluated: error == QAbstractSocket::RemoteHostClosedError
0
674 setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
never executed: setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
0
675 else -
676 setError(error, d->socket->errorString());
never executed: setError(error, d->socket->errorString());
0
677 emitConnectionNotification(); -
678 return;
never executed: return;
0
679 } -
680 -
681 -
682 if (error == QAbstractSocket::SocketTimeoutError)
partially evaluated: error == QAbstractSocket::SocketTimeoutError
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
683 return;
never executed: return;
0
684 -
685 d->state = None; -
686 setError(error, d->socket->errorString()); -
687 if (error != QAbstractSocket::RemoteHostClosedError)
partially evaluated: error != QAbstractSocket::RemoteHostClosedError
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
688 QMessageLogger("socket/qhttpsocketengine.cpp", 737, __PRETTY_FUNCTION__).debug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
never executed: QMessageLogger("socket/qhttpsocketengine.cpp", 737, __PRETTY_FUNCTION__).debug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
0
689 -
690 emitReadNotification(); -
691}
executed: }
Execution Count:6
6
692 -
693void QHttpSocketEngine::slotSocketStateChanged(QAbstractSocket::SocketState state) -
694{ -
695 (void)state;; -
696}
executed: }
Execution Count:125
125
697 -
698void QHttpSocketEngine::emitPendingReadNotification() -
699{ -
700 QHttpSocketEnginePrivate * const d = d_func(); -
701 d->readNotificationPending = false; -
702 if (d->readNotificationEnabled)
partially evaluated: d->readNotificationEnabled
TRUEFALSE
yes
Evaluation Count:55
no
Evaluation Count:0
0-55
703 readNotification();
executed: readNotification();
Execution Count:55
55
704}
executed: }
Execution Count:55
55
705 -
706void QHttpSocketEngine::emitPendingWriteNotification() -
707{ -
708 QHttpSocketEnginePrivate * const d = d_func(); -
709 d->writeNotificationPending = false; -
710 if (d->writeNotificationEnabled)
partially evaluated: d->writeNotificationEnabled
TRUEFALSE
yes
Evaluation Count:35
no
Evaluation Count:0
0-35
711 writeNotification();
executed: writeNotification();
Execution Count:35
35
712}
executed: }
Execution Count:35
35
713 -
714void QHttpSocketEngine::emitPendingConnectionNotification() -
715{ -
716 QHttpSocketEnginePrivate * const d = d_func(); -
717 d->connectionNotificationPending = false; -
718 connectionNotification(); -
719}
executed: }
Execution Count:17
17
720 -
721void QHttpSocketEngine::emitReadNotification() -
722{ -
723 QHttpSocketEnginePrivate * const d = d_func(); -
724 d->readNotificationActivated = true; -
725 -
726 -
727 -
728 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
729 d->readNotificationPending = true; -
730 QMetaObject::invokeMethod(this, "emitPendingReadNotification", Qt::QueuedConnection); -
731 }
executed: }
Execution Count:61
61
732}
executed: }
Execution Count:61
61
733 -
734void QHttpSocketEngine::emitWriteNotification() -
735{ -
736 QHttpSocketEnginePrivate * const d = d_func(); -
737 d->writeNotificationActivated = true; -
738 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
739 d->writeNotificationPending = true; -
740 QMetaObject::invokeMethod(this, "emitPendingWriteNotification", Qt::QueuedConnection); -
741 }
executed: }
Execution Count:35
35
742}
executed: }
Execution Count:35
35
743 -
744void QHttpSocketEngine::emitConnectionNotification() -
745{ -
746 QHttpSocketEnginePrivate * const d = d_func(); -
747 if (!d->connectionNotificationPending) {
partially evaluated: !d->connectionNotificationPending
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
748 d->connectionNotificationPending = true; -
749 QMetaObject::invokeMethod(this, "emitPendingConnectionNotification", Qt::QueuedConnection); -
750 }
executed: }
Execution Count:17
17
751}
executed: }
Execution Count:17
17
752 -
753QHttpSocketEnginePrivate::QHttpSocketEnginePrivate() -
754 : readNotificationEnabled(false) -
755 , writeNotificationEnabled(false) -
756 , exceptNotificationEnabled(false) -
757 , readNotificationActivated(false) -
758 , writeNotificationActivated(false) -
759 , readNotificationPending(false) -
760 , writeNotificationPending(false) -
761 , connectionNotificationPending(false) -
762 , credentialsSent(false) -
763 , pendingResponseData(0) -
764{ -
765 socket = 0; -
766 reply = 0; -
767 state = QHttpSocketEngine::None; -
768}
executed: }
Execution Count:17
17
769 -
770QHttpSocketEnginePrivate::~QHttpSocketEnginePrivate() -
771{ -
772} -
773 -
774QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socketType, -
775 const QNetworkProxy &proxy, -
776 QObject *parent) -
777{ -
778 if (socketType != QAbstractSocket::TcpSocket)
evaluated: socketType != QAbstractSocket::TcpSocket
TRUEFALSE
yes
Evaluation Count:306
yes
Evaluation Count:2600
306-2600
779 return 0;
executed: return 0;
Execution Count:306
306
780 -
781 -
782 if (proxy.type() != QNetworkProxy::HttpProxy)
evaluated: proxy.type() != QNetworkProxy::HttpProxy
TRUEFALSE
yes
Evaluation Count:2583
yes
Evaluation Count:17
17-2583
783 return 0;
executed: return 0;
Execution Count:2583
2583
784 -
785 -
786 if (!qobject_cast<QAbstractSocket *>(parent))
partially evaluated: !qobject_cast<QAbstractSocket *>(parent)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
787 return 0;
never executed: return 0;
0
788 -
789 QHttpSocketEngine *engine = new QHttpSocketEngine(parent); -
790 engine->setProxy(proxy); -
791 return engine;
executed: return engine;
Execution Count:17
17
792} -
793 -
794QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(qintptr, QObject *) -
795{ -
796 return 0;
executed: return 0;
Execution Count:616
616
797} -
798 -
799 -
800 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial