Changeset 561 for trunk/src/network/ssl/qsslsocket.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/network/ssl/qsslsocket.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtNetwork module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 50 50 51 51 \reentrant 52 \ingroup io52 \ingroup network 53 53 \ingroup ssl 54 54 \inmodule QtNetwork … … 114 114 internal buffer, and you can call write() or putChar() to write 115 115 data back to the peer. QSslSocket will automatically encrypt the 116 written data for you, and emit bytesWritten() once the data has117 been written to the peer.116 written data for you, and emit encryptedBytesWritten() once 117 the data has been written to the peer. 118 118 119 119 As a convenience, QSslSocket supports QTcpSocket's blocking … … 150 150 for use in the OpenSSL Toolkit (\l{http://www.openssl.org/}). 151 151 152 \note Be aware of the difference between the bytesWritten() signal and 153 the encryptedBytesWritten() signal. For a QTcpSocket, bytesWritten() 154 will get emitted as soon as data has been written to the TCP socket. 155 For a QSslSocket, bytesWritten() will get emitted when the data 156 is being encrypted and encryptedBytesWritten() 157 will get emitted as soon as data has been written to the TCP socket. 158 152 159 \sa QSslCertificate, QSslCipher, QSslError 153 160 */ … … 357 364 ignoreSslErrors(), either from inside a slot function connected to 358 365 the sslErrors() signal, or prior to entering encrypted mode. If 359 ignoreSslErrors is not called, the connection is dropped, signal366 ignoreSslErrors() is not called, the connection is dropped, signal 360 367 disconnected() is emitted, and QSslSocket returns to the 361 368 UnconnectedState. … … 398 405 399 406 /*! 407 \since 4.6 408 \overload 409 410 In addition to the original behaviour of connectToHostEncrypted, 411 this overloaded method enables the usage of a different hostname 412 (\a sslPeerName) for the certificate validation instead of 413 the one used for the TCP connection (\a hostName). 414 415 \sa connectToHostEncrypted() 416 */ 417 void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, 418 const QString &sslPeerName, OpenMode mode) 419 { 420 Q_D(QSslSocket); 421 if (d->state == ConnectedState || d->state == ConnectingState) { 422 qWarning("QSslSocket::connectToHostEncrypted() called when already connecting/connected"); 423 return; 424 } 425 426 d->init(); 427 d->autoStartHandshake = true; 428 d->initialized = true; 429 d->verificationPeerName = sslPeerName; 430 431 // Note: When connecting to localhost, some platforms (e.g., HP-UX and some BSDs) 432 // establish the connection immediately (i.e., first attempt). 433 connectToHost(hostName, port, mode); 434 } 435 436 /*! 400 437 Initializes QSslSocket with the native socket descriptor \a 401 438 socketDescriptor. Returns true if \a socketDescriptor is accepted … … 413 450 Q_D(QSslSocket); 414 451 #ifdef QSSLSOCKET_DEBUG 415 qDebug() << "QSslSocket::setSocketDescriptor(" << socketDescriptor << ","416 << state << "," << openMode << ")";452 qDebug() << "QSslSocket::setSocketDescriptor(" << socketDescriptor << ',' 453 << state << ',' << openMode << ')'; 417 454 #endif 418 455 if (!d->plainSocket) … … 432 469 433 470 /*! 471 \since 4.6 472 Sets the given \a option to the value described by \a value. 473 474 \sa socketOption() 475 */ 476 void QSslSocket::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value) 477 { 478 Q_D(QSslSocket); 479 if (d->plainSocket) 480 d->plainSocket->setSocketOption(option, value); 481 } 482 483 /*! 484 \since 4.6 485 Returns the value of the \a option option. 486 487 \sa setSocketOption() 488 */ 489 QVariant QSslSocket::socketOption(QAbstractSocket::SocketOption option) 490 { 491 Q_D(QSslSocket); 492 if (d->plainSocket) 493 return d->plainSocket->socketOption(option); 494 else 495 return QVariant(); 496 } 497 498 /*! 434 499 Returns the current mode for the socket; either UnencryptedMode, where 435 500 QSslSocket behaves identially to QTcpSocket, or one of SslClientMode or … … 451 516 452 517 An encrypted socket encrypts all data that is written by calling write() 453 or putChar() before the data is written to the network, and de scrypts all518 or putChar() before the data is written to the network, and decrypts all 454 519 incoming data as the data is received from the network, before you call 455 520 read(), readLine() or getChar(). … … 654 719 qDebug() << "QSslSocket::close()"; 655 720 #endif 721 Q_D(QSslSocket); 722 if (d->plainSocket) 723 d->plainSocket->close(); 656 724 QTcpSocket::close(); 725 726 // must be cleared, reading/writing not possible on closed socket: 727 d->readBuffer.clear(); 728 d->writeBuffer.clear(); 729 // for QTcpSocket this is already done because it uses the readBuffer/writeBuffer 730 // if the QIODevice it is based on 731 // ### FIXME QSslSocket should probably do similar instead of having 732 // its own readBuffer/writeBuffer 657 733 } 658 734 … … 1259 1335 1260 1336 /*! 1261 Returns the system default CA certificate database for your 1262 system. This database is normally found in a standard place for 1263 your system. If it is not found there, Qt will provide its own 1264 default CA certificate database. The CA certificate database 1337 This function provides a default CA certificate database 1338 shipped together with Qt. The CA certificate database 1265 1339 returned by this function is used to initialize the database 1266 1340 returned by defaultCaCertificates(). You can replace that database … … 1528 1602 Q_D(QSslSocket); 1529 1603 if (d->mode != UnencryptedMode) { 1530 qWarning("QSslSocket::start ClientEncryption: cannot start handshake on non-plain connection");1604 qWarning("QSslSocket::startServerEncryption: cannot start handshake on non-plain connection"); 1531 1605 return; 1532 1606 } … … 1563 1637 { 1564 1638 Q_D(QSslSocket); 1565 d->ignoreSslErrors = true; 1639 d->ignoreAllSslErrors = true; 1640 } 1641 1642 /*! 1643 \overload 1644 \since 4.6 1645 1646 This method tells QSslSocket to ignore only the errors given in \a 1647 errors. 1648 1649 Note that you can set the expected certificate in the SSL error: 1650 If, for instance, you want to connect to a server that uses 1651 a self-signed certificate, consider the following snippet: 1652 1653 \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 6 1654 1655 Multiple calls to this function will replace the list of errors that 1656 were passed in previous calls. 1657 You can clear the list of errors you want to ignore by calling this 1658 function with an empty list. 1659 1660 \sa sslErrors() 1661 */ 1662 void QSslSocket::ignoreSslErrors(const QList<QSslError> &errors) 1663 { 1664 Q_D(QSslSocket); 1665 d->ignoreErrorsList = errors; 1566 1666 } 1567 1667 … … 1579 1679 #ifdef QSSLSOCKET_DEBUG 1580 1680 qDebug() << "QSslSocket::connectToHostImplementation(" 1581 << hostName << "," << port << "," << openMode << ")";1681 << hostName << ',' << port << ',' << openMode << ')'; 1582 1682 #endif 1583 1683 if (!d->plainSocket) { … … 1653 1753 } 1654 1754 #ifdef QSSLSOCKET_DEBUG 1655 qDebug() << "QSslSocket::readData(" << (void *)data << ","<< maxlen << ") ==" << readBytes;1755 qDebug() << "QSslSocket::readData(" << (void *)data << ',' << maxlen << ") ==" << readBytes; 1656 1756 #endif 1757 1758 // possibly trigger another transmit() to decrypt more data from the socket 1759 if (d->readBuffer.isEmpty() && d->plainSocket->bytesAvailable()) 1760 QMetaObject::invokeMethod(this, "_q_flushReadBuffer", Qt::QueuedConnection); 1761 1657 1762 return readBytes; 1658 1763 } … … 1665 1770 Q_D(QSslSocket); 1666 1771 #ifdef QSSLSOCKET_DEBUG 1667 qDebug() << "QSslSocket::writeData(" << (void *)data << "," << len << ")";1772 qDebug() << "QSslSocket::writeData(" << (void *)data << ',' << len << ')'; 1668 1773 #endif 1669 1774 if (d->mode == UnencryptedMode && !d->autoStartHandshake) … … 1683 1788 */ 1684 1789 QSslSocketPrivate::QSslSocketPrivate() 1685 : initialized(false), readyReadEmittedPointer(0), plainSocket(0) 1790 : initialized(false) 1791 , mode(QSslSocket::UnencryptedMode) 1792 , autoStartHandshake(false) 1793 , connectionEncrypted(false) 1794 , ignoreAllSslErrors(false) 1795 , readyReadEmittedPointer(0) 1796 , plainSocket(0) 1686 1797 { 1687 1798 QSslConfigurationPrivate::deepCopyDefaultConfiguration(&configuration); … … 1703 1814 autoStartHandshake = false; 1704 1815 connectionEncrypted = false; 1705 ignoreSslErrors = false; 1816 ignoreAllSslErrors = false; 1817 1818 // we don't want to clear the ignoreErrorsList, so 1819 // that it is possible setting it before connecting 1820 // ignoreErrorsList.clear(); 1706 1821 1707 1822 readBuffer.clear(); … … 1970 2085 Q_Q(QSslSocket); 1971 2086 #ifdef QSSLSOCKET_DEBUG 1972 qDebug() << "QSslSocket::_q_stateChangedSlot(" << state << ")";2087 qDebug() << "QSslSocket::_q_stateChangedSlot(" << state << ')'; 1973 2088 #endif 1974 2089 q->setSocketState(state); … … 1983 2098 Q_Q(QSslSocket); 1984 2099 #ifdef QSSLSOCKET_DEBUG 1985 qDebug() << "QSslSocket::_q_errorSlot(" << error << ")";2100 qDebug() << "QSslSocket::_q_errorSlot(" << error << ')'; 1986 2101 qDebug() << "\tstate =" << q->state(); 1987 2102 qDebug() << "\terrorString =" << q->errorString(); … … 2018 2133 Q_Q(QSslSocket); 2019 2134 #ifdef QSSLSOCKET_DEBUG 2020 qDebug() << "QSslSocket::_q_bytesWrittenSlot(" << written << ")";2135 qDebug() << "QSslSocket::_q_bytesWrittenSlot(" << written << ')'; 2021 2136 #endif 2022 2137 … … 2039 2154 } 2040 2155 2156 /*! 2157 \internal 2158 */ 2159 void QSslSocketPrivate::_q_flushReadBuffer() 2160 { 2161 // trigger a read from the plainSocket into SSL 2162 if (mode != QSslSocket::UnencryptedMode) 2163 transmit(); 2164 } 2165 2041 2166 QT_END_NAMESPACE 2042 2167
Note:
See TracChangeset
for help on using the changeset viewer.