diff options
Diffstat (limited to 'src/network')
28 files changed, 333 insertions, 367 deletions
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 50a3b1edaa..a7f96fa463 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -1434,36 +1434,6 @@ QFtp::QFtp(QObject *parent) SIGNAL(listInfo(QUrlInfo))); } -#ifdef QT3_SUPPORT -/*! - Use one of the constructors that doesn't take the \a name - argument and then use setObjectName() instead. -*/ -QFtp::QFtp(QObject *parent, const char *name) - : QObject(*new QFtpPrivate, parent) -{ - Q_D(QFtp); - setObjectName(QLatin1String(name)); - d->errorString = tr("Unknown error"); - - connect(&d->pi, SIGNAL(connectState(int)), - SLOT(_q_piConnectState(int))); - connect(&d->pi, SIGNAL(finished(QString)), - SLOT(_q_piFinished(QString))); - connect(&d->pi, SIGNAL(error(int,QString)), - SLOT(_q_piError(int,QString))); - connect(&d->pi, SIGNAL(rawFtpReply(int,QString)), - SLOT(_q_piFtpReply(int,QString))); - - connect(&d->pi.dtp, SIGNAL(readyRead()), - SIGNAL(readyRead())); - connect(&d->pi.dtp, SIGNAL(dataTransferProgress(qint64,qint64)), - SIGNAL(dataTransferProgress(qint64,qint64))); - connect(&d->pi.dtp, SIGNAL(listInfo(QUrlInfo)), - SIGNAL(listInfo(QUrlInfo))); -} -#endif - /*! \enum QFtp::State diff --git a/src/network/access/qftp.h b/src/network/access/qftp.h index 2a58344780..671b9ba7c7 100644 --- a/src/network/access/qftp.h +++ b/src/network/access/qftp.h @@ -124,10 +124,6 @@ public: qint64 bytesAvailable() const; qint64 read(char *data, qint64 maxlen); -#ifdef QT3_SUPPORT - inline QT3_SUPPORT qint64 readBlock(char *data, quint64 maxlen) - { return read(data, qint64(maxlen)); } -#endif QByteArray readAll(); int currentId() const; @@ -155,11 +151,6 @@ Q_SIGNALS: void commandFinished(int, bool); void done(bool); -#ifdef QT3_SUPPORT -public: - QT3_SUPPORT_CONSTRUCTOR QFtp(QObject *parent, const char *name); -#endif - private: Q_DISABLE_COPY(QFtp) Q_DECLARE_PRIVATE(QFtp) diff --git a/src/network/access/qhttp.h b/src/network/access/qhttp.h index 9018b767ff..83b23f85f9 100644 --- a/src/network/access/qhttp.h +++ b/src/network/access/qhttp.h @@ -232,10 +232,6 @@ public: qint64 bytesAvailable() const; qint64 read(char *data, qint64 maxlen); -#ifdef QT3_SUPPORT - inline QT3_SUPPORT qint64 readBlock(char *data, quint64 maxlen) - { return read(data, qint64(maxlen)); } -#endif QByteArray readAll(); int currentId() const; diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index d950af4ee2..a8a4fd9ae7 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -46,6 +46,7 @@ #include <private/qnetworkrequest_p.h> #include <private/qobject_p.h> #include <private/qauthenticator_p.h> +#include "private/qhostinfo_p.h" #include <qnetworkproxy.h> #include <qauthenticator.h> @@ -83,7 +84,8 @@ const int QHttpNetworkConnectionPrivate::defaultRePipelineLength = 2; QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt) : state(RunningState), hostName(hostName), port(port), encrypt(encrypt), - channelCount(defaultChannelCount) + channelCount(defaultChannelCount), + networkLayerState(Unknown) #ifndef QT_NO_NETWORKPROXY , networkProxy(QNetworkProxy::NoProxy) #endif @@ -94,7 +96,8 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt) : state(RunningState), hostName(hostName), port(port), encrypt(encrypt), - channelCount(channelCount) + channelCount(channelCount), + networkLayerState(Unknown) #ifndef QT_NO_NETWORKPROXY , networkProxy(QNetworkProxy::NoProxy) #endif @@ -174,6 +177,45 @@ int QHttpNetworkConnectionPrivate::indexOf(QAbstractSocket *socket) const return 0; } +// If the connection is in the InProgress state channel errors should not always be +// emitted. This function will check the status of the connection channels if we +// have not decided the networkLayerState and will return true if the channel error +// should be emitted by the channel. +bool QHttpNetworkConnectionPrivate::shouldEmitChannelError(QAbstractSocket *socket) +{ + Q_Q(QHttpNetworkConnection); + + bool emitError = true; + int i = indexOf(socket); + int otherSocket = (i == 0 ? 1 : 0); + + if (networkLayerState == QHttpNetworkConnectionPrivate::InProgress) { + if (channels[otherSocket].isSocketBusy() && (channels[otherSocket].state != QHttpNetworkConnectionChannel::ClosingState)) { + // this was the first socket to fail. + channels[i].close(); + emitError = false; + } + else { + // Both connection attempts has failed. + networkLayerState = QHttpNetworkConnectionPrivate::Unknown; + channels[i].close(); + emitError = true; + } + } else { + if ((networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (channels[i].networkLayerPreference != QAbstractSocket::IPv4Protocol) + || (networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (channels[i].networkLayerPreference != QAbstractSocket::IPv6Protocol)) { + // First connection worked so this is the second one to complete and it failed. + channels[i].close(); + QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); + emitError = false; + } + if (networkLayerState == QHttpNetworkConnectionPrivate::Unknown) + qWarning() << "We got a connection error when networkLayerState is Unknown"; + } + return emitError; +} + + qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailable(const QHttpNetworkReply &reply) const { return reply.d_func()->responseData.byteAmount(); @@ -469,17 +511,23 @@ QHttpNetworkReply* QHttpNetworkConnectionPrivate::queueRequest(const QHttpNetwor break; } - // this used to be called via invokeMethod and a QueuedConnection - // It is the only place _q_startNextRequest is called directly without going - // through the event loop using a QueuedConnection. - // This is dangerous because of recursion that might occur when emitting - // signals as DirectConnection from this code path. Therefore all signal - // emissions that can come out from this code path need to - // be QueuedConnection. - // We are currently trying to fine-tune this. - _q_startNextRequest(); - - + // For Happy Eyeballs the networkLayerState is set to Unkown + // untill we have started the first connection attempt. So no + // request will be started untill we know if IPv4 or IPv6 + // should be used. + if (networkLayerState == Unknown) { + startHostInfoLookup(); + } else if ( networkLayerState == IPv4 || networkLayerState == IPv6 ) { + // this used to be called via invokeMethod and a QueuedConnection + // It is the only place _q_startNextRequest is called directly without going + // through the event loop using a QueuedConnection. + // This is dangerous because of recursion that might occur when emitting + // signals as DirectConnection from this code path. Therefore all signal + // emissions that can come out from this code path need to + // be QueuedConnection. + // We are currently trying to fine-tune this. + _q_startNextRequest(); + } return reply; } @@ -781,6 +829,10 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) // although it is called _q_startNextRequest, it will actually start multiple requests when possible void QHttpNetworkConnectionPrivate::_q_startNextRequest() { + // If there is no network layer state decided we should not start any new requests. + if (networkLayerState == Unknown || networkLayerState == InProgress) + return; + // If the QHttpNetworkConnection is currently paused then bail out immediately if (state == PausedState) return; @@ -830,11 +882,15 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() // connected or not. This is to reuse connected channels before we connect new once. int queuedRequest = highPriorityQueue.count() + lowPriorityQueue.count(); for (int i = 0; i < channelCount; ++i) { - if (channels[i].socket->state() == QAbstractSocket::ConnectingState) + if ((channels[i].socket->state() == QAbstractSocket::ConnectingState) || (channels[i].socket->state() == QAbstractSocket::HostLookupState)) queuedRequest--; if ( queuedRequest <=0 ) break; if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState)) { + if (networkLayerState == IPv4) + channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol; + else if (networkLayerState == IPv6) + channels[i].networkLayerPreference = QAbstractSocket::IPv6Protocol; channels[i].ensureConnection(); queuedRequest--; } @@ -853,6 +909,100 @@ void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply) } } + + +// The first time we start the connection is used we do not know if we +// should use IPv4 or IPv6. So we start a hostlookup to figure this out. +// Later when we do the connection the socket will not need to do another +// lookup as then the hostinfo will already be in the cache. +void QHttpNetworkConnectionPrivate::startHostInfoLookup() +{ + // At this time all channels should be unconnected. + Q_ASSERT(!channels[0].isSocketBusy()); + Q_ASSERT(!channels[1].isSocketBusy()); + + networkLayerState = InProgress; + + // check if we already now can descide if this is IPv4 or IPv6 + QHostAddress temp; + if (temp.setAddress(hostName)) { + if (temp.protocol() == QAbstractSocket::IPv4Protocol) { + networkLayerState = QHttpNetworkConnectionPrivate::IPv4; + QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); + return; + } else if (temp.protocol() == QAbstractSocket::IPv6Protocol) { + networkLayerState = QHttpNetworkConnectionPrivate::IPv6; + QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); + return; + } + } else { + int hostLookupId; + bool immediateResultValid = false; + QHostInfo hostInfo = qt_qhostinfo_lookup(hostName, + this->q_func(), + SLOT(_q_hostLookupFinished(QHostInfo)), + &immediateResultValid, + &hostLookupId); + if (immediateResultValid) { + _q_hostLookupFinished(hostInfo); + } + } +} + + +void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(QHostInfo info) +{ + bool bIpv4 = false; + bool bIpv6 = false; + + foreach (QHostAddress address, info.addresses()) { + if (address.protocol() == QAbstractSocket::IPv4Protocol) + bIpv4 = true; + else if (address.protocol() == QAbstractSocket::IPv6Protocol) + bIpv6 = true; + } + + if (bIpv4 && bIpv6) + startNetworkLayerStateLookup(); + else if (bIpv4) { + networkLayerState = QHttpNetworkConnectionPrivate::IPv4; + QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); + } else if (bIpv6) { + networkLayerState = QHttpNetworkConnectionPrivate::IPv6; + QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); + } else { + if (dequeueRequest(channels[0].socket)) { + emitReplyError(channels[0].socket, channels[0].reply, QNetworkReply::HostNotFoundError); + networkLayerState = QHttpNetworkConnectionPrivate::Unknown; + } else { + // Should not happen + qWarning() << "QHttpNetworkConnectionPrivate::_q_hostLookupFinished could not dequeu request"; + networkLayerState = QHttpNetworkConnectionPrivate::Unknown; + } + } +} + + +// This will be used if the host lookup found both and Ipv4 and +// Ipv6 address. Then we will start up two connections and pick +// the network layer of the one that finish first. The second +// connection will then be disconnected. +void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup() +{ + // At this time all channels should be unconnected. + Q_ASSERT(!channels[0].isSocketBusy()); + Q_ASSERT(!channels[1].isSocketBusy()); + + networkLayerState = InProgress; + + channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; + channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol; + + channels[0].ensureConnection(); // Possibly delay this one.. + channels[1].ensureConnection(); +} + + #ifndef QT_NO_BEARERMANAGEMENT QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent, QSharedPointer<QNetworkSession> networkSession) : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt)), parent) diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 6c953be58d..0c86fd94b9 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -82,6 +82,7 @@ QT_BEGIN_NAMESPACE class QHttpNetworkRequest; class QHttpNetworkReply; class QByteArray; +class QHostInfo; class QHttpNetworkConnectionPrivate; class Q_AUTOTEST_EXPORT QHttpNetworkConnection : public QObject @@ -132,6 +133,7 @@ private: friend class QHttpNetworkConnectionChannel; Q_PRIVATE_SLOT(d_func(), void _q_startNextRequest()) + Q_PRIVATE_SLOT(d_func(), void _q_hostLookupFinished(QHostInfo)) }; @@ -152,6 +154,13 @@ public: PausedState = 1, }; + enum NetworkLayerPreferenceState { + Unknown, + InProgress, + IPv4, + IPv6 + }; + QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt); QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt); ~QHttpNetworkConnectionPrivate(); @@ -160,6 +169,7 @@ public: void pauseConnection(); void resumeConnection(); ConnectionState state; + NetworkLayerPreferenceState networkLayerState; enum { ChunkSize = 4096 }; @@ -179,9 +189,14 @@ public: void copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy); + void startHostInfoLookup(); + void startNetworkLayerStateLookup(); + // private slots void _q_startNextRequest(); // send the next request from the queue + void _q_hostLookupFinished(QHostInfo info); + void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request); QString errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket, @@ -198,6 +213,7 @@ public: const int channelCount; QHttpNetworkConnectionChannel *channels; // parallel connections to the server + bool shouldEmitChannelError(QAbstractSocket *socket); qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const; qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const; diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 7c644ad4b9..b8ed8ee567 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -80,6 +80,7 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() #endif , pipeliningSupported(PipeliningSupportUnknown) , connection(0) + , networkLayerPreference(QAbstractSocket::AnyIPProtocol) { // Inlining this function in the header leads to compiler error on // release-armv5, on at least timebox 9.2 and 10.1. @@ -594,7 +595,7 @@ bool QHttpNetworkConnectionChannel::ensureConnection() if (ssl) { #ifndef QT_NO_OPENSSL QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); - sslSocket->connectToHostEncrypted(connectHost, connectPort); + sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); if (ignoreAllSslErrors) sslSocket->ignoreSslErrors(); sslSocket->ignoreSslErrors(ignoreSslErrorsList); @@ -613,12 +614,12 @@ bool QHttpNetworkConnectionChannel::ensureConnection() && connection->cacheProxy().type() == QNetworkProxy::NoProxy && connection->transparentProxy().type() == QNetworkProxy::NoProxy) { #endif - socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered); + socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered, networkLayerPreference); // For an Unbuffered QTcpSocket, the read buffer size has a special meaning. socket->setReadBufferSize(1*1024); #ifndef QT_NO_NETWORKPROXY } else { - socket->connectToHost(connectHost, connectPort); + socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); // limit the socket read buffer size. we will read everything into // the QHttpNetworkReply anyway, so let's grow only that and not @@ -1002,6 +1003,25 @@ void QHttpNetworkConnectionChannel::_q_disconnected() void QHttpNetworkConnectionChannel::_q_connected() { + // For the Happy Eyeballs we need to check if this is the first channel to connect. + if (!pendingEncrypt) { + if (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::InProgress) { + if (networkLayerPreference == QAbstractSocket::IPv4Protocol) + connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; + else if (networkLayerPreference == QAbstractSocket::IPv6Protocol) + connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; + } else { + if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol)) + || ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) { + close(); + // This is the second connection so it has to be closed and we can schedule it for another request. + QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); + return; + } + //The connections networkLayerState had already been decided. + } + } + // improve performance since we get the request sent by the kernel ASAP //socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); // We have this commented out now. It did not have the effect we wanted. If we want to @@ -1089,6 +1109,11 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket QPointer<QHttpNetworkConnection> that = connection; QString errorString = connection->d_func()->errorDetail(errorCode, socket, socket->errorString()); + // In the InProgress state the channel should not emit the error. + // This will instead be handled by the connection. + if (!connection->d_func()->shouldEmitChannelError(socket)) + return; + // Need to dequeu the request so that we can emit the error. if (!reply) connection->d_func()->dequeueRequest(socket); diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h index f635cc9557..8400f62ab9 100644 --- a/src/network/access/qhttpnetworkconnectionchannel_p.h +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -136,6 +136,8 @@ public: void detectPipeliningSupport(); QHttpNetworkConnectionChannel(); + + QAbstractSocket::NetworkLayerProtocol networkLayerPreference; void setConnection(QHttpNetworkConnection *c); QPointer<QHttpNetworkConnection> connection; diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index f4c905f007..df0a32dd6c 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -365,6 +365,7 @@ qint64 QNetworkReplyHttpImpl::readData(char* data, qint64 maxlen) void QNetworkReplyHttpImpl::setReadBufferSize(qint64 size) { + Q_UNUSED(size); // FIXME, unsupported right now return; } @@ -379,7 +380,8 @@ bool QNetworkReplyHttpImpl::canReadLine () const if (d->cacheLoadDevice) return d->cacheLoadDevice->canReadLine() || d->downloadMultiBuffer.canReadLine(); - // FIXME zerocopy buffer? + if (d->downloadZerocopyBuffer) + return memchr(d->downloadZerocopyBuffer + d->downloadBufferReadPosition, '\n', d->downloadBufferCurrentSize - d->downloadBufferReadPosition); return d->downloadMultiBuffer.canReadLine(); } @@ -876,6 +878,7 @@ void QNetworkReplyHttpImplPrivate::postRequest() delegate->isPipeliningUsed, QSharedPointer<char>(), delegate->incomingContentLength); + replyDownloadData(delegate->synchronousDownloadData); httpError(delegate->incomingErrorCode, delegate->incomingErrorDetail); } else { replyDownloadMetaData @@ -1168,7 +1171,6 @@ void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceive void QNetworkReplyHttpImplPrivate::httpAuthenticationRequired(const QHttpNetworkRequest &, QAuthenticator *auth) { - Q_Q(QNetworkReplyHttpImpl); managerPrivate->authenticationRequired(auth, q_func(), synchronous, url, &urlForLastAuthentication); } diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 5608f1f9a3..7f61ef9239 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -77,28 +77,33 @@ QT_BEGIN_NAMESPACE List of known header types that QNetworkRequest parses. Each known header is also represented in raw form with its full HTTP name. - \value ContentTypeHeader corresponds to the HTTP Content-Type + \value ContentDispositionHeader Corresponds to the HTTP + Content-Disposition header and contains a string containing the + disposition type (for instance, attachment) and a parameter (for + instance, filename). + + \value ContentTypeHeader Corresponds to the HTTP Content-Type header and contains a string containing the media (MIME) type and - any auxiliary data (for instance, charset) + any auxiliary data (for instance, charset). - \value ContentLengthHeader corresponds to the HTTP Content-Length + \value ContentLengthHeader Corresponds to the HTTP Content-Length header and contains the length in bytes of the data transmitted. - \value LocationHeader corresponds to the HTTP Location + \value LocationHeader Corresponds to the HTTP Location header and contains a URL representing the actual location of the data, including the destination URL in case of redirections. - \value LastModifiedHeader corresponds to the HTTP Last-Modified + \value LastModifiedHeader Corresponds to the HTTP Last-Modified header and contains a QDateTime representing the last modification - date of the contents + date of the contents. - \value CookieHeader corresponds to the HTTP Cookie header + \value CookieHeader Corresponds to the HTTP Cookie header and contains a QList<QNetworkCookie> representing the cookies to - be sent back to the server + be sent back to the server. - \value SetCookieHeader corresponds to the HTTP Set-Cookie + \value SetCookieHeader Corresponds to the HTTP Set-Cookie header and contains a QList<QNetworkCookie> representing the - cookies sent by the server to be stored locally + cookies sent by the server to be stored locally. \sa header(), setHeader(), rawHeader(), setRawHeader() */ diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp index bff351c34f..3dd7461a75 100644 --- a/src/network/kernel/qhostaddress.cpp +++ b/src/network/kernel/qhostaddress.cpp @@ -38,19 +38,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #include "qhostaddress.h" #include "qhostaddress_p.h" #include "qdebug.h" +#if defined(Q_OS_WIN) +#include <winsock2.h> +#endif #include "qplatformdefs.h" #include "qstringlist.h" #include "qendian.h" #ifndef QT_NO_DATASTREAM #include <qdatastream.h> #endif -#if defined(Q_OS_WINCE) -#include <winsock.h> -#endif #ifdef QT_LINUXBASE # include <arpa/inet.h> @@ -65,7 +64,6 @@ QT_BEGIN_NAMESPACE } while (0) #ifdef Q_OS_WIN -# if !defined (QT_NO_IPV6) // sockaddr_in6 size changed between old and new SDK // Only the new version is the correct one, so always // use this structure. @@ -90,12 +88,6 @@ typedef struct { struct qt_in6_addr sin6_addr; /* IPv6 address */ u_long sin6_scope_id; /* set of interfaces for a scope */ } qt_sockaddr_in6; -# else -typedef void * qt_sockaddr_in6 ; -# endif -# ifndef AF_INET6 -# define AF_INET6 23 /* Internetwork Version 6 */ -# endif #else #define qt_sockaddr_in6 sockaddr_in6 #define qt_s6_addr s6_addr @@ -545,10 +537,8 @@ QHostAddress::QHostAddress(const struct sockaddr *sockaddr) { if (sockaddr->sa_family == AF_INET) setAddress(htonl(((sockaddr_in *)sockaddr)->sin_addr.s_addr)); -#ifndef QT_NO_IPV6 else if (sockaddr->sa_family == AF_INET6) setAddress(((qt_sockaddr_in6 *)sockaddr)->sin6_addr.qt_s6_addr); -#endif } /*! @@ -700,10 +690,8 @@ void QHostAddress::setAddress(const struct sockaddr *sockaddr) clear(); if (sockaddr->sa_family == AF_INET) setAddress(htonl(((sockaddr_in *)sockaddr)->sin_addr.s_addr)); -#ifndef QT_NO_IPV6 else if (sockaddr->sa_family == AF_INET6) setAddress(((qt_sockaddr_in6 *)sockaddr)->sin6_addr.qt_s6_addr); -#endif } /*! diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h index efb3198fc0..3d364de6e6 100644 --- a/src/network/kernel/qhostaddress.h +++ b/src/network/kernel/qhostaddress.h @@ -117,15 +117,6 @@ public: bool isNull() const; void clear(); -#ifdef QT3_SUPPORT - inline QT3_SUPPORT quint32 ip4Addr() const { return toIPv4Address(); } - inline QT3_SUPPORT bool isIPv4Address() const { return protocol() == QAbstractSocket::IPv4Protocol - || protocol() == QAbstractSocket::UnknownNetworkLayerProtocol; } - inline QT3_SUPPORT bool isIp4Addr() const { return protocol() == QAbstractSocket::IPv4Protocol - || protocol() == QAbstractSocket::UnknownNetworkLayerProtocol; } - inline QT3_SUPPORT bool isIPv6Address() const { return protocol() == QAbstractSocket::IPv6Protocol; } -#endif - bool isInSubnet(const QHostAddress &subnet, int netmask) const; bool isInSubnet(const QPair<QHostAddress, int> &subnet) const; diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index 0a56bc309a..37444ae2d9 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -149,9 +149,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) // Reverse lookups using getnameinfo are broken on darwin, use gethostbyaddr instead. #if !defined (QT_NO_GETADDRINFO) && !defined (Q_OS_DARWIN) sockaddr_in sa4; -#ifndef QT_NO_IPV6 sockaddr_in6 sa6; -#endif sockaddr *sa = 0; QT_SOCKLEN_T saSize = 0; if (address.protocol() == QAbstractSocket::IPv4Protocol) { @@ -161,7 +159,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) sa4.sin_family = AF_INET; sa4.sin_addr.s_addr = htonl(address.toIPv4Address()); } -#ifndef QT_NO_IPV6 else { sa = (sockaddr *)&sa6; saSize = sizeof(sa6); @@ -169,7 +166,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) sa6.sin6_family = AF_INET6; memcpy(sa6.sin6_addr.s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.s6_addr)); } -#endif char hbuf[NI_MAXHOST]; if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0) @@ -231,7 +227,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) if (!addresses.contains(addr)) addresses.append(addr); } -#ifndef QT_NO_IPV6 else if (node->ai_family == AF_INET6) { QHostAddress addr; sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr; @@ -241,7 +236,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) if (!addresses.contains(addr)) addresses.append(addr); } -#endif node = node->ai_next; } if (addresses.isEmpty() && node == 0) { diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index 0ce21f905f..528e195ef6 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -80,10 +80,9 @@ static QHostAddress addressFromSockaddr(sockaddr *sa) if (sa->sa_family == AF_INET) address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr)); -#ifndef QT_NO_IPV6 else if (sa->sa_family == AF_INET6) address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr); -#endif + return address; } diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp index 4f9836e863..1062663b23 100644 --- a/src/network/kernel/qnetworkproxy.cpp +++ b/src/network/kernel/qnetworkproxy.cpp @@ -1191,6 +1191,11 @@ void QNetworkProxyQuery::setUrl(const QUrl &url) } #ifndef QT_NO_BEARERMANAGEMENT +/*! + Returns the network configuration component of the query. + + \sa setNetworkConfiguration() +*/ QNetworkConfiguration QNetworkProxyQuery::networkConfiguration() const { return d ? d->config : QNetworkConfiguration(); @@ -1206,7 +1211,7 @@ QNetworkConfiguration QNetworkProxyQuery::networkConfiguration() const you should first start the QNetworkSession and obtain the active configuration from its properties. - \sa networkConfiguration + \sa networkConfiguration() */ void QNetworkProxyQuery::setNetworkConfiguration(const QNetworkConfiguration &networkConfiguration) { diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 5316626638..b662a75259 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -483,7 +483,8 @@ QAbstractSocketPrivate::QAbstractSocketPrivate() hostLookupId(-1), socketType(QAbstractSocket::UnknownSocketType), state(QAbstractSocket::UnconnectedState), - socketError(QAbstractSocket::UnknownSocketError) + socketError(QAbstractSocket::UnknownSocketError), + preferredNetworkLayerProtocol(QAbstractSocket::UnknownNetworkLayerProtocol) { } @@ -892,6 +893,7 @@ void QAbstractSocketPrivate::startConnectingByName(const QString &host) void QAbstractSocketPrivate::_q_startConnecting(const QHostInfo &hostInfo) { Q_Q(QAbstractSocket); + addresses.clear(); if (state != QAbstractSocket::HostLookupState) return; @@ -899,7 +901,16 @@ void QAbstractSocketPrivate::_q_startConnecting(const QHostInfo &hostInfo) qWarning("QAbstractSocketPrivate::_q_startConnecting() received hostInfo for wrong lookup ID %d expected %d", hostInfo.lookupId(), hostLookupId); } - addresses = hostInfo.addresses(); + // Only add the addresses for the prefered network layer. + // Or all if prefered network layer is not set. + if (preferredNetworkLayerProtocol == QAbstractSocket::UnknownNetworkLayerProtocol || preferredNetworkLayerProtocol == QAbstractSocket::AnyIPProtocol) { + addresses = hostInfo.addresses(); + } else { + foreach (QHostAddress address, hostInfo.addresses()) + if (address.protocol() == preferredNetworkLayerProtocol) + addresses += address; + } + #if defined(QABSTRACTSOCKET_DEBUG) QString s = QLatin1String("{"); @@ -993,17 +1004,6 @@ void QAbstractSocketPrivate::_q_connectToNextAddress() host.toString().toLatin1().constData(), port, addresses.count()); #endif -#if defined(QT_NO_IPV6) - if (host.protocol() == QAbstractSocket::IPv6Protocol) { - // If we have no IPv6 support, then we will not be able to - // connect. So we just pretend we didn't see this address. -#if defined(QABSTRACTSOCKET_DEBUG) - qDebug("QAbstractSocketPrivate::_q_connectToNextAddress(), skipping IPv6 entry"); -#endif - continue; - } -#endif - if (!initSocketLayer(host.protocol())) { // hope that the next address is better #if defined(QABSTRACTSOCKET_DEBUG) @@ -1330,8 +1330,12 @@ bool QAbstractSocket::isValid() const \sa state(), peerName(), peerAddress(), peerPort(), waitForConnected() */ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port, - OpenMode openMode) + OpenMode openMode, + NetworkLayerProtocol protocol) { + Q_D(QAbstractSocket); + d->preferredNetworkLayerProtocol = protocol; + QMetaObject::invokeMethod(this, "connectToHostImplementation", Qt::DirectConnection, Q_ARG(QString, hostName), @@ -2501,10 +2505,6 @@ void QAbstractSocket::disconnectFromHostImplementation() return; } -#ifdef QT3_SUPPORT - emit connectionClosed(); // compat signal -#endif - // Disable and delete read notification if (d->socketEngine) d->socketEngine->setReadNotificationEnabled(false); @@ -2567,9 +2567,6 @@ void QAbstractSocket::disconnectFromHostImplementation() emit stateChanged(d->state); emit readChannelFinished(); // we got an EOF -#ifdef QT3_SUPPORT - emit delayedCloseFinished(); // compat signal -#endif // only emit disconnected if we were connected before if (previousState == ConnectedState || previousState == ClosingState) emit disconnected(); @@ -2747,78 +2744,6 @@ QNetworkProxy QAbstractSocket::proxy() const } #endif // QT_NO_NETWORKPROXY -#ifdef QT3_SUPPORT -/*! - \enum QAbstractSocket::Error - \compat - - Use QAbstractSocket::SocketError instead. - - \value ErrConnectionRefused Use QAbstractSocket::ConnectionRefusedError instead. - \value ErrHostNotFound Use QAbstractSocket::HostNotFoundError instead. - \value ErrSocketRead Use QAbstractSocket::UnknownSocketError instead. -*/ - -/*! - \typedef QAbstractSocket::State - \compat - - Use QAbstractSocket::SocketState instead. - - \table - \header \o Qt 3 enum value \o Qt 4 enum value - \row \o \c Idle \o \l UnconnectedState - \row \o \c HostLookup \o \l HostLookupState - \row \o \c Connecting \o \l ConnectingState - \row \o \c Connected \o \l ConnectedState - \row \o \c Closing \o \l ClosingState - \row \o \c Connection \o \l ConnectedState - \endtable -*/ - -/*! - \fn int QAbstractSocket::socket() const - - Use socketDescriptor() instead. -*/ - -/*! - \fn void QAbstractSocket::setSocket(int socket) - - Use setSocketDescriptor() instead. -*/ - -/*! - \fn Q_ULONG QAbstractSocket::waitForMore(int msecs, bool *timeout = 0) const - - Use waitForReadyRead() instead. - - \oldcode - bool timeout; - Q_ULONG numBytes = socket->waitForMore(30000, &timeout); - \newcode - qint64 numBytes = 0; - if (socket->waitForReadyRead(msecs)) - numBytes = socket->bytesAvailable(); - bool timeout = (error() == QAbstractSocket::SocketTimeoutError); - \endcode - - \sa waitForReadyRead(), bytesAvailable(), error(), SocketTimeoutError -*/ - -/*! - \fn void QAbstractSocket::connectionClosed() - - Use disconnected() instead. -*/ - -/*! - \fn void QAbstractSocket::delayedCloseFinished() - - Use disconnected() instead. -*/ -#endif // QT3_SUPPORT - #ifndef QT_NO_DEBUG_STREAM Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error) { diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h index 2717ceb58a..b757092915 100644 --- a/src/network/socket/qabstractsocket.h +++ b/src/network/socket/qabstractsocket.h @@ -108,15 +108,6 @@ public: BoundState, ListeningState, ClosingState -#ifdef QT3_SUPPORT - , - Idle = UnconnectedState, - HostLookup = HostLookupState, - Connecting = ConnectingState, - Connected = ConnectedState, - Closing = ClosingState, - Connection = ConnectedState -#endif }; enum SocketOption { LowDelayOption, // TCP_NODELAY @@ -129,7 +120,7 @@ public: virtual ~QAbstractSocket(); // ### Qt 5: Make connectToHost() and disconnectFromHost() virtual. - void connectToHost(const QString &hostName, quint16 port, OpenMode mode = ReadWrite); + void connectToHost(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol); void connectToHost(const QHostAddress &address, quint16 port, OpenMode mode = ReadWrite); void disconnectFromHost(); @@ -221,32 +212,6 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt()) Q_PRIVATE_SLOT(d_func(), void _q_testConnection()) Q_PRIVATE_SLOT(d_func(), void _q_forceDisconnect()) - -#ifdef QT3_SUPPORT -public: - enum Error { - ErrConnectionRefused = ConnectionRefusedError, - ErrHostNotFound = HostNotFoundError, - ErrSocketRead = UnknownSocketError - }; - inline QT3_SUPPORT int socket() const { return socketDescriptor(); } - inline QT3_SUPPORT void setSocket(int socket) { setSocketDescriptor(socket); } - inline QT3_SUPPORT qulonglong waitForMore(int msecs, bool *timeout = 0) const - { - QAbstractSocket *that = const_cast<QAbstractSocket *>(this); - if (that->waitForReadyRead(msecs)) - return qulonglong(bytesAvailable()); - if (error() == SocketTimeoutError && timeout) - *timeout = true; - return 0; - } - typedef SocketState State; -Q_SIGNALS: - QT_MOC_COMPAT void connectionClosed(); // same as disconnected() - QT_MOC_COMPAT void delayedCloseFinished(); // same as disconnected() - - -#endif }; #ifndef QT_NO_DEBUG_STREAM diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h index cf7d98895f..978fb1433a 100644 --- a/src/network/socket/qabstractsocket_p.h +++ b/src/network/socket/qabstractsocket_p.h @@ -156,6 +156,8 @@ public: QAbstractSocket::SocketError socketError; + QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol; + bool prePauseReadSocketNotifierState; bool prePauseWriteSocketNotifierState; bool prePauseExceptionSocketNotifierState; diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp index 875852265e..2dc6a40d99 100644 --- a/src/network/socket/qnativesocketengine.cpp +++ b/src/network/socket/qnativesocketengine.cpp @@ -203,6 +203,7 @@ void QNativeSocketEnginePrivate::setError(QAbstractSocket::SocketError error, Er case BroadcastingInitFailedErrorString: socketErrorString = QNativeSocketEngine::tr("Unable to initialize broadcast socket"); break; + // should not happen anymore case NoIpV6ErrorString: socketErrorString = QNativeSocketEngine::tr("Attempt to use IPv6 socket on a platform with no IPv6 support"); break; @@ -345,14 +346,6 @@ bool QNativeSocketEngine::initialize(QAbstractSocket::SocketType socketType, QAb if (isValid()) close(); -#if defined(QT_NO_IPV6) - if (protocol == QAbstractSocket::IPv6Protocol) { - d->setError(QAbstractSocket::UnsupportedSocketOperationError, - QNativeSocketEnginePrivate::NoIpV6ErrorString); - return false; - } -#endif - // Create the socket if (!d->createNewSocket(socketType, protocol)) { #if defined (QNATIVESOCKETENGINE_DEBUG) @@ -511,13 +504,6 @@ bool QNativeSocketEngine::connectToHost(const QHostAddress &address, quint16 por Q_D(QNativeSocketEngine); Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::connectToHost(), false); -#if defined (QT_NO_IPV6) - if (address.protocol() == QAbstractSocket::IPv6Protocol) { - d->setError(QAbstractSocket::UnsupportedSocketOperationError, - QNativeSocketEnginePrivate::NoIpV6ErrorString); - return false; - } -#endif if (!d->checkProxy(address)) return false; @@ -581,13 +567,6 @@ bool QNativeSocketEngine::bind(const QHostAddress &address, quint16 port) Q_D(QNativeSocketEngine); Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::bind(), false); -#if defined (QT_NO_IPV6) - if (address.protocol() == QAbstractSocket::IPv6Protocol) { - d->setError(QAbstractSocket::UnsupportedSocketOperationError, - QNativeSocketEnginePrivate::NoIpV6ErrorString); - return false; - } -#endif if (!d->checkProxy(address)) return false; diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 26053981ce..246b5ede9b 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -124,7 +124,6 @@ static void qt_ignore_sigpipe() */ static inline void qt_socket_getPortAndAddress(const qt_sockaddr *s, quint16 *port, QHostAddress *addr) { -#if !defined(QT_NO_IPV6) if (s->a.sa_family == AF_INET6) { Q_IPV6ADDR tmp; memcpy(&tmp, &s->a6.sin6_addr, sizeof(tmp)); @@ -144,7 +143,7 @@ static inline void qt_socket_getPortAndAddress(const qt_sockaddr *s, quint16 *po *port = ntohs(s->a6.sin6_port); return; } -#endif + if (port) *port = ntohs(s->a4.sin_port); if (addr) { @@ -162,12 +161,7 @@ static inline void qt_socket_getPortAndAddress(const qt_sockaddr *s, quint16 *po bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType socketType, QAbstractSocket::NetworkLayerProtocol socketProtocol) { -#ifndef QT_NO_IPV6 int protocol = (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) ? AF_INET6 : AF_INET; -#else - Q_UNUSED(socketProtocol); - int protocol = AF_INET; -#endif int type = (socketType == QAbstractSocket::UdpSocket) ? SOCK_DGRAM : SOCK_STREAM; int socket = qt_safe_socket(protocol, type, 0); @@ -238,24 +232,20 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co n = SO_KEEPALIVE; break; case QNativeSocketEngine::MulticastTtlOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_HOPS; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_TTL; } break; case QNativeSocketEngine::MulticastLoopbackOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_LOOP; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_LOOP; @@ -343,24 +333,20 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt n = SO_KEEPALIVE; break; case QNativeSocketEngine::MulticastTtlOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_HOPS; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_TTL; } break; case QNativeSocketEngine::MulticastLoopbackOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_LOOP; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_LOOP; @@ -381,7 +367,6 @@ bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint16 struct sockaddr *sockAddrPtr = 0; QT_SOCKLEN_T sockAddrSize = 0; -#if !defined(QT_NO_IPV6) struct sockaddr_in6 sockAddrIPv6; if (addr.protocol() == QAbstractSocket::IPv6Protocol) { @@ -402,10 +387,6 @@ bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint16 sockAddrSize = sizeof(sockAddrIPv6); sockAddrPtr = (struct sockaddr *) &sockAddrIPv6; } else -#if 0 - {} -#endif -#endif if (addr.protocol() == QAbstractSocket::IPv4Protocol) { memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4)); sockAddrIPv4.sin_family = AF_INET; @@ -492,7 +473,7 @@ bool QNativeSocketEnginePrivate::nativeBind(const QHostAddress &address, quint16 struct sockaddr *sockAddrPtr = 0; QT_SOCKLEN_T sockAddrSize = 0; -#if !defined(QT_NO_IPV6) + struct sockaddr_in6 sockAddrIPv6; if (address.protocol() == QAbstractSocket::IPv6Protocol || address.protocol() == QAbstractSocket::AnyIPProtocol) { @@ -516,7 +497,6 @@ bool QNativeSocketEnginePrivate::nativeBind(const QHostAddress &address, quint16 sockAddrSize = sizeof(sockAddrIPv6); sockAddrPtr = (struct sockaddr *) &sockAddrIPv6; } else -#endif if (address.protocol() == QAbstractSocket::IPv4Protocol) { memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4)); sockAddrIPv4.sin_family = AF_INET; @@ -612,7 +592,6 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d, int sockArgSize; ip_mreq mreq4; -#ifndef QT_NO_IPV6 ipv6_mreq mreq6; if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) { @@ -625,7 +604,6 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d, memcpy(&mreq6.ipv6mr_multiaddr, &ip6, sizeof(ip6)); mreq6.ipv6mr_interface = interface.index(); } else -#endif if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) { level = IPPROTO_IP; sockOpt = how4; @@ -679,11 +657,7 @@ bool QNativeSocketEnginePrivate::nativeJoinMulticastGroup(const QHostAddress &gr const QNetworkInterface &interface) { return multicastMembershipHelper(this, -#ifndef QT_NO_IPV6 IPV6_JOIN_GROUP, -#else - 0, -#endif IP_ADD_MEMBERSHIP, groupAddress, interface); @@ -693,11 +667,7 @@ bool QNativeSocketEnginePrivate::nativeLeaveMulticastGroup(const QHostAddress &g const QNetworkInterface &interface) { return multicastMembershipHelper(this, -#ifndef QT_NO_IPV6 IPV6_LEAVE_GROUP, -#else - 0, -#endif IP_DROP_MEMBERSHIP, groupAddress, interface); @@ -705,7 +675,6 @@ bool QNativeSocketEnginePrivate::nativeLeaveMulticastGroup(const QHostAddress &g QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const { -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { uint v; QT_SOCKOPTLEN_T sizeofv = sizeof(v); @@ -713,7 +682,6 @@ QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const return QNetworkInterface(); return QNetworkInterface::interfaceFromIndex(v); } -#endif struct in_addr v = { 0 }; QT_SOCKOPTLEN_T sizeofv = sizeof(v); @@ -737,12 +705,10 @@ QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const bool QNativeSocketEnginePrivate::nativeSetMulticastInterface(const QNetworkInterface &iface) { -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { uint v = iface.index(); return (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, &v, sizeof(v)) != -1); } -#endif struct in_addr v; if (iface.isValid()) { @@ -871,7 +837,6 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l struct sockaddr *sockAddrPtr = 0; QT_SOCKLEN_T sockAddrSize = 0; -#if !defined(QT_NO_IPV6) struct sockaddr_in6 sockAddrIPv6; if (host.protocol() == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::IPv6Protocol) { @@ -884,7 +849,7 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l sockAddrSize = sizeof(sockAddrIPv6); sockAddrPtr = (struct sockaddr *)&sockAddrIPv6; } else -#endif + if (host.protocol() == QAbstractSocket::IPv4Protocol) { memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4)); sockAddrIPv4.sin_family = AF_INET; @@ -941,11 +906,9 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters() case AF_INET: socketProtocol = QAbstractSocket::IPv4Protocol; break; -#if !defined (QT_NO_IPV6) case AF_INET6: socketProtocol = QAbstractSocket::IPv6Protocol; break; -#endif default: socketProtocol = QAbstractSocket::UnknownNetworkLayerProtocol; break; diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index ba62bd6da2..67a9a2131a 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -165,7 +165,6 @@ static QByteArray qt_prettyDebug(const char *data, int len, int maxLength) */ static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt_sockaddr *sa, quint16 *port, QHostAddress *address) { -#if !defined (QT_NO_IPV6) if (sa->a.sa_family == AF_INET6) { const qt_sockaddr_in6 *sa6 = &sa->a6; Q_IPV6ADDR tmp; @@ -178,7 +177,7 @@ static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt if (port) WSANtohs(socketDescriptor, sa6->sin6_port, port); } else -#endif + if (sa->a.sa_family == AF_INET) { const sockaddr_in *sa4 = &sa->a4; unsigned long addr; @@ -200,7 +199,7 @@ static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt void QNativeSocketEnginePrivate::setPortAndAddress(sockaddr_in * sockAddrIPv4, qt_sockaddr_in6 * sockAddrIPv6, quint16 port, const QHostAddress & address, sockaddr ** sockAddrPtr, QT_SOCKLEN_T *sockAddrSize) { -#if !defined(QT_NO_IPV6) + if (address.protocol() == QAbstractSocket::IPv6Protocol || address.protocol() == QAbstractSocket::AnyIPProtocol || socketProtocol == QAbstractSocket::IPv6Protocol) { @@ -213,7 +212,7 @@ void QNativeSocketEnginePrivate::setPortAndAddress(sockaddr_in * sockAddrIPv4, q *sockAddrSize = sizeof(qt_sockaddr_in6); *sockAddrPtr = (struct sockaddr *) sockAddrIPv6; } else -#endif + if (address.protocol() == QAbstractSocket::IPv4Protocol || address.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol) { memset(sockAddrIPv4, 0, sizeof(sockaddr_in)); @@ -403,24 +402,21 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co n = SO_KEEPALIVE; break; case QNativeSocketEngine::MulticastTtlOption: -#ifndef QT_NO_IPV6 + if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_HOPS; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_TTL; } break; case QNativeSocketEngine::MulticastLoopbackOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_LOOP; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_LOOP; @@ -487,24 +483,20 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt n = SO_KEEPALIVE; break; case QNativeSocketEngine::MulticastTtlOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_HOPS; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_TTL; } break; case QNativeSocketEngine::MulticastLoopbackOption: -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { level = IPPROTO_IPV6; n = IPV6_MULTICAST_LOOP; } else -#endif { level = IPPROTO_IP; n = IP_MULTICAST_LOOP; @@ -545,11 +537,9 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters() case AF_INET: socketProtocol = QAbstractSocket::IPv4Protocol; break; -#if !defined (QT_NO_IPV6) case AF_INET6: socketProtocol = QAbstractSocket::IPv6Protocol; break; -#endif default: socketProtocol = QAbstractSocket::UnknownNetworkLayerProtocol; break; @@ -714,7 +704,7 @@ bool QNativeSocketEnginePrivate::nativeBind(const QHostAddress &a, quint16 port) // binding to a multicast address address = QHostAddress(QHostAddress::AnyIPv6); } -#if !defined (QT_NO_IPV6) && defined (IPV6_V6ONLY) +#if defined (IPV6_V6ONLY) //This is default in current windows versions, it may change in future so set it explicitly if (QSysInfo::windowsVersion() >= QSysInfo::WV_6_0) { ipv6only = 1; @@ -729,7 +719,7 @@ bool QNativeSocketEnginePrivate::nativeBind(const QHostAddress &a, quint16 port) } break; case QAbstractSocket::AnyIPProtocol: -#if !defined (QT_NO_IPV6) && defined (IPV6_V6ONLY) +#if defined (IPV6_V6ONLY) if (QSysInfo::windowsVersion() >= QSysInfo::WV_6_0) ipv6only = ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&ipv6only, sizeof(ipv6only) ); else @@ -849,7 +839,6 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d, int sockArgSize; struct ip_mreq mreq4; -#ifndef QT_NO_IPV6 struct ipv6_mreq mreq6; if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) { @@ -862,7 +851,7 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d, memcpy(&mreq6.ipv6mr_multiaddr, &ip6, sizeof(ip6)); mreq6.ipv6mr_interface = iface.index(); } else -#endif + if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) { level = IPPROTO_IP; sockOpt = how4; @@ -904,11 +893,7 @@ bool QNativeSocketEnginePrivate::nativeJoinMulticastGroup(const QHostAddress &gr const QNetworkInterface &iface) { return multicastMembershipHelper(this, -#ifndef QT_NO_IPV6 IPV6_JOIN_GROUP, -#else - 0, -#endif IP_ADD_MEMBERSHIP, groupAddress, iface); @@ -918,11 +903,7 @@ bool QNativeSocketEnginePrivate::nativeLeaveMulticastGroup(const QHostAddress &g const QNetworkInterface &iface) { return multicastMembershipHelper(this, -#ifndef QT_NO_IPV6 IPV6_LEAVE_GROUP, -#else - 0, -#endif IP_DROP_MEMBERSHIP, groupAddress, iface); @@ -930,7 +911,6 @@ bool QNativeSocketEnginePrivate::nativeLeaveMulticastGroup(const QHostAddress &g QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const { -#ifndef QT_NO_IPV6 if (socketProtocol == QAbstractSocket::IPv6Protocol) { uint v; QT_SOCKOPTLEN_T sizeofv = sizeof(v); @@ -938,7 +918,6 @@ QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const return QNetworkInterface(); return QNetworkInterface::interfaceFromIndex(v); } -#endif struct in_addr v; v.s_addr = 0; @@ -965,12 +944,11 @@ QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const bool QNativeSocketEnginePrivate::nativeSetMulticastInterface(const QNetworkInterface &iface) { -#ifndef QT_NO_IPV6 + if (socketProtocol == QAbstractSocket::IPv6Protocol) { uint v = iface.isValid() ? iface.index() : 0; return (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (char *) &v, sizeof(v)) != -1); } -#endif struct in_addr v; if (iface.isValid()) { diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp index 6bc93dd7f0..009ce92d8e 100644 --- a/src/network/socket/qudpsocket.cpp +++ b/src/network/socket/qudpsocket.cpp @@ -192,15 +192,6 @@ bool QUdpSocketPrivate::doEnsureInitialized(const QHostAddress &bindAddress, qui proto = address->protocol(); } -#if defined(QT_NO_IPV6) - Q_Q(QUdpSocket); - if (proto == QUdpSocket::IPv6Protocol) { - socketError = QUdpSocket::UnsupportedSocketOperationError; - q->setErrorString(QUdpSocket::tr("This platform does not support IPv6")); - return false; - } -#endif - // now check if the socket engine is initialized and to the right type if (!socketEngine || !socketEngine->isValid()) { resolveProxy(remoteAddress.toString(), bindPort); diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 6100c68a2d..7403590f8c 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -307,6 +307,9 @@ static QString _q_SubjectInfoToString(QSslCertificate::SubjectInfo info) case QSslCertificate::OrganizationalUnitName: str = QLatin1String("OU"); break; case QSslCertificate::CountryName: str = QLatin1String("C"); break; case QSslCertificate::StateOrProvinceName: str = QLatin1String("ST"); break; + case QSslCertificate::DistinguishedNameQualifier: str = QLatin1String("dnQualifier"); break; + case QSslCertificate::SerialNumber: str = QLatin1String("serialNumber"); break; + case QSslCertificate::EmailAddress: str = QLatin1String("emailAddress"); break; } return str; } @@ -320,14 +323,14 @@ static QString _q_SubjectInfoToString(QSslCertificate::SubjectInfo info) \sa subjectInfo() */ -QString QSslCertificate::issuerInfo(SubjectInfo info) const +QStringList QSslCertificate::issuerInfo(SubjectInfo info) const { // lazy init if (d->issuerInfo.isEmpty() && d->x509) d->issuerInfo = _q_mapFromX509Name(q_X509_get_issuer_name(d->x509)); - return d->issuerInfo.value(_q_SubjectInfoToString(info)); + return d->issuerInfo.values(_q_SubjectInfoToString(info)); } /*! @@ -337,14 +340,14 @@ QString QSslCertificate::issuerInfo(SubjectInfo info) const \sa subjectInfo() */ -QString QSslCertificate::issuerInfo(const QByteArray &tag) const +QStringList QSslCertificate::issuerInfo(const QByteArray &tag) const { // lazy init if (d->issuerInfo.isEmpty() && d->x509) d->issuerInfo = _q_mapFromX509Name(q_X509_get_issuer_name(d->x509)); - return d->issuerInfo.value(QString::fromLatin1(tag)); + return d->issuerInfo.values(QString::fromLatin1(tag)); } /*! @@ -356,14 +359,14 @@ QString QSslCertificate::issuerInfo(const QByteArray &tag) const \sa issuerInfo() */ -QString QSslCertificate::subjectInfo(SubjectInfo info) const +QStringList QSslCertificate::subjectInfo(SubjectInfo info) const { // lazy init if (d->subjectInfo.isEmpty() && d->x509) d->subjectInfo = _q_mapFromX509Name(q_X509_get_subject_name(d->x509)); - return d->subjectInfo.value(_q_SubjectInfoToString(info)); + return d->subjectInfo.values(_q_SubjectInfoToString(info)); } /*! @@ -372,14 +375,14 @@ QString QSslCertificate::subjectInfo(SubjectInfo info) const \sa issuerInfo() */ -QString QSslCertificate::subjectInfo(const QByteArray &tag) const +QStringList QSslCertificate::subjectInfo(const QByteArray &tag) const { // lazy init if (d->subjectInfo.isEmpty() && d->x509) d->subjectInfo = _q_mapFromX509Name(q_X509_get_subject_name(d->x509)); - return d->subjectInfo.value(QString::fromLatin1(tag)); + return d->subjectInfo.values(QString::fromLatin1(tag)); } /*! @@ -711,7 +714,7 @@ static QMap<QString, QString> _q_mapFromX509Name(X509_NAME *name) const char *obj = q_OBJ_nid2sn(q_OBJ_obj2nid(q_X509_NAME_ENTRY_get_object(e))); unsigned char *data = 0; int size = q_ASN1_STRING_to_UTF8(&data, q_X509_NAME_ENTRY_get_data(e)); - info[QString::fromUtf8(obj)] = QString::fromUtf8((char*)data, size); + info.insertMulti(QString::fromUtf8(obj), QString::fromUtf8((char*)data, size)); q_CRYPTO_free(data); } return info; @@ -867,6 +870,9 @@ QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo info) case QSslCertificate::LocalityName: debug << "LocalityName"; break; case QSslCertificate::OrganizationalUnitName: debug << "OrganizationalUnitName"; break; case QSslCertificate::StateOrProvinceName: debug << "StateOrProvinceName"; break; + case QSslCertificate::DistinguishedNameQualifier: debug << "DistinguishedNameQualifier"; break; + case QSslCertificate::SerialNumber: debug << "SerialNumber"; break; + case QSslCertificate::EmailAddress: debug << "EmailAddress"; break; } return debug; } diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h index b942bd8a25..8abaa3f73e 100644 --- a/src/network/ssl/qsslcertificate.h +++ b/src/network/ssl/qsslcertificate.h @@ -76,7 +76,10 @@ public: LocalityName, OrganizationalUnitName, CountryName, - StateOrProvinceName + StateOrProvinceName, + DistinguishedNameQualifier, + SerialNumber, + EmailAddress }; QSslCertificate(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem); @@ -96,10 +99,10 @@ public: QByteArray version() const; QByteArray serialNumber() const; QByteArray digest(QCryptographicHash::Algorithm algorithm = QCryptographicHash::Md5) const; - QString issuerInfo(SubjectInfo info) const; - QString issuerInfo(const QByteArray &tag) const; - QString subjectInfo(SubjectInfo info) const; - QString subjectInfo(const QByteArray &tag) const; + QStringList issuerInfo(SubjectInfo info) const; + QStringList issuerInfo(const QByteArray &tag) const; + QStringList subjectInfo(SubjectInfo info) const; + QStringList subjectInfo(const QByteArray &tag) const; QMultiMap<QSsl::AlternateNameEntryType, QString> alternateSubjectNames() const; QDateTime effectiveDate() const; QDateTime expiryDate() const; diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index df61fb6c18..f191ed9324 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -405,7 +405,7 @@ QSslSocket::~QSslSocket() \sa connectToHost(), startClientEncryption(), waitForConnected(), waitForEncrypted() */ -void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode) +void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode, NetworkLayerProtocol protocol) { Q_D(QSslSocket); if (d->state == ConnectedState || d->state == ConnectingState) { @@ -419,7 +419,7 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, O // Note: When connecting to localhost, some platforms (e.g., HP-UX and some BSDs) // establish the connection immediately (i.e., first attempt). - connectToHost(hostName, port, mode); + connectToHost(hostName, port, mode, protocol); } /*! @@ -434,7 +434,8 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, O \sa connectToHostEncrypted() */ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, - const QString &sslPeerName, OpenMode mode) + const QString &sslPeerName, OpenMode mode, + NetworkLayerProtocol protocol) { Q_D(QSslSocket); if (d->state == ConnectedState || d->state == ConnectingState) { @@ -449,7 +450,7 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, // Note: When connecting to localhost, some platforms (e.g., HP-UX and some BSDs) // establish the connection immediately (i.e., first attempt). - connectToHost(hostName, port, mode); + connectToHost(hostName, port, mode, protocol); } /*! @@ -1740,7 +1741,7 @@ void QSslSocket::connectToHostImplementation(const QString &hostName, quint16 po d->plainSocket->setProperty("_q_user-agent", property("_q_user-agent")); #endif QIODevice::open(openMode); - d->plainSocket->connectToHost(hostName, port, openMode); + d->plainSocket->connectToHost(hostName, port, openMode, d->preferredNetworkLayerProtocol); d->cachedSocketDescriptor = d->plainSocket->socketDescriptor(); } diff --git a/src/network/ssl/qsslsocket.h b/src/network/ssl/qsslsocket.h index 1e7c67ce91..f175ffd946 100644 --- a/src/network/ssl/qsslsocket.h +++ b/src/network/ssl/qsslsocket.h @@ -85,8 +85,8 @@ public: ~QSslSocket(); // Autostarting the SSL client handshake. - void connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode = ReadWrite); - void connectToHostEncrypted(const QString &hostName, quint16 port, const QString &sslPeerName, OpenMode mode = ReadWrite); + void connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol); + void connectToHostEncrypted(const QString &hostName, quint16 port, const QString &sslPeerName, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol); bool setSocketDescriptor(int socketDescriptor, SocketState state = ConnectedState, OpenMode openMode = ReadWrite); diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index fb41b7c9e9..479a6bd60e 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -420,7 +420,11 @@ init_context: QByteArray ace = QUrl::toAce(tlsHostName); // only send the SNI header if the URL is valid and not an IP if (!ace.isEmpty() && !QHostAddress().setAddress(tlsHostName)) { +#if OPENSSL_VERSION_NUMBER >= 0x10000000L + if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.data())) +#else if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.constData())) +#endif qWarning("could not set SSL_CTRL_SET_TLSEXT_HOSTNAME, Server Name Indication disabled"); } } @@ -1262,10 +1266,17 @@ bool QSslSocketBackendPrivate::startHandshake() // if we're the server, don't check CN if (mode == QSslSocket::SslClientMode) { QString peerName = (verificationPeerName.isEmpty () ? q->peerName() : verificationPeerName); - QString commonName = configuration.peerCertificate.subjectInfo(QSslCertificate::CommonName); + QStringList commonNameList = configuration.peerCertificate.subjectInfo(QSslCertificate::CommonName); + bool matched = false; + + foreach (const QString &commonName, commonNameList) { + if (isMatchingHostname(commonName.toLower(), peerName.toLower())) { + matched = true; + break; + } + } - if (!isMatchingHostname(commonName.toLower(), peerName.toLower())) { - bool matched = false; + if (!matched) { foreach (const QString &altName, configuration.peerCertificate .alternateSubjectNames().values(QSsl::DnsEntry)) { if (isMatchingHostname(altName.toLower(), peerName.toLower())) { @@ -1273,15 +1284,15 @@ bool QSslSocketBackendPrivate::startHandshake() break; } } + } - if (!matched) { - // No matches in common names or alternate names. - QSslError error(QSslError::HostNameMismatch, configuration.peerCertificate); - errors << error; - emit q->peerVerifyError(error); - if (q->state() != QAbstractSocket::ConnectedState) - return false; - } + if (!matched) { + // No matches in common names or alternate names. + QSslError error(QSslError::HostNameMismatch, configuration.peerCertificate); + errors << error; + emit q->peerVerifyError(error); + if (q->state() != QAbstractSocket::ConnectedState) + return false; } } } else { diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index 6d29b294a1..b652833b45 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -210,8 +210,12 @@ DEFINEFUNC(int, SSL_library_init, void, DUMMYARG, return -1, return) DEFINEFUNC(void, SSL_load_error_strings, void, DUMMYARG, return, DUMMYARG) DEFINEFUNC(SSL *, SSL_new, SSL_CTX *a, a, return 0, return) #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT) +#if OPENSSL_VERSION_NUMBER >= 0x10000000L +DEFINEFUNC4(long, SSL_ctrl, SSL *a, a, int cmd, cmd, long larg, larg, void *parg, parg, return -1, return) +#else DEFINEFUNC4(long, SSL_ctrl, SSL *a, a, int cmd, cmd, long larg, larg, const void *parg, parg, return -1, return) #endif +#endif DEFINEFUNC3(int, SSL_read, SSL *a, a, void *b, b, int c, c, return -1, return) DEFINEFUNC3(void, SSL_set_bio, SSL *a, a, BIO *b, b, BIO *c, c, return, DUMMYARG) DEFINEFUNC(void, SSL_set_accept_state, SSL *a, a, return, DUMMYARG) diff --git a/src/network/ssl/qsslsocket_openssl_symbols_p.h b/src/network/ssl/qsslsocket_openssl_symbols_p.h index 00f56d65af..658aa144a7 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols_p.h +++ b/src/network/ssl/qsslsocket_openssl_symbols_p.h @@ -318,8 +318,12 @@ int q_SSL_library_init(); void q_SSL_load_error_strings(); SSL *q_SSL_new(SSL_CTX *a); #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT) +#if OPENSSL_VERSION_NUMBER >= 0x10000000L +long q_SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg); +#else long q_SSL_ctrl(SSL *ssl,int cmd, long larg, const void *parg); #endif +#endif int q_SSL_read(SSL *a, void *b, int c); void q_SSL_set_bio(SSL *a, BIO *b, BIO *c); void q_SSL_set_accept_state(SSL *a); |