From d6a24fd24597af8cdff5944d32a54acb01b806f3 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 15 Sep 2014 17:07:33 +0200 Subject: Make QWebSocketPrivate::makeConnections() take care of all connections. Otherwise all code that calls it has to handle the other connections separately, which is error-prone and has actually been forgotten for the case where the QWebSocket is created via upgradeFrom(). Task-number: QTBUG-39551 Change-Id: I4d1e4faa1594b53e7a8dccc9ce13ef2c323b1c61 Reviewed-by: Kurt Pattyn --- src/websockets/qwebsocket_p.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index 1932aeb..5b37a27 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -392,12 +392,6 @@ void QWebSocketPrivate::open(const QUrl &url, bool mask) m_pSocket->setPauseMode(m_pauseMode); makeConnections(m_pSocket.data()); - QObject::connect(sslSocket, &QSslSocket::encryptedBytesWritten, q, - &QWebSocket::bytesWritten); - typedef void (QSslSocket:: *sslErrorSignalType)(const QList &); - QObject::connect(sslSocket, - static_cast(&QSslSocket::sslErrors), - q, &QWebSocket::sslErrors); setSocketState(QAbstractSocket::ConnectingState); sslSocket->setSslConfiguration(m_configuration.m_sslConfiguration); @@ -426,8 +420,6 @@ void QWebSocketPrivate::open(const QUrl &url, bool mask) m_pSocket->setPauseMode(m_pauseMode); makeConnections(m_pSocket.data()); - QObject::connect(m_pSocket.data(), &QAbstractSocket::bytesWritten, q, - &QWebSocket::bytesWritten); setSocketState(QAbstractSocket::ConnectingState); #ifndef QT_NO_NETWORKPROXY m_pSocket->setProxy(m_configuration.m_proxy); @@ -545,7 +537,7 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket) #ifndef QT_NO_NETWORKPROXY QObject::connect(pTcpSocket, &QAbstractSocket::proxyAuthenticationRequired, q, &QWebSocket::proxyAuthenticationRequired); -#endif +#endif // QT_NO_NETWORKPROXY QObject::connect(pTcpSocket, &QAbstractSocket::readChannelFinished, q, &QWebSocket::readChannelFinished); QObject::connect(pTcpSocket, &QAbstractSocket::aboutToClose, q, &QWebSocket::aboutToClose); @@ -557,6 +549,21 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket) //with QTcpSocket there is no problem, but with QSslSocket the processing hangs QObjectPrivate::connect(pTcpSocket, &QAbstractSocket::readyRead, this, &QWebSocketPrivate::processData, Qt::QueuedConnection); +#ifndef QT_NO_SSL + const QSslSocket * const sslSocket = qobject_cast(pTcpSocket); + if (sslSocket) { + QObject::connect(sslSocket, &QSslSocket::encryptedBytesWritten, q, + &QWebSocket::bytesWritten); + typedef void (QSslSocket:: *sslErrorSignalType)(const QList &); + QObject::connect(sslSocket, + static_cast(&QSslSocket::sslErrors), + q, &QWebSocket::sslErrors); + } else +#endif // QT_NO_SSL + { + QObject::connect(pTcpSocket, &QAbstractSocket::bytesWritten, q, + &QWebSocket::bytesWritten); + } } QObject::connect(&m_dataProcessor, &QWebSocketDataProcessor::textFrameReceived, q, -- cgit v1.2.1 From 7aeea581882425be657123d2945c7165c7063aab Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Tue, 19 Aug 2014 15:35:57 +0300 Subject: Fix invalid Date header field in handshake response Fix invalid Date header in handshake response on systems with non- english system locale. Task-number: QTBUG-40866 Change-Id: If6d5cc55e879eff259698e87c9cda753990245e7 Reviewed-by: Kurt Pattyn --- src/websockets/qwebsockethandshakeresponse.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/websockets/qwebsockethandshakeresponse.cpp b/src/websockets/qwebsockethandshakeresponse.cpp index aa9a881..89a947c 100644 --- a/src/websockets/qwebsockethandshakeresponse.cpp +++ b/src/websockets/qwebsockethandshakeresponse.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -186,14 +187,15 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse( } else { if (origin.isEmpty()) origin = QStringLiteral("*"); + QDateTime datetime = QDateTime::currentDateTimeUtc(); response << QStringLiteral("Server: ") % serverName << QStringLiteral("Access-Control-Allow-Credentials: false") << QStringLiteral("Access-Control-Allow-Methods: GET") << QStringLiteral("Access-Control-Allow-Headers: content-type") << QStringLiteral("Access-Control-Allow-Origin: ") % origin << - QStringLiteral("Date: ") % - QDateTime::currentDateTimeUtc() - .toString(QStringLiteral("ddd, dd MMM yyyy hh:mm:ss 'GMT'")); + QStringLiteral("Date: ") % QLocale::c() + .toString(datetime, QStringLiteral("ddd, dd MMM yyyy hh:mm:ss 'GMT'")); + m_acceptedVersion = QWebSocketProtocol::currentVersion(); m_canUpgrade = true; -- cgit v1.2.1 From 64927e04f202d33b9a9a1f94141ef692c0b513ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Sat, 2 Aug 2014 14:48:32 +0200 Subject: Set parent of internal server objects After moving the websocket server into another thread current code doesn't work because then the QTcpServer/QSslServer objects reside in a different thread: "QWarning: QObject: Cannot create children for a parent that is in a different thread." QObject::moveToThread(QThread*) also moves QObjects's children, therefore the internal server objects need to be children of QWebSocketServer. Change-Id: Ic7e8a564cd87400a4ab7258e3799157ed359c098 Reviewed-by: Liang Qi Reviewed-by: Alex Blasche --- src/websockets/qwebsocketserver.cpp | 2 ++ src/websockets/qwebsocketserver_p.cpp | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/websockets/qwebsocketserver.cpp b/src/websockets/qwebsocketserver.cpp index 59cfd89..b7368b3 100644 --- a/src/websockets/qwebsocketserver.cpp +++ b/src/websockets/qwebsocketserver.cpp @@ -247,6 +247,8 @@ QWebSocketServer::QWebSocketServer(const QString &serverName, SslMode secureMode */ QWebSocketServer::~QWebSocketServer() { + Q_D(QWebSocketServer); + d->close(true); } /*! diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp index 28f9bea..77caa51 100644 --- a/src/websockets/qwebsocketserver_p.cpp +++ b/src/websockets/qwebsocketserver_p.cpp @@ -74,7 +74,7 @@ QWebSocketServerPrivate::QWebSocketServerPrivate(const QString &serverName, void QWebSocketServerPrivate::init() { if (m_secureMode == NonSecureMode) { - m_pTcpServer = new QTcpServer(); + m_pTcpServer = new QTcpServer(q_ptr); if (Q_LIKELY(m_pTcpServer)) QObjectPrivate::connect(m_pTcpServer, &QTcpServer::newConnection, this, &QWebSocketServerPrivate::onNewConnection); @@ -82,7 +82,7 @@ void QWebSocketServerPrivate::init() qFatal("Could not allocate memory for tcp server."); } else { #ifndef QT_NO_SSL - QSslServer *pSslServer = new QSslServer(); + QSslServer *pSslServer = new QSslServer(q_ptr); m_pTcpServer = pSslServer; if (Q_LIKELY(m_pTcpServer)) { QObjectPrivate::connect(pSslServer, &QSslServer::newEncryptedConnection, @@ -105,8 +105,6 @@ void QWebSocketServerPrivate::init() */ QWebSocketServerPrivate::~QWebSocketServerPrivate() { - close(true); - m_pTcpServer->deleteLater(); } /*! -- cgit v1.2.1