aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-10-11 20:17:45 +0200
committerLiang Qi <liang.qi@qt.io>2017-10-11 20:17:45 +0200
commit825df0cef516fb84adab88a31106e214f2b29b2d (patch)
treee6e7fb12b1c77faa65df20106c8bf342a410b690
parent75042d31d1d267d0a4091932c95579747a102e9d (diff)
parentcd26439ac7ca1a444e9b5534a504afb0bb411890 (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: examples/websockets/simplechat/chatserver.cpp Change-Id: I98697cef4c05516b5b4122ad81c084546d57115f
-rw-r--r--dist/changes-5.6.324
-rw-r--r--dist/changes-5.9.218
-rw-r--r--examples/websockets/simplechat/chatclient.html15
-rw-r--r--examples/websockets/simplechat/chatserver.cpp40
-rw-r--r--examples/websockets/simplechat/chatserver.h6
-rw-r--r--examples/websockets/simplechat/main.cpp1
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.h2
-rw-r--r--src/websockets/qwebsocket_p.cpp7
-rw-r--r--src/websockets/qwebsockethandshakerequest.cpp18
-rw-r--r--src/websockets/qwebsocketserver.h3
10 files changed, 97 insertions, 37 deletions
diff --git a/dist/changes-5.6.3 b/dist/changes-5.6.3
new file mode 100644
index 0000000..dc73187
--- /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 0000000..83b0299
--- /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 511d05b..d2dbf47 100644
--- a/examples/websockets/simplechat/chatclient.html
+++ b/examples/websockets/simplechat/chatclient.html
@@ -5,17 +5,20 @@
<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 50d2625..8885fe8 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 43ce306..4a8285b 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 0b1c753..a1ffb49 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 c3a808f..8db435d 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 5253804..5e1a103 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 ddeee2d..e6a626c 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 8a78c57..decd7c3 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);