Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/ssl/qsslsocket.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtNetwork module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    5050
    5151    \reentrant
    52     \ingroup io
     52    \ingroup network
    5353    \ingroup ssl
    5454    \inmodule QtNetwork
     
    114114    internal buffer, and you can call write() or putChar() to write
    115115    data back to the peer. QSslSocket will automatically encrypt the
    116     written data for you, and emit bytesWritten() once the data has
    117     been written to the peer.
     116    written data for you, and emit encryptedBytesWritten() once
     117    the data has been written to the peer.
    118118
    119119    As a convenience, QSslSocket supports QTcpSocket's blocking
     
    150150    for use in the OpenSSL Toolkit (\l{http://www.openssl.org/}).
    151151
     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
    152159    \sa QSslCertificate, QSslCipher, QSslError
    153160*/
     
    357364    ignoreSslErrors(), either from inside a slot function connected to
    358365    the sslErrors() signal, or prior to entering encrypted mode. If
    359     ignoreSslErrors is not called, the connection is dropped, signal
     366    ignoreSslErrors() is not called, the connection is dropped, signal
    360367    disconnected() is emitted, and QSslSocket returns to the
    361368    UnconnectedState.
     
    398405
    399406/*!
     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*/
     417void 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/*!
    400437    Initializes QSslSocket with the native socket descriptor \a
    401438    socketDescriptor. Returns true if \a socketDescriptor is accepted
     
    413450    Q_D(QSslSocket);
    414451#ifdef QSSLSOCKET_DEBUG
    415     qDebug() << "QSslSocket::setSocketDescriptor(" << socketDescriptor << ","
    416              << state << "," << openMode << ")";
     452    qDebug() << "QSslSocket::setSocketDescriptor(" << socketDescriptor << ','
     453             << state << ',' << openMode << ')';
    417454#endif
    418455    if (!d->plainSocket)
     
    432469
    433470/*!
     471    \since 4.6
     472    Sets the given \a option to the value described by \a value.
     473
     474    \sa socketOption()
     475*/
     476void 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*/
     489QVariant 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/*!
    434499    Returns the current mode for the socket; either UnencryptedMode, where
    435500    QSslSocket behaves identially to QTcpSocket, or one of SslClientMode or
     
    451516
    452517    An encrypted socket encrypts all data that is written by calling write()
    453     or putChar() before the data is written to the network, and descrypts all
     518    or putChar() before the data is written to the network, and decrypts all
    454519    incoming data as the data is received from the network, before you call
    455520    read(), readLine() or getChar().
     
    654719    qDebug() << "QSslSocket::close()";
    655720#endif
     721    Q_D(QSslSocket);
     722    if (d->plainSocket)
     723        d->plainSocket->close();
    656724    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
    657733}
    658734
     
    12591335
    12601336/*!
    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
    12651339    returned by this function is used to initialize the database
    12661340    returned by defaultCaCertificates(). You can replace that database
     
    15281602    Q_D(QSslSocket);
    15291603    if (d->mode != UnencryptedMode) {
    1530         qWarning("QSslSocket::startClientEncryption: cannot start handshake on non-plain connection");
     1604        qWarning("QSslSocket::startServerEncryption: cannot start handshake on non-plain connection");
    15311605        return;
    15321606    }
     
    15631637{
    15641638    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*/
     1662void QSslSocket::ignoreSslErrors(const QList<QSslError> &errors)
     1663{
     1664    Q_D(QSslSocket);
     1665    d->ignoreErrorsList = errors;
    15661666}
    15671667
     
    15791679#ifdef QSSLSOCKET_DEBUG
    15801680    qDebug() << "QSslSocket::connectToHostImplementation("
    1581              << hostName << "," << port << "," << openMode << ")";
     1681             << hostName << ',' << port << ',' << openMode << ')';
    15821682#endif
    15831683    if (!d->plainSocket) {
     
    16531753    }
    16541754#ifdef QSSLSOCKET_DEBUG
    1655     qDebug() << "QSslSocket::readData(" << (void *)data << "," << maxlen << ") ==" << readBytes;
     1755    qDebug() << "QSslSocket::readData(" << (void *)data << ',' << maxlen << ") ==" << readBytes;
    16561756#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
    16571762    return readBytes;
    16581763}
     
    16651770    Q_D(QSslSocket);
    16661771#ifdef QSSLSOCKET_DEBUG
    1667     qDebug() << "QSslSocket::writeData(" << (void *)data << "," << len << ")";
     1772    qDebug() << "QSslSocket::writeData(" << (void *)data << ',' << len << ')';
    16681773#endif
    16691774    if (d->mode == UnencryptedMode && !d->autoStartHandshake)
     
    16831788*/
    16841789QSslSocketPrivate::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)
    16861797{
    16871798    QSslConfigurationPrivate::deepCopyDefaultConfiguration(&configuration);
     
    17031814    autoStartHandshake = false;
    17041815    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();
    17061821
    17071822    readBuffer.clear();
     
    19702085    Q_Q(QSslSocket);
    19712086#ifdef QSSLSOCKET_DEBUG
    1972     qDebug() << "QSslSocket::_q_stateChangedSlot(" << state << ")";
     2087    qDebug() << "QSslSocket::_q_stateChangedSlot(" << state << ')';
    19732088#endif
    19742089    q->setSocketState(state);
     
    19832098    Q_Q(QSslSocket);
    19842099#ifdef QSSLSOCKET_DEBUG
    1985     qDebug() << "QSslSocket::_q_errorSlot(" << error << ")";
     2100    qDebug() << "QSslSocket::_q_errorSlot(" << error << ')';
    19862101    qDebug() << "\tstate =" << q->state();
    19872102    qDebug() << "\terrorString =" << q->errorString();
     
    20182133    Q_Q(QSslSocket);
    20192134#ifdef QSSLSOCKET_DEBUG
    2020     qDebug() << "QSslSocket::_q_bytesWrittenSlot(" << written << ")";
     2135    qDebug() << "QSslSocket::_q_bytesWrittenSlot(" << written << ')';
    20212136#endif
    20222137
     
    20392154}
    20402155
     2156/*!
     2157    \internal
     2158*/
     2159void QSslSocketPrivate::_q_flushReadBuffer()
     2160{
     2161    // trigger a read from the plainSocket into SSL
     2162    if (mode != QSslSocket::UnencryptedMode)
     2163        transmit();
     2164}
     2165
    20412166QT_END_NAMESPACE
    20422167
Note: See TracChangeset for help on using the changeset viewer.