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