diff --git a/dist/changes-5.6.3 b/dist/changes-5.6.3 new file mode 100644 index 0000000000000000000000000000000000000000..dc731870b82e7a76a285909e548ad62677dd3dd2 --- /dev/null +++ b/dist/changes-5.6.3 @@ -0,0 +1,24 @@ +Qt 5.6.3 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.6.0. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + + http://doc.qt.io/qt-5/index.html + +The Qt version 5.6 series is binary compatible with the 5.5.x series. +Applications compiled for 5.5 will continue to run with 5.6. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + + https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* Library * +**************************************************************************** +- QWebSocketHandshakeRequest + [QTBUG-57357] Fixed the parsing of port in handshake requests. diff --git a/dist/changes-5.9.2 b/dist/changes-5.9.2 new file mode 100644 index 0000000000000000000000000000000000000000..83b029956279ce42fbd136d09a9d896f0b087842 --- /dev/null +++ b/dist/changes-5.9.2 @@ -0,0 +1,18 @@ +Qt 5.9.2 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.9.0. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +http://doc.qt.io/qt-5/index.html + +The Qt version 5.9 series is binary compatible with the 5.8.x series. +Applications compiled for 5.8 will continue to run with 5.9. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. diff --git a/examples/websockets/simplechat/chatclient.html b/examples/websockets/simplechat/chatclient.html index 511d05b17a917c72d31cd63d2719b037046bf9c9..d2dbf47ffd6181a09b98fa49fe3218f14cb927e8 100644 --- a/examples/websockets/simplechat/chatclient.html +++ b/examples/websockets/simplechat/chatclient.html @@ -4,18 +4,21 @@ </head> <body> <h1>WebSocket Chat Client</h1> + <p> + Host: <input id="webSocketHost" type="text" value="localhost:1234"/> + </p> <p> <button onClick="initWebSocket();">Connect</button> - <button onClick="stopWebSocket();">Disconnect</button> + <button id="disconnectButton" onClick="stopWebSocket();" disabled>Disconnect</button> <button onClick="checkSocket();">State</button> </p> <p> - <textarea id="debugTextArea" style="width:400px;height:200px;"></textarea> + <textarea id="debugTextArea" style="width:400px;height:200px;" readonly></textarea> </p> <p> <input type="text" id="inputNick" value="nickname" /> <input type="text" id="inputText" onkeydown="if(event.keyCode==13)sendMessage();"/> - <button onClick="sendMessage();">Send</button> + <button id="sendButton" onClick="sendMessage();" disabled>Send</button> </p> <script type="text/javascript"> @@ -38,7 +41,6 @@ } } - var wsUri = "ws://localhost:1234"; var websocket = null; function initWebSocket() { @@ -47,12 +49,17 @@ WebSocket = MozWebSocket; if ( websocket && websocket.readyState == 1 ) websocket.close(); + var wsUri = "ws://" + document.getElementById("webSocketHost").value; websocket = new WebSocket( wsUri ); websocket.onopen = function (evt) { debug("CONNECTED"); + document.getElementById("disconnectButton").disabled = false; + document.getElementById("sendButton").disabled = false; }; websocket.onclose = function (evt) { debug("DISCONNECTED"); + document.getElementById("disconnectButton").disabled = true; + document.getElementById("sendButton").disabled = true; }; websocket.onmessage = function (evt) { console.log( "Message received :", evt.data ); diff --git a/examples/websockets/simplechat/chatserver.cpp b/examples/websockets/simplechat/chatserver.cpp index 50d262539067544367255315c5ea4c66aed6f65c..8885fe838aa120f9b5fd2fb2ad69ff4e32a2a110 100644 --- a/examples/websockets/simplechat/chatserver.cpp +++ b/examples/websockets/simplechat/chatserver.cpp @@ -48,23 +48,31 @@ ** ****************************************************************************/ #include "chatserver.h" -#include "QtWebSockets/QWebSocketServer" -#include "QtWebSockets/QWebSocket" -#include <QtCore/QDebug> + +#include <QtWebSockets> +#include <QtCore> + +#include <cstdio> +using namespace std; QT_USE_NAMESPACE +static QString getIdentifier(QWebSocket *peer) +{ + return QStringLiteral("%1:%2").arg(peer->peerAddress().toString(), + QString::number(peer->peerPort())); +} + //! [constructor] ChatServer::ChatServer(quint16 port, QObject *parent) : QObject(parent), - m_pWebSocketServer(nullptr) + m_pWebSocketServer(new QWebSocketServer(QStringLiteral("Chat Server"), + QWebSocketServer::NonSecureMode, + this)) { - m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Chat Server"), - QWebSocketServer::NonSecureMode, - this); if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { - qDebug() << "Chat Server listening on port" << port; + QTextStream(stdout) << "Chat Server listening on port " << port << '\n'; connect(m_pWebSocketServer, &QWebSocketServer::newConnection, this, &ChatServer::onNewConnection); } @@ -73,31 +81,32 @@ ChatServer::ChatServer(quint16 port, QObject *parent) : ChatServer::~ChatServer() { m_pWebSocketServer->close(); - qDeleteAll(m_clients.begin(), m_clients.end()); } //! [constructor] //! [onNewConnection] void ChatServer::onNewConnection() { - QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); + auto pSocket = m_pWebSocketServer->nextPendingConnection(); + QTextStream(stdout) << getIdentifier(pSocket) << " connected!\n"; + pSocket->setParent(this); - connect(pSocket, &QWebSocket::textMessageReceived, this, &ChatServer::processMessage); - connect(pSocket, &QWebSocket::disconnected, this, &ChatServer::socketDisconnected); + connect(pSocket, &QWebSocket::textMessageReceived, + this, &ChatServer::processMessage); + connect(pSocket, &QWebSocket::disconnected, + this, &ChatServer::socketDisconnected); m_clients << pSocket; } //! [onNewConnection] //! [processMessage] -void ChatServer::processMessage(QString message) +void ChatServer::processMessage(const QString &message) { QWebSocket *pSender = qobject_cast<QWebSocket *>(sender()); for (QWebSocket *pClient : qAsConst(m_clients)) { if (pClient != pSender) //don't echo message back to sender - { pClient->sendTextMessage(message); - } } } //! [processMessage] @@ -106,6 +115,7 @@ void ChatServer::processMessage(QString message) void ChatServer::socketDisconnected() { QWebSocket *pClient = qobject_cast<QWebSocket *>(sender()); + QTextStream(stdout) << getIdentifier(pClient) << " disconnected!\n"; if (pClient) { m_clients.removeAll(pClient); diff --git a/examples/websockets/simplechat/chatserver.h b/examples/websockets/simplechat/chatserver.h index 43ce306c020d874254f712256650ed9eed54446f..4a8285b055292735f1f329246b8d5a900683df72 100644 --- a/examples/websockets/simplechat/chatserver.h +++ b/examples/websockets/simplechat/chatserver.h @@ -52,10 +52,10 @@ #include <QtCore/QObject> #include <QtCore/QList> -#include <QtCore/QByteArray> QT_FORWARD_DECLARE_CLASS(QWebSocketServer) QT_FORWARD_DECLARE_CLASS(QWebSocket) +QT_FORWARD_DECLARE_CLASS(QString) class ChatServer : public QObject { @@ -64,9 +64,9 @@ public: explicit ChatServer(quint16 port, QObject *parent = nullptr); virtual ~ChatServer(); -private Q_SLOTS: +private slots: void onNewConnection(); - void processMessage(QString message); + void processMessage(const QString &message); void socketDisconnected(); private: diff --git a/examples/websockets/simplechat/main.cpp b/examples/websockets/simplechat/main.cpp index 0b1c753387e0c0e9b4cb944e7177c6f0bd692de9..a1ffb4926c2d32d9e09d9a38cef962b74c4531f0 100644 --- a/examples/websockets/simplechat/main.cpp +++ b/examples/websockets/simplechat/main.cpp @@ -48,6 +48,7 @@ ** ****************************************************************************/ #include <QtCore/QCoreApplication> + #include "chatserver.h" int main(int argc, char *argv[]) diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.h b/src/imports/qmlwebsockets/qqmlwebsocket.h index c3a808fee3f30ea4ef188b2f63a6212a3cedc28b..8db435d536823175311c2465e60ad173a492eeaa 100644 --- a/src/imports/qmlwebsockets/qqmlwebsocket.h +++ b/src/imports/qmlwebsockets/qqmlwebsocket.h @@ -54,7 +54,6 @@ class QQmlWebSocket : public QObject, public QQmlParserStatus Q_DISABLE_COPY(QQmlWebSocket) Q_INTERFACES(QQmlParserStatus) - Q_ENUMS(Status) Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) @@ -73,6 +72,7 @@ public: Closed = 3, Error = 4 }; + Q_ENUM(Status) QUrl url() const; void setUrl(const QUrl &url); diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index 52538040310cf0058d856c8c886189ebb8e7acc7..5e1a10321b98cf84f772664b2de402ff581f1917 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -633,7 +633,7 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket) void QWebSocketPrivate::releaseConnections(const QTcpSocket *pTcpSocket) { if (Q_LIKELY(pTcpSocket)) - pTcpSocket->disconnect(pTcpSocket); + pTcpSocket->disconnect(); m_dataProcessor.disconnect(); } @@ -1011,7 +1011,7 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket) if (!ok) errorDescription = QWebSocket::tr("Accept-Key received from server %1 does not match the client key %2.") - .arg(acceptKey).arg(accept); + .arg(acceptKey, accept); } else { errorDescription = QWebSocket::tr("QWebSocketPrivate::processHandshake: Invalid statusline in response: %1.") @@ -1145,7 +1145,8 @@ void QWebSocketPrivate::socketDestroyed(QObject *socket) */ void QWebSocketPrivate::processData() { - Q_ASSERT(m_pSocket); + if (!m_pSocket) // disconnected with data still in-bound + return; while (m_pSocket->bytesAvailable()) { if (state() == QAbstractSocket::ConnectingState) { if (!m_pSocket->canReadLine()) diff --git a/src/websockets/qwebsockethandshakerequest.cpp b/src/websockets/qwebsockethandshakerequest.cpp index ddeee2d24ec94710f4f6c58dd590689da94f68a8..e6a626c266c5c43f0f74c762b12b7ee38ec94d0f 100644 --- a/src/websockets/qwebsockethandshakerequest.cpp +++ b/src/websockets/qwebsockethandshakerequest.cpp @@ -318,17 +318,17 @@ void QWebSocketHandshakeRequest::readHandshake(QTextStream &textStream, int maxH //optional headers m_origin = m_headers.value(QStringLiteral("origin"), QString()); const QStringList protocolLines = m_headers.values(QStringLiteral("sec-websocket-protocol")); - for (QStringList::const_iterator pl = protocolLines.begin(); pl != protocolLines.end(); ++pl) { - QStringList protocols = (*pl).split(QStringLiteral(","), QString::SkipEmptyParts); - for (QStringList::const_iterator p = protocols.begin(); p != protocols.end(); ++p) - m_protocols << (*p).trimmed(); + for (const QString& pl : protocolLines) { + const QStringList protocols = pl.split(QStringLiteral(","), QString::SkipEmptyParts); + for (const QString& p : protocols) + m_protocols << p.trimmed(); } + const QStringList extensionLines = m_headers.values(QStringLiteral("sec-websocket-extensions")); - for (QStringList::const_iterator el = extensionLines.begin(); - el != extensionLines.end(); ++el) { - QStringList extensions = (*el).split(QStringLiteral(","), QString::SkipEmptyParts); - for (QStringList::const_iterator e = extensions.begin(); e != extensions.end(); ++e) - m_extensions << (*e).trimmed(); + for (const QString& el : extensionLines) { + const QStringList extensions = el.split(QStringLiteral(","), QString::SkipEmptyParts); + for (const QString& e : extensions) + m_extensions << e.trimmed(); } //TODO: authentication field diff --git a/src/websockets/qwebsocketserver.h b/src/websockets/qwebsocketserver.h index 8a78c57f740d95ec54b6507d392acabec5845c6a..decd7c35d34f70b17acf4391255aef068e8ebb4a 100644 --- a/src/websockets/qwebsocketserver.h +++ b/src/websockets/qwebsocketserver.h @@ -65,8 +65,6 @@ class Q_WEBSOCKETS_EXPORT QWebSocketServer : public QObject Q_DISABLE_COPY(QWebSocketServer) Q_DECLARE_PRIVATE(QWebSocketServer) - Q_ENUMS(SslMode) - public: enum SslMode { #ifndef QT_NO_SSL @@ -74,6 +72,7 @@ public: #endif NonSecureMode = 1 }; + Q_ENUM(SslMode) explicit QWebSocketServer(const QString &serverName, SslMode secureMode, QObject *parent = nullptr);