├── .tag ├── qtwebsockets.pro ├── examples ├── examples.pro ├── websockets │ ├── doc │ │ ├── images │ │ │ ├── echoclient-html-example.png │ │ │ ├── simplechat-html-example.webp │ │ │ ├── echoclient-console-example.webp │ │ │ ├── qmlwebsocketclient-example.webp │ │ │ ├── qmlwebsocketserver-example.webp │ │ │ ├── sslechoclient-html-example.webp │ │ │ └── sslechoclient-console-example.webp │ │ ├── examples.qdoc │ │ ├── qmlwebsocketserver.qdoc │ │ ├── echoserver.qdoc │ │ ├── echoclient.qdoc │ │ ├── sslechoclient.qdoc │ │ ├── simplechat.qdoc │ │ ├── sslechoserver.qdoc │ │ └── qmlwebsocketclient.qdoc │ ├── qmlwebsocketclient │ │ ├── data.qrc │ │ ├── qmlwebsocketclient.pro │ │ ├── main.cpp │ │ ├── CMakeLists.txt │ │ └── qml │ │ │ └── qmlwebsocketclient │ │ │ └── main.qml │ ├── qmlwebsocketserver │ │ ├── data.qrc │ │ ├── qmlwebsocketserver.pro │ │ ├── main.cpp │ │ ├── CMakeLists.txt │ │ └── qml │ │ │ └── qmlwebsocketserver │ │ │ └── main.qml │ ├── sslechoserver │ │ ├── securesocketclient.qrc │ │ ├── generate.sh │ │ ├── main.cpp │ │ ├── sslechoserver.pro │ │ ├── sslechoserver.h │ │ ├── CMakeLists.txt │ │ ├── localhost.cert │ │ ├── localhost.key │ │ ├── sslechoserver.cpp │ │ └── sslechoclient.html │ ├── websockets.pro │ ├── simplechat │ │ ├── main.cpp │ │ ├── simplechat.pro │ │ ├── chatserver.h │ │ ├── CMakeLists.txt │ │ └── chatserver.cpp │ ├── echoclient │ │ ├── echoclient.pro │ │ ├── echoclient.h │ │ ├── CMakeLists.txt │ │ ├── echoclient.cpp │ │ └── main.cpp │ ├── echoserver │ │ ├── echoserver.pro │ │ ├── echoserver.h │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── echoserver.cpp │ │ └── echoclient.html │ ├── sslechoclient │ │ ├── sslechoclient.pro │ │ ├── sslechoclient.h │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── sslechoclient.cpp │ └── CMakeLists.txt └── CMakeLists.txt ├── .gitreview ├── tests ├── manual │ ├── manual.pro │ ├── compliance │ │ ├── compliance.pro │ │ └── tst_compliance.cpp │ └── websockets │ │ └── websockets.pro ├── auto │ ├── websockets │ │ ├── qwebsocketserver │ │ │ ├── BLACKLIST │ │ │ └── CMakeLists.txt │ │ ├── CMakeLists.txt │ │ ├── qwebsocketcorsauthenticator │ │ │ ├── CMakeLists.txt │ │ │ └── tst_qwebsocketcorsauthenticator.cpp │ │ ├── dataprocessor │ │ │ └── CMakeLists.txt │ │ ├── websocketframe │ │ │ └── CMakeLists.txt │ │ ├── websocketprotocol │ │ │ └── CMakeLists.txt │ │ ├── qdefaultmaskgenerator │ │ │ ├── CMakeLists.txt │ │ │ └── tst_defaultmaskgenerator.cpp │ │ ├── handshakerequest │ │ │ └── CMakeLists.txt │ │ ├── handshakeresponse │ │ │ ├── CMakeLists.txt │ │ │ └── tst_handshakeresponse.cpp │ │ ├── qwebsocket │ │ │ └── CMakeLists.txt │ │ └── shared │ │ │ ├── localhost.cert │ │ │ ├── localhost.key │ │ │ ├── selfsigned.cert │ │ │ └── selfsigned.key │ ├── qml │ │ ├── CMakeLists.txt │ │ └── qmlwebsockets │ │ │ ├── tst_qmlwebsockets.cpp │ │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ └── cmake │ │ └── CMakeLists.txt ├── global │ └── global.cfg ├── CMakeLists.txt └── doc │ └── README.qdocinc ├── src ├── websockets │ ├── doc │ │ ├── images │ │ │ └── websockets-pictorial-representation.jpg │ │ ├── snippets │ │ │ └── src_websockets_ssl_qwebsocket.cpp │ │ ├── src │ │ │ ├── qtwebsockets-toc.qdoc │ │ │ ├── qt6-changes.qdoc │ │ │ ├── qtwebsockets-module.qdoc │ │ │ ├── external-resources.qdoc │ │ │ ├── index.qdoc │ │ │ └── overview.qdoc │ │ └── qtwebsockets.qdocconf │ ├── qwebsockets_global.h │ ├── qmaskgenerator.h │ ├── qwebsocketcorsauthenticator_p.h │ ├── qwebsockethandshakeoptions_p.h │ ├── qdefaultmaskgenerator_p.h │ ├── qwebsocketcorsauthenticator.h │ ├── qwebsocketprotocol.h │ ├── CMakeLists.txt │ ├── qwebsockethandshakeoptions.h │ ├── qmaskgenerator.cpp │ ├── qwebsockethandshakerequest_p.h │ ├── qdefaultmaskgenerator_p.cpp │ ├── qwebsocketprotocol_p.h │ ├── qwebsockethandshakeresponse_p.h │ ├── qwebsocketframe_p.h │ ├── qwebsocketdataprocessor_p.h │ ├── qwebsockethandshakeoptions.cpp │ └── qwebsocketserver_p.h ├── imports │ ├── CMakeLists.txt │ └── qmlwebsockets │ │ ├── CMakeLists.txt │ │ ├── qqmlwebsocketserver.h │ │ └── qqmlwebsocket.h └── CMakeLists.txt ├── dependencies.yaml ├── .cmake.conf ├── dist ├── REUSE.toml ├── changes-5.9.2 ├── changes-5.13.0 ├── changes-5.8.0 ├── changes-5.12.1 ├── changes-5.13.1 ├── changes-5.14.1 ├── changes-5.15.1 ├── changes-5.11.3 ├── changes-5.12.2 ├── changes-5.12.3 ├── changes-5.12.4 ├── changes-5.12.5 ├── changes-5.13.2 ├── changes-5.14.2 ├── changes-5.10.0 ├── changes-5.11.0 ├── changes-5.9.1 ├── changes-5.9.5 ├── changes-5.11.1 ├── changes-5.15.0 ├── changes-5.9.4 ├── changes-5.9.6 ├── changes-5.11.2 ├── changes-5.6.3 ├── changes-5.10.1 ├── changes-5.9.3 ├── changes-5.15.2 ├── changes-5.14.0 ├── changes-5.7.0 ├── changes-5.12.0 ├── changes-5.9.0 └── changes-5.5.0 ├── LICENSES ├── LicenseRef-Qt-Commercial.txt └── BSD-3-Clause.txt ├── coin ├── module_config.yaml └── axivion │ └── ci_config_linux.json ├── CMakeLists.txt ├── README.md └── REUSE.toml /.tag: -------------------------------------------------------------------------------- 1 | ecf7bc43c93b4edd49e11e342a9beae900bd0680 2 | -------------------------------------------------------------------------------- /qtwebsockets.pro: -------------------------------------------------------------------------------- 1 | requires(qtHaveModule(network)) 2 | load(qt_parts) 3 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS = websockets 4 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=codereview.qt-project.org 3 | project=qt/qtwebsockets 4 | defaultbranch=dev 5 | -------------------------------------------------------------------------------- /tests/manual/manual.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | compliance \ 5 | websockets 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketserver/BLACKLIST: -------------------------------------------------------------------------------- 1 | # QTBUG-102713 2 | [tst_scheme] 3 | android 4 | [tst_handshakeTimeout] 5 | android 6 | -------------------------------------------------------------------------------- /tests/global/global.cfg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/websockets/doc/images/echoclient-html-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/echoclient-html-example.png -------------------------------------------------------------------------------- /examples/websockets/doc/images/simplechat-html-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/simplechat-html-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/echoclient-console-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/echoclient-console-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/qmlwebsocketclient-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/qmlwebsocketclient-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/qmlwebsocketserver-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/qmlwebsocketserver-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/sslechoclient-html-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/sslechoclient-html-example.webp -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/data.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/qmlwebsocketclient/main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/data.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/qmlwebsocketserver/main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/websockets/doc/images/sslechoclient-console-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/examples/websockets/doc/images/sslechoclient-console-example.webp -------------------------------------------------------------------------------- /src/websockets/doc/images/websockets-pictorial-representation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/dev/src/websockets/doc/images/websockets-pictorial-representation.jpg -------------------------------------------------------------------------------- /src/imports/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from imports.pro. 5 | 6 | add_subdirectory(qmlwebsockets) 7 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/securesocketclient.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | localhost.cert 4 | localhost.key 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/auto/qml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qml.pro. 5 | 6 | if(NOT UIKIT) 7 | add_subdirectory(qmlwebsockets) 8 | endif() 9 | -------------------------------------------------------------------------------- /dependencies.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | ../qtbase: 3 | ref: df1292e2b96aab02ad6df778d8336e7958ad5d1c 4 | required: true 5 | ../qtdeclarative: 6 | ref: 7ef1d06ce70fa360613dca0b5ff03365ebbc9883 7 | required: false 8 | -------------------------------------------------------------------------------- /tests/auto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | add_subdirectory(cmake) 5 | add_subdirectory(websockets) 6 | if(TARGET Qt::Quick) 7 | add_subdirectory(qml) 8 | endif() 9 | -------------------------------------------------------------------------------- /tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include 5 | QUICK_TEST_MAIN(qmlwebsockets) 6 | -------------------------------------------------------------------------------- /tests/manual/compliance/compliance.pro: -------------------------------------------------------------------------------- 1 | CONFIG += console 2 | CONFIG += testcase 3 | CONFIG -= app_bundle 4 | 5 | TEMPLATE = app 6 | 7 | TARGET = tst_compliance 8 | 9 | QT = websockets testlib 10 | 11 | SOURCES += tst_compliance.cpp 12 | -------------------------------------------------------------------------------- /tests/manual/websockets/websockets.pro: -------------------------------------------------------------------------------- 1 | CONFIG += console 2 | CONFIG += testcase 3 | CONFIG -= app_bundle 4 | 5 | TEMPLATE = app 6 | 7 | TARGET = tst_websockets 8 | 9 | QT = websockets testlib 10 | 11 | SOURCES += tst_websockets.cpp 12 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | qt_examples_build_begin(EXTERNAL_BUILD) 5 | 6 | add_subdirectory(websockets) 7 | 8 | qt_examples_build_end() 9 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from src.pro. 5 | 6 | add_subdirectory(websockets) 7 | if(TARGET Qt::Quick) 8 | add_subdirectory(imports) 9 | endif() 10 | -------------------------------------------------------------------------------- /.cmake.conf: -------------------------------------------------------------------------------- 1 | set(QT_REPO_MODULE_VERSION "6.12.0") 2 | set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") 3 | set(QT_EXTRA_INTERNAL_TARGET_DEFINES 4 | "QT_NO_FOREACH=1" 5 | "QT_NO_QASCONST=1" 6 | "QT_NO_URL_CAST_FROM_STRING=1" 7 | "QT_USE_NODISCARD_FILE_OPEN=1" 8 | ) 9 | -------------------------------------------------------------------------------- /dist/REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["*"] 5 | precedence = "override" 6 | comment = "Licensed as documentation." 7 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 9 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | # Copyright (C) 2024 The Qt Company Ltd. 3 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 4 | 5 | openssl req -x509 -nodes -newkey rsa:4096 -keyout localhost.key -out localhost.cert -sha512 -days 365 -subj "/C=NO/ST=Oslo/L=Oslo/O=The Qt Project/OU=WebSockets/CN=localhost" 6 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from tests.pro. 5 | 6 | if(QT_BUILD_STANDALONE_TESTS) 7 | # Add qt_find_package calls for extra dependencies that need to be found when building 8 | # the standalone tests here. 9 | endif() 10 | 11 | qt_build_tests() 12 | 13 | -------------------------------------------------------------------------------- /examples/websockets/websockets.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | QT_FOR_CONFIG += network 3 | 4 | SUBDIRS = echoclient \ 5 | echoserver \ 6 | simplechat 7 | 8 | qtHaveModule(quick) { 9 | SUBDIRS += qmlwebsocketclient \ 10 | qmlwebsocketserver 11 | } 12 | 13 | qtConfig(ssl) { 14 | SUBDIRS += \ 15 | sslechoserver \ 16 | sslechoclient 17 | } 18 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/qmlwebsocketclient.pro: -------------------------------------------------------------------------------- 1 | QT += quick websockets 2 | 3 | TARGET = qmlwebsocketclient 4 | 5 | TEMPLATE = app 6 | 7 | CONFIG -= app_bundle 8 | 9 | SOURCES += main.cpp 10 | 11 | RESOURCES += data.qrc 12 | 13 | OTHER_FILES += qml/qmlwebsocketclient/main.qml 14 | 15 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/qmlwebsocketclient 16 | INSTALLS += target 17 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/qmlwebsocketserver.pro: -------------------------------------------------------------------------------- 1 | QT += quick websockets 2 | 3 | TARGET = qmlwebsocketserver 4 | 5 | TEMPLATE = app 6 | 7 | CONFIG -= app_bundle 8 | 9 | SOURCES += main.cpp 10 | 11 | RESOURCES += data.qrc 12 | 13 | OTHER_FILES += qml/qmlwebsocketserver/main.qml 14 | 15 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/qmlwebsocketserver 16 | INSTALLS += target 17 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | 5 | #include "chatserver.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QCoreApplication a(argc, argv); 10 | ChatServer server(1234); 11 | 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /examples/websockets/doc/examples.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | 5 | /*! 6 | \group qtwebsockets-examples 7 | \title Qt WebSockets Examples 8 | \brief List of Qt WebSocket examples 9 | 10 | The examples below can be used as a guide to using the \l{Qt WebSockets} API. 11 | */ 12 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/echoclient.pro: -------------------------------------------------------------------------------- 1 | QT += core websockets 2 | QT -= gui 3 | 4 | TARGET = echoclient 5 | CONFIG += console 6 | CONFIG -= app_bundle 7 | 8 | TEMPLATE = app 9 | 10 | SOURCES += \ 11 | main.cpp \ 12 | echoclient.cpp 13 | 14 | HEADERS += \ 15 | echoclient.h 16 | 17 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/echoclient 18 | INSTALLS += target 19 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoserver.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = echoserver 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | echoserver.cpp 12 | 13 | HEADERS += \ 14 | echoserver.h 15 | 16 | EXAMPLE_FILES += echoclient.html 17 | 18 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/echoserver 19 | INSTALLS += target 20 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/simplechat.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = simplechatserver 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | chatserver.cpp 12 | 13 | HEADERS += \ 14 | chatserver.h 15 | 16 | EXAMPLE_FILES += chatclient.html 17 | 18 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/simplechat 19 | INSTALLS += target 20 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include "sslechoserver.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication a(argc, argv); 9 | SslEchoServer server(1234); 10 | 11 | Q_UNUSED(server); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /src/websockets/qwebsockets_global.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason: default 4 | 5 | #ifndef QWEBSOCKETSGLOBAL_H 6 | #define QWEBSOCKETSGLOBAL_H 7 | 8 | #include 9 | #include 10 | 11 | #endif // QWEBSOCKETSGLOBAL_H 12 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoserver.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = sslechoserver 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | sslechoserver.cpp 12 | 13 | HEADERS += \ 14 | sslechoserver.h 15 | 16 | EXAMPLE_FILES += sslechoclient.html 17 | 18 | RESOURCES += securesocketclient.qrc 19 | 20 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/sslechoserver 21 | INSTALLS += target 22 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/sslechoclient.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = sslechoclient 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | sslechoclient.cpp 12 | 13 | HEADERS += \ 14 | sslechoclient.h 15 | 16 | resources.files = ../sslechoserver/localhost.cert 17 | resources.prefix = / 18 | 19 | RESOURCES += resources 20 | 21 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/sslechoclient 22 | INSTALLS += target 23 | -------------------------------------------------------------------------------- /LICENSES/LicenseRef-Qt-Commercial.txt: -------------------------------------------------------------------------------- 1 | Licensees holding valid commercial Qt licenses may use this software in 2 | accordance with the the terms contained in a written agreement between 3 | you and The Qt Company. Alternatively, the terms and conditions that were 4 | accepted by the licensee when buying and/or downloading the 5 | software do apply. 6 | 7 | For the latest licensing terms and conditions, see https://www.qt.io/terms-conditions. 8 | For further information use the contact form at https://www.qt.io/contact-us. 9 | -------------------------------------------------------------------------------- /coin/module_config.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | accept_configuration: 3 | condition: property 4 | property: features 5 | not_contains_value: Disable 6 | 7 | instructions: 8 | Build: 9 | - type: EnvironmentVariable 10 | variableName: VERIFY_SOURCE_SBOM 11 | variableValue: "ON" 12 | - !include "{{qt/qtbase}}/coin_module_build_template_v2.yaml" 13 | 14 | Test: 15 | - !include "{{qt/qtbase}}/coin_module_test_template_v3.yaml" 16 | - !include "{{qt/qtbase}}/coin_module_test_docs.yaml" 17 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QGuiApplication app(argc, argv); 10 | 11 | QQuickView view; 12 | view.setSource(QUrl(QStringLiteral("qrc:/qml/qmlwebsocketclient/main.qml"))); 13 | view.show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QGuiApplication app(argc, argv); 10 | 11 | QQuickView view; 12 | view.setSource(QUrl(QStringLiteral("qrc:/qml/qmlwebsocketserver/main.qml"))); 13 | view.show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/auto/websockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websockets.pro. 5 | 6 | add_subdirectory(qwebsocketcorsauthenticator) 7 | add_subdirectory(qwebsocket) 8 | add_subdirectory(qwebsocketserver) 9 | if(QT_FEATURE_private_tests) 10 | add_subdirectory(websocketprotocol) 11 | add_subdirectory(dataprocessor) 12 | add_subdirectory(websocketframe) 13 | add_subdirectory(handshakerequest) 14 | add_subdirectory(handshakeresponse) 15 | add_subdirectory(qdefaultmaskgenerator) 16 | endif() 17 | -------------------------------------------------------------------------------- /src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Kurt Pattyn 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | //! [6] 4 | QList cert = QSslCertificate::fromPath(QLatin1String("server-certificate.pem")); 5 | QSslError error(QSslError::SelfSignedCertificate, cert.at(0)); 6 | QList expectedSslErrors; 7 | expectedSslErrors.append(error); 8 | 9 | QWebSocket socket; 10 | socket.ignoreSslErrors(expectedSslErrors); 11 | socket.open(QUrl(QStringLiteral("wss://myserver.at.home"))); 12 | //! [6] 13 | -------------------------------------------------------------------------------- /examples/websockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | if(TARGET Qt::Quick) 5 | qt_internal_add_example(qmlwebsocketclient) 6 | qt_internal_add_example(qmlwebsocketserver) 7 | endif() 8 | if (NOT ANDROID) 9 | qt_internal_add_example(echoclient) 10 | qt_internal_add_example(echoserver) 11 | qt_internal_add_example(simplechat) 12 | if(QT_FEATURE_ssl) 13 | qt_internal_add_example(sslechoserver) 14 | qt_internal_add_example(sslechoclient) 15 | endif() 16 | endif() 17 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | qt_internal_add_qml_module(qmlwebsockets 5 | URI "QtWebSockets" 6 | VERSION "${PROJECT_VERSION}" 7 | PAST_MAJOR_VERSIONS 1 8 | CLASS_NAME QtWebSocketsDeclarativeModule 9 | PLUGIN_TARGET qmlwebsockets 10 | SOURCES 11 | qqmlwebsocket.cpp qqmlwebsocket.h 12 | qqmlwebsocketserver.cpp qqmlwebsocketserver.h 13 | DEFINES 14 | QT_NO_CONTEXTLESS_CONNECT 15 | LIBRARIES 16 | Qt::CorePrivate 17 | Qt::QmlPrivate 18 | Qt::WebSockets 19 | NO_GENERATE_CPP_EXPORTS 20 | ) 21 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qwebsocketcorsauthenticator.pro. 5 | 6 | ##################################################################### 7 | ## tst_qwebsocketcorsauthenticator Test: 8 | ##################################################################### 9 | 10 | qt_internal_add_test(tst_qwebsocketcorsauthenticator 11 | SOURCES 12 | tst_qwebsocketcorsauthenticator.cpp 13 | LIBRARIES 14 | Qt::WebSockets 15 | ) 16 | 17 | #### Keys ignored in scope 1:.:.:qwebsocketcorsauthenticator.pro:: 18 | # TEMPLATE = "app" 19 | -------------------------------------------------------------------------------- /src/websockets/doc/src/qtwebsockets-toc.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebsockets-toc.html 6 | \title Qt WebSockets module topics 7 | 8 | The following list has links to all the individual topics (HTML files) 9 | in the Qt WebSockets module. 10 | 11 | \list 12 | \li \l {Qt WebSockets Overview}{Overview} 13 | \li \l {Testing Qt WebSockets} 14 | \li \l {QWebSocket client example}{WebSocket client sample} 15 | \li \l {WebSocket server example}{WebSocket server sample} 16 | \li \l {Changes to Qt WebSockets}{Upgrading from Qt 5} 17 | \endlist 18 | 19 | */ 20 | -------------------------------------------------------------------------------- /tests/auto/websockets/dataprocessor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from dataprocessor.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_dataprocessor Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_dataprocessor 15 | SOURCES 16 | tst_dataprocessor.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:dataprocessor.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/echoclient.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef ECHOCLIENT_H 4 | #define ECHOCLIENT_H 5 | 6 | #include 7 | #include 8 | 9 | class EchoClient : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit EchoClient(const QUrl &url, bool debug = false, QObject *parent = nullptr); 14 | 15 | Q_SIGNALS: 16 | void closed(); 17 | 18 | private Q_SLOTS: 19 | void onConnected(); 20 | void onTextMessageReceived(QString message); 21 | 22 | private: 23 | QWebSocket m_webSocket; 24 | bool m_debug; 25 | }; 26 | 27 | #endif // ECHOCLIENT_H 28 | -------------------------------------------------------------------------------- /tests/auto/websockets/websocketframe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websocketframe.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_websocketframe Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_websocketframe 15 | SOURCES 16 | tst_websocketframe.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:websocketframe.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /dist/changes-5.9.2: -------------------------------------------------------------------------------- 1 | Qt 5.9.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | -------------------------------------------------------------------------------- /tests/auto/websockets/websocketprotocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websocketprotocol.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_websocketprotocol Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_websocketprotocol 15 | SOURCES 16 | tst_websocketprotocol.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:websocketprotocol.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qdefaultmaskgenerator.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_defaultmaskgenerator Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_defaultmaskgenerator 15 | SOURCES 16 | tst_defaultmaskgenerator.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:qdefaultmaskgenerator.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /tests/auto/websockets/handshakerequest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from handshakerequest.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_handshakerequest Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_handshakerequest 15 | SOURCES 16 | tst_handshakerequest.cpp 17 | LIBRARIES 18 | Qt::NetworkPrivate 19 | Qt::WebSocketsPrivate 20 | ) 21 | 22 | #### Keys ignored in scope 1:.:.:handshakerequest.pro:: 23 | # TEMPLATE = "app" 24 | # _REQUIREMENTS = "qtConfig(private_tests)" 25 | -------------------------------------------------------------------------------- /tests/auto/websockets/handshakeresponse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from handshakeresponse.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_handshakeresponse Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_handshakeresponse 15 | SOURCES 16 | tst_handshakeresponse.cpp 17 | LIBRARIES 18 | Qt::NetworkPrivate 19 | Qt::WebSocketsPrivate 20 | ) 21 | 22 | #### Keys ignored in scope 1:.:.:handshakeresponse.pro:: 23 | # TEMPLATE = "app" 24 | # _REQUIREMENTS = "qtConfig(private_tests)" 25 | -------------------------------------------------------------------------------- /dist/changes-5.13.0: -------------------------------------------------------------------------------- 1 | Qt 5.13 introduces many new features and improvements as well as bugfixes 2 | over the 5.12.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 8 | Applications compiled for 5.12 will continue to run with 5.13. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | - This release contains only minor code improvements. 19 | -------------------------------------------------------------------------------- /src/websockets/qmaskgenerator.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QMASKGENERATOR_H 6 | #define QMASKGENERATOR_H 7 | 8 | #include 9 | #include "QtWebSockets/qwebsockets_global.h" 10 | 11 | QT_BEGIN_NAMESPACE 12 | 13 | class Q_WEBSOCKETS_EXPORT QMaskGenerator : public QObject 14 | { 15 | Q_DISABLE_COPY(QMaskGenerator) 16 | 17 | public: 18 | explicit QMaskGenerator(QObject *parent = nullptr); 19 | ~QMaskGenerator() override; 20 | 21 | virtual bool seed() = 0; 22 | virtual quint32 nextMask() = 0; 23 | }; 24 | 25 | QT_END_NAMESPACE 26 | 27 | #endif // QMASKGENERATOR_H 28 | -------------------------------------------------------------------------------- /dist/changes-5.8.0: -------------------------------------------------------------------------------- 1 | Qt 5.8 introduces many new features and improvements as well as bugfixes 2 | over the 5.7.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.8 series is binary compatible with the 5.7.x series. 8 | Applications compiled for 5.7 will continue to run with 5.8. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | QWebSocket 19 | ---------- 20 | 21 | - It is now possible to use TLS PSK ciphersuites. 22 | -------------------------------------------------------------------------------- /dist/changes-5.12.1: -------------------------------------------------------------------------------- 1 | Qt 5.12.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.1: -------------------------------------------------------------------------------- 1 | Qt 5.13.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.1: -------------------------------------------------------------------------------- 1 | Qt 5.14.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.15.1: -------------------------------------------------------------------------------- 1 | Qt 5.15.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.15.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 10 | Applications compiled for 5.14 will continue to run with 5.15. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.11.3: -------------------------------------------------------------------------------- 1 | Qt 5.11.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.2: -------------------------------------------------------------------------------- 1 | Qt 5.12.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.3: -------------------------------------------------------------------------------- 1 | Qt 5.12.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.4: -------------------------------------------------------------------------------- 1 | Qt 5.12.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.3. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.5: -------------------------------------------------------------------------------- 1 | Qt 5.12.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.4. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.2: -------------------------------------------------------------------------------- 1 | Qt 5.13.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0 through 5.13.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.2: -------------------------------------------------------------------------------- 1 | Qt 5.14.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0 through 5.14.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /tests/auto/qml/qmlwebsockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qmlwebsockets.pro. 5 | 6 | ##################################################################### 7 | ## tst_qmlwebsockets Test: 8 | ##################################################################### 9 | file(GLOB_RECURSE test_data_glob 10 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | *.qml) 12 | list(APPEND test_data ${test_data_glob}) 13 | 14 | qt_internal_add_test(tst_qmlwebsockets 15 | QMLTEST 16 | SOURCES 17 | tst_qmlwebsockets.cpp 18 | LIBRARIES 19 | Qt::Gui 20 | TESTDATA ${test_data} 21 | ) 22 | 23 | #### Keys ignored in scope 1:.:.:qmlwebsockets.pro:: 24 | # DEPLOYMENT = "importFiles" 25 | # TEMPLATE = "app" 26 | # importFiles.path = "." 27 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/chatserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef CHATSERVER_H 4 | #define CHATSERVER_H 5 | 6 | #include 7 | #include 8 | 9 | QT_FORWARD_DECLARE_CLASS(QWebSocketServer) 10 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 11 | QT_FORWARD_DECLARE_CLASS(QString) 12 | 13 | class ChatServer : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit ChatServer(quint16 port, QObject *parent = nullptr); 18 | ~ChatServer() override; 19 | 20 | private slots: 21 | void onNewConnection(); 22 | void processMessage(const QString &message); 23 | void socketDisconnected(); 24 | 25 | private: 26 | QWebSocketServer *m_pWebSocketServer; 27 | QList m_clients; 28 | }; 29 | 30 | #endif //CHATSERVER_H 31 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/sslechoclient.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef SSLECHOCLIENT_H 4 | #define SSLECHOCLIENT_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 14 | 15 | class SslEchoClient : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit SslEchoClient(const QUrl &url, QObject *parent = nullptr); 20 | 21 | private Q_SLOTS: 22 | void onConnected(); 23 | void onTextMessageReceived(QString message); 24 | void onSslErrors(const QList &errors); 25 | 26 | private: 27 | QWebSocket m_webSocket; 28 | }; 29 | 30 | #endif // SSLECHOCLIENT_H 31 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qwebsocket.pro. 5 | 6 | ##################################################################### 7 | ## tst_qwebsocket Test: 8 | ##################################################################### 9 | 10 | qt_internal_add_test(tst_qwebsocket 11 | SOURCES 12 | tst_qwebsocket.cpp 13 | LIBRARIES 14 | Qt::WebSockets 15 | Qt::TestPrivate 16 | BUNDLE_ANDROID_OPENSSL_LIBS 17 | ) 18 | 19 | set(qwebsocketshared_resource_files 20 | "../shared/localhost.cert" 21 | "../shared/localhost.key" 22 | ) 23 | qt_internal_add_resource(tst_qwebsocket "qwebsocketshared" 24 | PREFIX 25 | "/" 26 | BASE 27 | "../shared" 28 | FILES 29 | ${qwebsocketshared_resource_files} 30 | ) 31 | 32 | #### Keys ignored in scope 1:.:.:qwebsocket.pro:: 33 | # TEMPLATE = "app" 34 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef ECHOSERVER_H 4 | #define ECHOSERVER_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | QT_FORWARD_DECLARE_CLASS(QWebSocketServer) 11 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 12 | 13 | class EchoServer : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit EchoServer(quint16 port, bool debug = false, QObject *parent = nullptr); 18 | ~EchoServer(); 19 | 20 | Q_SIGNALS: 21 | void closed(); 22 | 23 | private Q_SLOTS: 24 | void onNewConnection(); 25 | void processTextMessage(QString message); 26 | void processBinaryMessage(QByteArray message); 27 | void socketDisconnected(); 28 | 29 | private: 30 | QWebSocketServer *m_pWebSocketServer; 31 | QList m_clients; 32 | bool m_debug; 33 | }; 34 | 35 | #endif //ECHOSERVER_H 36 | -------------------------------------------------------------------------------- /dist/changes-5.10.0: -------------------------------------------------------------------------------- 1 | Qt 5.10 introduces many new features and improvements as well as bugfixes 2 | over the 5.9.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 8 | Applications compiled for 5.9 will continue to run with 5.10. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.10.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /dist/changes-5.11.0: -------------------------------------------------------------------------------- 1 | Qt 5.11 introduces many new features and improvements as well as bugfixes 2 | over the 5.10.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 8 | Applications compiled for 5.10 will continue to run with 5.11. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.11.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef SSLECHOSERVER_H 4 | #define SSLECHOSERVER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | QT_FORWARD_DECLARE_CLASS(QWebSocketServer) 12 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 13 | 14 | class SslEchoServer : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit SslEchoServer(quint16 port, QObject *parent = nullptr); 19 | ~SslEchoServer() override; 20 | 21 | private Q_SLOTS: 22 | void onNewConnection(); 23 | void processTextMessage(QString message); 24 | void processBinaryMessage(QByteArray message); 25 | void socketDisconnected(); 26 | void onSslErrors(const QList &errors); 27 | 28 | private: 29 | QWebSocketServer *m_pWebSocketServer; 30 | QList m_clients; 31 | }; 32 | 33 | #endif //SSLECHOSERVER_H 34 | -------------------------------------------------------------------------------- /dist/changes-5.9.1: -------------------------------------------------------------------------------- 1 | Qt 5.9.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.5: -------------------------------------------------------------------------------- 1 | Qt 5.9.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.5 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.1: -------------------------------------------------------------------------------- 1 | Qt 5.11.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.1 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /examples/websockets/doc/qmlwebsocketserver.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example qmlwebsocketserver 6 | \title QML WebSocket Server 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A simple example that shows how to use a QML WebSocketServer. 10 | 11 | \image qmlwebsocketserver-example.webp QML WebSocket Server GUI 12 | 13 | This example opens a window and has a WebSocketServer listening 14 | for incoming connections and a WebSocket connecting to the 15 | WebSocketServer. Every time the window is clicked, the WebSocket 16 | sends a message to the WebSocketServer. The WebSocketServer has a 17 | signal handler that logs the incoming message to the window and 18 | sends a message back again, and the WebSocket has a signal 19 | handler that logs the returned message to the window. 20 | */ 21 | -------------------------------------------------------------------------------- /dist/changes-5.15.0: -------------------------------------------------------------------------------- 1 | Qt 5.15 introduces many new features and improvements as well as bugfixes 2 | over the 5.14.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 8 | Applications compiled for 5.14 will continue to run with 5.15. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebSocket * 20 | **************************************************************************** 21 | 22 | - [QTBUG-70693] Added public API to set the maximum frame size and 23 | message size 24 | -------------------------------------------------------------------------------- /dist/changes-5.9.4: -------------------------------------------------------------------------------- 1 | Qt 5.9.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.4 Changes * 22 | **************************************************************************** 23 | 24 | - This release does not contain any changes to this module. 25 | 26 | -------------------------------------------------------------------------------- /dist/changes-5.9.6: -------------------------------------------------------------------------------- 1 | Qt 5.9.6 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0 through 5.9.5. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.6 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketcorsauthenticator_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | #ifndef QWEBSOCKETCORSAUTHENTICATOR_P_H 5 | #define QWEBSOCKETCORSAUTHENTICATOR_P_H 6 | 7 | #include 8 | #include 9 | 10 | // 11 | // W A R N I N G 12 | // ------------- 13 | // 14 | // This file is not part of the Qt API. It exists purely as an 15 | // implementation detail. This header file may change from version to 16 | // version without notice, or even be removed. 17 | // 18 | // We mean it. 19 | // 20 | QT_BEGIN_NAMESPACE 21 | 22 | class QWebSocketCorsAuthenticatorPrivate 23 | { 24 | public: 25 | QWebSocketCorsAuthenticatorPrivate(const QString &origin, bool allowed); 26 | ~QWebSocketCorsAuthenticatorPrivate(); 27 | 28 | QString m_origin; 29 | bool m_isAllowed; 30 | }; 31 | 32 | QT_END_NAMESPACE 33 | 34 | #endif // QWEBSOCKETCORSAUTHENTICATOR_P_H 35 | -------------------------------------------------------------------------------- /dist/changes-5.11.2: -------------------------------------------------------------------------------- 1 | Qt 5.11.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.2 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.6.3: -------------------------------------------------------------------------------- 1 | Qt 5.6.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.6.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 10 | Applications compiled for 5.5 will continue to run with 5.6. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | - QWebSocketHandshakeRequest 24 | [QTBUG-57357] Fixed the parsing of port in handshake requests. 25 | -------------------------------------------------------------------------------- /examples/websockets/doc/echoserver.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example echoserver 6 | \title WebSocket Echo Server 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief Show how to write a simple WebSocket server application. 10 | 11 | This Echo Server shows how to create a simple server application that sends 12 | back a reply in response to a message it receives, using the 13 | \l {Qt WebSockets}{WebSocket} API. For the sake of illustration, the reply 14 | is simply a copy of the message. 15 | 16 | If your web browser supports \l {Qt WebSockets}{WebSocket}, you can also use it 17 | to open the \c {echoserver/echoclient.html}{echoclient.html} file, and operate 18 | as shown in the following screenshot: 19 | 20 | \image echoclient-html-example.png WebSocket Echo HTML Client 21 | 22 | Otherwise use the \l {WebSocket Echo Client} to connect to the server. 23 | 24 | \sa {WebSocket Echo Client} 25 | */ 26 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(echoserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/echoserver") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(echoserver 22 | echoserver.cpp echoserver.h 23 | main.cpp 24 | ) 25 | 26 | set_target_properties(echoserver PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(echoserver PUBLIC 32 | Qt::WebSockets 33 | ) 34 | 35 | install(TARGETS echoserver 36 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 37 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | ) 40 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(echoclient LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/echoclient") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS Core WebSockets) 20 | 21 | qt_add_executable(echoclient 22 | echoclient.cpp echoclient.h 23 | main.cpp 24 | ) 25 | 26 | set_target_properties(echoclient PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(echoclient PUBLIC 32 | Qt::Core 33 | Qt::WebSockets 34 | ) 35 | 36 | install(TARGETS echoclient 37 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 40 | ) 41 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qtwebsockets.pro. 5 | 6 | cmake_minimum_required(VERSION 3.16) 7 | 8 | include(.cmake.conf) 9 | project(QtWebSockets # special case 10 | VERSION "${QT_REPO_MODULE_VERSION}" 11 | DESCRIPTION "Qt WebSockets Libraries" # special case 12 | HOMEPAGE_URL "https://qt.io/" 13 | LANGUAGES CXX C 14 | ) 15 | 16 | # Make sure we use the fixed BASE argument of qt_add_resource. 17 | set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE) 18 | 19 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals) 20 | 21 | # This should be called as early as possible, just after find_package(BuildInternals) where it is 22 | # defined. 23 | qt_internal_project_setup() 24 | 25 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core Network) 26 | find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Quick QuickTest) 27 | 28 | if(NOT TARGET Qt::Network) 29 | message(NOTICE "Skipping the build as the condition \"TARGET Qt::Network\" is not met.") 30 | return() 31 | endif() 32 | qt_build_repo() 33 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(simplechatserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/simplechat") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(simplechatserver 22 | chatserver.cpp chatserver.h 23 | main.cpp 24 | ) 25 | 26 | set_target_properties(simplechatserver PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(simplechatserver PUBLIC 32 | Qt::WebSockets 33 | ) 34 | 35 | install(TARGETS simplechatserver 36 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 37 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | ) 40 | -------------------------------------------------------------------------------- /dist/changes-5.10.1: -------------------------------------------------------------------------------- 1 | Qt 5.10.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.10.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 10 | Applications compiled for 5.9 will continue to run with 5.10. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | This release contains all fixes included in the Qt 5.9.4 release. 21 | 22 | **************************************************************************** 23 | * Qt 5.10.1 Changes * 24 | **************************************************************************** 25 | 26 | - This release does not contain any changes to this module. 27 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeoptions_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETHANDSHAKEOPTIONS_P_H 6 | #define QWEBSOCKETHANDSHAKEOPTIONS_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | 21 | #include "qwebsockethandshakeoptions.h" 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | class Q_AUTOTEST_EXPORT QWebSocketHandshakeOptionsPrivate : public QSharedData 26 | { 27 | public: 28 | inline bool operator==(const QWebSocketHandshakeOptionsPrivate &other) const 29 | { return subprotocols == other.subprotocols; } 30 | 31 | QStringList subprotocols; 32 | }; 33 | 34 | QT_END_NAMESPACE 35 | 36 | #endif // QWEBSOCKETHANDSHAKEOPTIONS_P_H 37 | -------------------------------------------------------------------------------- /tests/auto/websockets/shared/localhost.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC+zCCAeOgAwIBAgIJAP26rumH9qOkMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV 3 | BAMMCWxvY2FsaG9zdDAeFw0xMzExMDYxNjU4NTRaFw0yMzExMDQxNjU4NTRaMBQx 4 | EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 5 | ggEBALgagHqEqWr4WH+MFBQE+BWZri5UUn/QPORN2pUB1lWMzeDCM5YMc/D1dhUG 6 | 7zg5I9QO5Ut1YcoVO25OAseddgVaIFXPNyEG2nUTz53xx3pyqp3WtQkYCRAQzI8K 7 | IFIzBSD+nJNl+8gBld7Fe+4d8bFCwfXspQBJ2RY8SQ6tjRFVKHN7haLsD+WV3AFg 8 | siWkCxeXxVLNI69cuLwV7bEsv6U1N1yNROvRpu4yJcaNnu36kJFbORPhNfy6qJGX 9 | i0A30dYdMoLhtCN3Qf/XwGyS84Rs2XXduNlBdUgbpluY2r2x3Gz32hIwsHHcPzX6 10 | O9nwVPQ8k29lfC8yPmAWA9vPiBUCAwEAAaNQME4wHQYDVR0OBBYEFJZESCN01tY3 11 | MgXxmqiUBNPxsgiKMB8GA1UdIwQYMBaAFJZESCN01tY3MgXxmqiUBNPxsgiKMAwG 12 | A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAHylCJYED9PqLB9FE4A0CRfy 13 | BdxIqOK+UExxxkU1DeN7kM4U2+E0G85nqBLOL34BDj8LDKJH9WC7L9jMV8T3Upbg 14 | +RrTGiIcyjsL18L2KWeOia1R6VVAQcZrqoWv+QXyVvIi8IpTOE074C6+Vzx6XYMe 15 | CpW4jcdfmn39oVeMXxz9+8wD7CWeCT+SMj8tt+OB1XjQwdEG03vb6ArtnuJT77VI 16 | 3I090OtKksBE5hy1H9N2E3wxhFTxC+DI5sc7Bj87v3blL4Z3DvRUEHwQHcDccQ0D 17 | ERUEcSyn1YGSlDVbVf3CzH4WXxddUBmaSHf4JTuAMy0C0A6IWuMP+rVVvVMIXNM= 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /dist/changes-5.9.3: -------------------------------------------------------------------------------- 1 | Qt 5.9.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.3 Changes * 22 | **************************************************************************** 23 | 24 | - Fixed a race condition in QWebSocketServer where the server would, 25 | in rare cases, miss the start of the handshake coming from a client. 26 | - Other minor code improvements. 27 | -------------------------------------------------------------------------------- /examples/websockets/doc/echoclient.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example echoclient 6 | \title WebSocket Echo Client 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief Show how to write a simple WebSocket client application. 10 | 11 | The Echo Client shows how to use the \l {Qt WebSockets}{WebSocket} 12 | API to send a message to a server and process whatever response the 13 | server returns - in this case, simply reporting the response. 14 | 15 | The client by default opens a WebSocket connection to a server listening 16 | on local port 1234. When the connection attempt is successful, the client 17 | will send a message to the server and print out whatever response the 18 | server sends. The client then closes the connection. 19 | 20 | \image echoclient-console-example.webp WebSocket Echo Console Client 21 | 22 | For the sake of illustration, we use the \l {WebSocket Echo Server}, whose 23 | reply is simply the message that was sent. 24 | 25 | \sa {WebSocket Echo Server} 26 | */ 27 | -------------------------------------------------------------------------------- /src/websockets/qdefaultmaskgenerator_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QDEFAULTMASKGENERATOR_P_H 6 | #define QDEFAULTMASKGENERATOR_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | 22 | QT_BEGIN_NAMESPACE 23 | class QObject; 24 | 25 | class Q_AUTOTEST_EXPORT QDefaultMaskGenerator : public QMaskGenerator 26 | { 27 | Q_DISABLE_COPY(QDefaultMaskGenerator) 28 | 29 | public: 30 | explicit QDefaultMaskGenerator(QObject *parent = nullptr); 31 | ~QDefaultMaskGenerator() override; 32 | 33 | bool seed() noexcept override; 34 | quint32 nextMask() noexcept override; 35 | }; 36 | 37 | QT_END_NAMESPACE 38 | 39 | #endif // QDEFAULTMASKGENERATOR_P_H 40 | -------------------------------------------------------------------------------- /examples/websockets/doc/sslechoclient.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example sslechoclient 6 | \title Secure WebSocket Echo Client 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A simple client application using secure WebSockets (wss). 10 | 11 | The Secure WebSocket Echo Client example shows how to use the 12 | \l {Qt WebSockets}{WebSocket} class to implement an echo client over 13 | a secure connection (wss). It connects to a server and sends a message, 14 | and when it receives a message back, it prints it out and exits. SSL 15 | support is required for this example to work. 16 | 17 | This example connects by default to localhost at port 1234 using a secure 18 | connection. It trusts the certificates signed by the CA certificates 19 | configured in the SSL backend, and in addition trusts the certificate 20 | used by \l {Secure WebSocket Echo Server}. 21 | 22 | \image echoclient-console-example.webp Secure WebSocket Echo Console Client 23 | 24 | \sa {WebSocket Echo Client}, {Secure WebSocket Echo Server} 25 | */ 26 | -------------------------------------------------------------------------------- /coin/axivion/ci_config_linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "Project": { 3 | "BuildSystemIntegration": { 4 | "child_order": [ 5 | "GCCSetup", 6 | "CMake", 7 | "LinkLibraries" 8 | ] 9 | }, 10 | "CMake": { 11 | "_active": true, 12 | "_copy_from": "CMakeIntegration", 13 | "build_environment": {}, 14 | "build_options": "-j4", 15 | "generate_options": "--fresh", 16 | "generator": "Ninja" 17 | }, 18 | "GCCSetup": { 19 | "_active": true, 20 | "_copy_from": "Command", 21 | "build_command": "gccsetup --cc gcc --cxx g++ --config ../../../axivion/" 22 | }, 23 | "LinkLibraries": { 24 | "_active": true, 25 | "_copy_from": "AxivionLinker", 26 | "input_files": [ 27 | "build/lib/lib*.so*.ir", 28 | "build/qml/*/lib*.so*.ir" 29 | ], 30 | "ir": "build/$(env:TESTED_MODULE_COIN).ir" 31 | } 32 | }, 33 | "_Format": "1.0", 34 | "_Version": "7.6.2", 35 | "_VersionNum": [ 36 | 7, 37 | 6, 38 | 2, 39 | 12725 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /dist/changes-5.15.2: -------------------------------------------------------------------------------- 1 | Qt 5.15.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.15.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5.15/index.html 8 | 9 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 10 | Applications compiled for 5.14 will continue to run with 5.15. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Important Behavior Changes * 22 | **************************************************************************** 23 | 24 | **************************************************************************** 25 | * Library * 26 | **************************************************************************** 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(sslechoclient LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/sslechoclient") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(sslechoclient 22 | main.cpp 23 | sslechoclient.cpp sslechoclient.h 24 | ) 25 | 26 | qt_add_resources(sslechoclient "cert" 27 | BASE ../sslechoserver 28 | FILES ../sslechoserver/localhost.cert 29 | ) 30 | 31 | set_target_properties(sslechoclient PROPERTIES 32 | WIN32_EXECUTABLE FALSE 33 | MACOSX_BUNDLE FALSE 34 | ) 35 | 36 | target_link_libraries(sslechoclient PUBLIC 37 | Qt::WebSockets 38 | ) 39 | 40 | install(TARGETS sslechoclient 41 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 42 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 43 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 44 | ) 45 | -------------------------------------------------------------------------------- /examples/websockets/doc/simplechat.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example simplechat 6 | \title Simple WebSocket Chat 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A minimal chat application using the WebSocket protocol. 10 | 11 | This application shows how to use the QWebSocket and QWebSocketServer 12 | classes to create a minimalist chat application over the WebSocket protocol. 13 | The example is a server that allows multiple clients to connect to it to send 14 | and receive messages. 15 | 16 | By default it listens at localhost port 1234. It keeps track of all clients 17 | that are connected to it, and each time one of the clients sends a message to 18 | the server, the message is forwarded to all other clients. When a client 19 | disconnects, it is removed from the list of clients. 20 | 21 | \image simplechat-html-example.webp Simple WebSocket Chat HTML Client 22 | 23 | There is also an HTML-client that is used to connect to and disconnect from 24 | the server, query about the connection, send messages, and view all the 25 | messages sent by other clients. 26 | 27 | */ 28 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qwebsocketserver.pro. 5 | 6 | ##################################################################### 7 | ## tst_qwebsocketserver Test: 8 | ##################################################################### 9 | 10 | qt_internal_add_test(tst_qwebsocketserver 11 | SOURCES 12 | tst_qwebsocketserver.cpp 13 | LIBRARIES 14 | Qt::WebSockets 15 | BUNDLE_ANDROID_OPENSSL_LIBS 16 | ) 17 | 18 | # Resources: 19 | set(qwebsocketshared_resource_files 20 | "../shared/localhost.cert" 21 | "../shared/localhost.key" 22 | "../shared/selfsigned.cert" 23 | "../shared/selfsigned.key" 24 | ) 25 | 26 | qt_internal_add_resource(tst_qwebsocketserver "qwebsocketshared" 27 | PREFIX 28 | "/" 29 | BASE 30 | "../shared" 31 | FILES 32 | ${qwebsocketshared_resource_files} 33 | ) 34 | 35 | 36 | #### Keys ignored in scope 1:.:.:qwebsocketserver.pro:: 37 | # TEMPLATE = "app" 38 | 39 | ## Scopes: 40 | ##################################################################### 41 | 42 | qt_internal_extend_target(tst_qwebsocketserver CONDITION boot2qt 43 | DEFINES 44 | SHOULD_CHECK_SYSCALL_SUPPORT 45 | ) 46 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/echoclient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "echoclient.h" 4 | #include 5 | 6 | QT_USE_NAMESPACE 7 | 8 | //! [constructor] 9 | EchoClient::EchoClient(const QUrl &url, bool debug, QObject *parent) : 10 | QObject(parent), 11 | m_debug(debug) 12 | { 13 | if (m_debug) 14 | qDebug() << "WebSocket server:" << url; 15 | connect(&m_webSocket, &QWebSocket::connected, this, &EchoClient::onConnected); 16 | connect(&m_webSocket, &QWebSocket::disconnected, this, &EchoClient::closed); 17 | m_webSocket.open(url); 18 | } 19 | //! [constructor] 20 | 21 | //! [onConnected] 22 | void EchoClient::onConnected() 23 | { 24 | if (m_debug) 25 | qDebug() << "WebSocket connected"; 26 | connect(&m_webSocket, &QWebSocket::textMessageReceived, 27 | this, &EchoClient::onTextMessageReceived); 28 | m_webSocket.sendTextMessage(QStringLiteral("Hello, world!")); 29 | } 30 | //! [onConnected] 31 | 32 | //! [onTextMessageReceived] 33 | void EchoClient::onTextMessageReceived(QString message) 34 | { 35 | if (m_debug) 36 | qDebug() << "Message received:" << message; 37 | m_webSocket.close(); 38 | } 39 | //! [onTextMessageReceived] 40 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(qmlwebsocketclient LANGUAGES CXX) 6 | 7 | set(CMAKE_AUTOMOC ON) 8 | 9 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 10 | set(INSTALL_EXAMPLESDIR "examples") 11 | endif() 12 | 13 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/qmlwebsocketclient") 14 | 15 | find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebSockets) 16 | 17 | qt_add_executable(qmlwebsocketclient 18 | main.cpp 19 | ) 20 | 21 | set_target_properties(qmlwebsocketclient PROPERTIES 22 | WIN32_EXECUTABLE TRUE 23 | MACOSX_BUNDLE FALSE 24 | ) 25 | 26 | target_link_libraries(qmlwebsocketclient PUBLIC 27 | Qt::Core 28 | Qt::Gui 29 | Qt::Quick 30 | Qt::WebSockets 31 | ) 32 | 33 | # Resources: 34 | set(data_resource_files 35 | "qml/qmlwebsocketclient/main.qml" 36 | ) 37 | 38 | qt6_add_resources(qmlwebsocketclient "data" 39 | PREFIX 40 | "/" 41 | FILES 42 | ${data_resource_files} 43 | ) 44 | 45 | install(TARGETS qmlwebsocketclient 46 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 47 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 48 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 49 | ) 50 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(qmlwebsocketserver LANGUAGES CXX) 6 | 7 | set(CMAKE_AUTOMOC ON) 8 | 9 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 10 | set(INSTALL_EXAMPLESDIR "examples") 11 | endif() 12 | 13 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/qmlwebsocketserver") 14 | 15 | find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebSockets) 16 | 17 | qt_add_executable(qmlwebsocketserver 18 | main.cpp 19 | ) 20 | 21 | set_target_properties(qmlwebsocketserver PROPERTIES 22 | WIN32_EXECUTABLE TRUE 23 | MACOSX_BUNDLE FALSE 24 | ) 25 | 26 | target_link_libraries(qmlwebsocketserver PUBLIC 27 | Qt::Core 28 | Qt::Gui 29 | Qt::Quick 30 | Qt::WebSockets 31 | ) 32 | 33 | # Resources: 34 | set(data_resource_files 35 | "qml/qmlwebsocketserver/main.qml" 36 | ) 37 | 38 | qt6_add_resources(qmlwebsocketserver "data" 39 | PREFIX 40 | "/" 41 | FILES 42 | ${data_resource_files} 43 | ) 44 | 45 | install(TARGETS qmlwebsocketserver 46 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 47 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 48 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 49 | ) 50 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include 5 | #include 6 | #include "echoserver.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | QCoreApplication a(argc, argv); 11 | 12 | QCommandLineParser parser; 13 | parser.setApplicationDescription("QtWebSockets example: echoserver"); 14 | parser.addHelpOption(); 15 | 16 | QCommandLineOption dbgOption(QStringList() << "d" << "debug", 17 | QCoreApplication::translate("main", "Debug output [default: off].")); 18 | parser.addOption(dbgOption); 19 | QCommandLineOption portOption(QStringList() << "p" << "port", 20 | QCoreApplication::translate("main", "Port for echoserver [default: 1234]."), 21 | QCoreApplication::translate("main", "port"), QLatin1String("1234")); 22 | parser.addOption(portOption); 23 | parser.process(a); 24 | bool debug = parser.isSet(dbgOption); 25 | int port = parser.value(portOption).toInt(); 26 | 27 | EchoServer *server = new EchoServer(port, debug); 28 | QObject::connect(server, &EchoServer::closed, &a, &QCoreApplication::quit); 29 | 30 | return a.exec(); 31 | } 32 | -------------------------------------------------------------------------------- /src/websockets/doc/src/qt6-changes.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebsockets-changes-qt6.html 6 | \title Changes to Qt WebSockets 7 | \ingroup changes-qt-5-to-6 8 | \brief Migrate Qt WebSockets to Qt 6. 9 | 10 | Qt 6 is a result of the conscious effort to make the framework more 11 | efficient and easy to use. 12 | 13 | We try to maintain binary and source compatibility for all the public 14 | APIs in each release. But some changes were inevitable in an effort to 15 | make Qt a better framework. 16 | 17 | In this topic we summarize those changes in Qt WebSockets, and provide guidance 18 | to handle them. 19 | 20 | \section1 Breaking public API changes 21 | 22 | This section contains information about API changes that break source 23 | compatibility. 24 | 25 | \section2 QWebSocketServer::socketDescriptor(), QWebSocketServer::setSocketDescriptor() 26 | 27 | In Qt 6, you should use QWebSocketServer::socketDescriptor() and QWebSocketServer::setSocketDescriptor() 28 | to access the underlying socket descriptor of type \c{qintptr}. They mirror QTcpServer::socketDescriptor() 29 | and QTcpServer::setSocketDescriptor(), and replace the now deprecated nativeDescriptor() and 30 | setNativeDescriptor() methods. 31 | 32 | */ 33 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(sslechoserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/sslechoserver") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(sslechoserver 22 | main.cpp 23 | sslechoserver.cpp sslechoserver.h 24 | ) 25 | 26 | set_target_properties(sslechoserver PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(sslechoserver PUBLIC 32 | Qt::WebSockets 33 | ) 34 | 35 | # Resources: 36 | set(securesocketclient_resource_files 37 | "localhost.cert" 38 | "localhost.key" 39 | ) 40 | 41 | qt6_add_resources(sslechoserver "securesocketclient" 42 | PREFIX 43 | "/" 44 | FILES 45 | ${securesocketclient_resource_files} 46 | ) 47 | 48 | install(TARGETS sslechoserver 49 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 50 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 51 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 52 | ) 53 | -------------------------------------------------------------------------------- /src/websockets/doc/src/qtwebsockets-module.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Kurt Pattyn 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | /*! 4 | \module QtWebSockets 5 | \title Qt WebSockets C++ Classes 6 | \ingroup modules 7 | \qtcmakepackage WebSockets 8 | \qtvariable websockets 9 | \since 5.3 10 | \brief List of C++ classes that enable WebSocket-based communication. 11 | 12 | To use these classes in your application, use the following include 13 | statement: 14 | 15 | \code 16 | #include 17 | \endcode 18 | 19 | To link against the module, add this line to your \l qmake \c 20 | .pro file: 21 | 22 | \code 23 | QT += websockets 24 | \endcode 25 | */ 26 | 27 | /*! 28 | \qmlmodule QtWebSockets 1.\QtMinorVersion 29 | \title Qt WebSockets QML Types 30 | \ingroup qmlmodules 31 | \brief Provides QML types for WebSocket-based communication. 32 | 33 | 34 | The QML types are accessed by using: 35 | \qml \QtMinorVersion 36 | import QtWebSockets 1.\1 37 | \endqml 38 | 39 | \note Prior to Qt 5.5, the import statement was \c{import Qt.WebSockets 1.0} 40 | (notice the dot between \c Qt and \c WebSockets). The old statement is still 41 | supported for backwards compatibility, but it cannot be mixed with the new 42 | statement within the same project. 43 | */ 44 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketcorsauthenticator.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | #ifndef QWEBSOCKETCORSAUTHENTICATOR_H 5 | #define QWEBSOCKETCORSAUTHENTICATOR_H 6 | 7 | #include "QtWebSockets/qwebsockets_global.h" 8 | #include 9 | 10 | QT_BEGIN_NAMESPACE 11 | 12 | class QWebSocketCorsAuthenticatorPrivate; 13 | 14 | class Q_WEBSOCKETS_EXPORT QWebSocketCorsAuthenticator 15 | { 16 | Q_DECLARE_PRIVATE(QWebSocketCorsAuthenticator) 17 | 18 | public: 19 | explicit QWebSocketCorsAuthenticator(const QString &origin); 20 | ~QWebSocketCorsAuthenticator(); 21 | explicit QWebSocketCorsAuthenticator(const QWebSocketCorsAuthenticator &other); 22 | 23 | QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other) noexcept; 24 | QWebSocketCorsAuthenticator &operator =(QWebSocketCorsAuthenticator &&other) noexcept; 25 | 26 | void swap(QWebSocketCorsAuthenticator &other) noexcept; 27 | 28 | QWebSocketCorsAuthenticator &operator =(const QWebSocketCorsAuthenticator &other); 29 | 30 | QString origin() const; 31 | 32 | void setAllowed(bool allowed); 33 | bool allowed() const; 34 | 35 | private: 36 | std::unique_ptr d_ptr; 37 | }; 38 | 39 | QT_END_NAMESPACE 40 | 41 | #endif // QWEBSOCKETCORSAUTHENTICATOR_H 42 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /examples/websockets/doc/sslechoserver.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example sslechoserver 6 | \title Secure WebSocket Echo Server 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A simple server to respond to clients over secure WebSockets (wss). 10 | 11 | The Secure WebSocket Echo Server example shows how to use the QWebSocketServer 12 | class to implement a simple echo server over secure sockets (wss). TLS support 13 | is required for this example to work. It authenticates itself to the client 14 | and, on success, can accept a message from the client, to which it responds. 15 | For the sake of illustration, its response is simply a copy of the message 16 | it was sent. 17 | 18 | This server is configured with a self-signed certificate and key. 19 | Unless the clients contacting this server is configured to trust that 20 | certificate, which \l {Secure WebSocket Echo Client} does, they will reject 21 | this server. 22 | 23 | \image sslechoclient-html-example.webp Secure WebSocket Echo HTML Client 24 | 25 | There is an HTML-based client as part of this example. But it will only 26 | work either if the browser used supports the certificate as described above, 27 | or if it ignores TLS errors for localhost addresses. 28 | 29 | \sa {Secure WebSocket Echo Client}, {WebSocket Echo Server} 30 | */ 31 | -------------------------------------------------------------------------------- /tests/doc/README.qdocinc: -------------------------------------------------------------------------------- 1 | This directory contains autotests and manual tests for the Qt WebSockets 2 | module. 3 | 4 | In addition, Autobahn|Testsuite, a standard test suite for WebSocket 5 | Protocol (RFC 6455), can be used for testing the conformance of Qt 6 | WebSockets. 7 | 8 | http://autobahn.ws/testsuite/ 9 | 10 | Refer to Autobahn|Testsuite installation documentation at 11 | http://autobahn.ws/testsuite/installation.html 12 | 13 | //! [testsuite] 14 | \section1 Testing Qt WebSockets with Autobahn|Testsuite 15 | 16 | 17 | \section2 wstest - fuzzingserver mode 18 | 19 | \code 20 | cd your_build_dir/tests/manual/compliance 21 | qmake your_src_dir/tests/manual/compliance/compliance.pro 22 | make 23 | 24 | cd ~ 25 | wstest -m fuzzingserver 26 | \endcode 27 | 28 | Then, in another terminal: 29 | 30 | \code 31 | cd your_build_dir/tests/manual/compliance 32 | ./tst_compliance 33 | \endcode 34 | 35 | Test results will be generated under ~/reports/clients directory. 36 | Point your browser to ~/reports/clients/index.html. 37 | 38 | 39 | \section2 wstest - fuzzingclient mode 40 | 41 | \code 42 | cd your_build_dir/examples/websockets/echoserver 43 | qmake your_src_dir/examples/websockets/echoserver/echoserver.pro 44 | make 45 | 46 | ./echoserver -p 9001 47 | \endcode 48 | 49 | Then, in another terminal: 50 | 51 | \code 52 | cd ~ 53 | wstest -m fuzzingclient 54 | \endcode 55 | 56 | Test results will be generated under ~/reports/servers directory. 57 | Point your browser to ~/reports/servers/index.html. 58 | //! [testsuite] 59 | -------------------------------------------------------------------------------- /examples/websockets/doc/qmlwebsocketclient.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example qmlwebsocketclient 6 | \title QML WebSocket Client 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief Explains how to write a QML WebSocket client example. 10 | 11 | The QML WebSocket Client example creates a secure and an 12 | insecure \l {Qt WebSockets}{WebSocket} connection to an echo 13 | server, using the QML API, and alternates between opening 14 | connections and closing them. Every time a connection has 15 | been opened, it sends a message. 16 | 17 | \image qmlwebsocketclient-example.webp QML WebSocket Client GUI 18 | 19 | This example opens a window with a welcome message. Every time 20 | the window is clicked on, it alternates between opening and 21 | closing two connections to an external echo server. The echo 22 | server used is at ws.ifelse.io, and an Internet connection is 23 | necessary for the example to work. Also TLS must be enabled for 24 | the secure connection to work. When the connection is opened or 25 | closed, the statusChanged signal is handled by the 26 | onStatusChanged handler. Every time the socket is opened, a 27 | message is sent, and every time the socket is closed, a message 28 | is logged in the window. In addition, there is an 29 | onTextMessageReceived handler that logs to the window the 30 | messages received from the server. 31 | */ 32 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketprotocol.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETPROTOCOL_H 6 | #define QWEBSOCKETPROTOCOL_H 7 | 8 | #if 0 9 | # pragma qt_class(QWebSocketProtocol) 10 | #endif 11 | 12 | #include 13 | #include "QtWebSockets/qwebsockets_global.h" 14 | 15 | QT_BEGIN_NAMESPACE 16 | 17 | class QString; 18 | 19 | namespace QWebSocketProtocol 20 | { 21 | enum Version 22 | { 23 | VersionUnknown = -1, 24 | Version0 = 0, 25 | //hybi-01, hybi-02 and hybi-03 not supported 26 | Version4 = 4, 27 | Version5 = 5, 28 | Version6 = 6, 29 | Version7 = 7, 30 | Version8 = 8, 31 | Version13 = 13, 32 | VersionLatest = Version13 33 | }; 34 | 35 | enum CloseCode 36 | { 37 | CloseCodeNormal = 1000, 38 | CloseCodeGoingAway = 1001, 39 | CloseCodeProtocolError = 1002, 40 | CloseCodeDatatypeNotSupported = 1003, 41 | CloseCodeReserved1004 = 1004, 42 | CloseCodeMissingStatusCode = 1005, 43 | CloseCodeAbnormalDisconnection = 1006, 44 | CloseCodeWrongDatatype = 1007, 45 | CloseCodePolicyViolated = 1008, 46 | CloseCodeTooMuchData = 1009, 47 | CloseCodeMissingExtension = 1010, 48 | CloseCodeBadOperation = 1011, 49 | CloseCodeTlsHandshakeFailed = 1015 50 | }; 51 | 52 | } //end namespace QWebSocketProtocol 53 | 54 | QT_END_NAMESPACE 55 | 56 | #endif // QWEBSOCKETPROTOCOL_H 57 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include 5 | #include 6 | #include "sslechoclient.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | using namespace Qt::Literals::StringLiterals; 11 | QCoreApplication a(argc, argv); 12 | 13 | QCommandLineParser parser; 14 | parser.setApplicationDescription("QtWebSockets example: sslechoclient"); 15 | parser.addHelpOption(); 16 | 17 | QCommandLineOption hostnameOption( 18 | QStringList{ u"n"_s, u"hostname"_s }, 19 | QCoreApplication::translate("main", "Hostname [default: localhost]."), "hostname", 20 | "localhost"); 21 | parser.addOption(hostnameOption); 22 | QCommandLineOption portOption(QStringList{ u"p"_s, u"port"_s }, 23 | QCoreApplication::translate("main", "Port [default: 1234]."), 24 | "port", "1234"); 25 | parser.addOption(portOption); 26 | 27 | parser.process(a); 28 | bool ok = true; 29 | int port = parser.value(portOption).toInt(&ok); 30 | if (!ok || port < 1 || port > 65535) { 31 | qWarning("Port invalid, must be a number between 1 and 65535\n%s", 32 | qPrintable(parser.helpText())); 33 | return 1; 34 | } 35 | QUrl url; 36 | url.setScheme(u"wss"_s); 37 | url.setHost(parser.value(hostnameOption)); 38 | url.setPort(port); 39 | SslEchoClient client(url); 40 | Q_UNUSED(client); 41 | 42 | return a.exec(); 43 | } 44 | -------------------------------------------------------------------------------- /tests/auto/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # This is an automatic test for the CMake configuration files. 5 | # To run it manually, 6 | # 1) mkdir build # Create a build directory 7 | # 2) cd build 8 | # 3) # Run cmake on this directory 9 | # `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..` 10 | # 4) ctest # Run ctest 11 | 12 | cmake_minimum_required(VERSION 3.16) 13 | project(websockets_cmake_tests) 14 | enable_testing() 15 | 16 | set(required_packages Core WebSockets) 17 | 18 | # Setup the test when called as a completely standalone project. 19 | if(TARGET Qt6::Core) 20 | # Tests are built as part of the repository's build tree. 21 | # Setup paths so that the Qt packages are found. 22 | qt_internal_set_up_build_dir_package_paths() 23 | endif() 24 | 25 | find_package(Qt6 REQUIRED COMPONENTS ${required_packages}) 26 | 27 | # Setup common test variables which were previously set by ctest_testcase_common.prf. 28 | set(CMAKE_MODULES_UNDER_TEST "${required_packages}") 29 | 30 | foreach(qt_package ${CMAKE_MODULES_UNDER_TEST}) 31 | set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}") 32 | if(${package_name}_FOUND) 33 | set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}") 34 | set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}") 35 | set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}") 36 | endif() 37 | endforeach() 38 | 39 | include("${_Qt6CTestMacros}") 40 | 41 | set(module_includes 42 | WebSockets QWebSocket 43 | ) 44 | 45 | _qt_internal_test_module_includes( 46 | ${module_includes} 47 | ) 48 | -------------------------------------------------------------------------------- /tests/auto/websockets/shared/localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAuBqAeoSpavhYf4wUFAT4FZmuLlRSf9A85E3alQHWVYzN4MIz 3 | lgxz8PV2FQbvODkj1A7lS3VhyhU7bk4Cx512BVogVc83IQbadRPPnfHHenKqnda1 4 | CRgJEBDMjwogUjMFIP6ck2X7yAGV3sV77h3xsULB9eylAEnZFjxJDq2NEVUoc3uF 5 | ouwP5ZXcAWCyJaQLF5fFUs0jr1y4vBXtsSy/pTU3XI1E69Gm7jIlxo2e7fqQkVs5 6 | E+E1/LqokZeLQDfR1h0yguG0I3dB/9fAbJLzhGzZdd242UF1SBumW5javbHcbPfa 7 | EjCwcdw/Nfo72fBU9DyTb2V8LzI+YBYD28+IFQIDAQABAoIBADADmWZamuSvCEWb 8 | ftEJyrm3btneW/XBlV/lfhBGfmOpaTgo7dNARCyfl8A8Ir+DB3kSuXJIlsxhZTKL 9 | XeY5hsI2kyBN/o66ftbx57/FgsTIiv7HNEe+4P4zo2Xaujs12yyTuromatfqse97 10 | iaq8XIBibLt6kD3XBKrr5hHR6WyPW9F7sM91e/1OGTXBt9URvnnHqcimJ8Wvto5p 11 | SMFlud8JXMmARhWaIfqQIcNYmNEHea0LfOZVerTOPE7IZd5coM91mr71lzoxs9Ik 12 | bRMbqgyAMXEJV3ynEH2LjjJZo1bVb8Va45QqqOQ4FtL46n1Z+EVUXyhCHGepwyOv 13 | uAru0wECgYEA3CnM252417At+N9Zq4KtBJ8tIEXKqvK1Bl5aZSqaJClywjCttR2l 14 | lRAlIRAmqHCQuxLDDfLfiJh6xgZsjr4MhksuyKc7DKssfWW+XCd+5GaaMoMvJXhs 15 | caJdhNSHzpnLPi++tJBYHwHa354D5PJ3eItzLkmuVyhmc3plNbkBGLECgYEA1hIX 16 | mA9KadVG9VkaDci+xo1p0ACb5ccHAvmA8+fzb0H09yKw5bCSpNGeHj4Qv5ZFqsUm 17 | 96NWYEB38ezupWqWMFd9zr1kD2s3r6Kpq1TS6xuDPapyiXaKpcH1ys7IWZkinCkN 18 | oxhPHcQbFu9/CN2zIVFKvF5P98Rh0+wO7fgL/qUCgYAyleAd7cVUuYQ2lIrz31iF 19 | oVUq/x4r3Qw+5Fr8t6cm++cEO08OODudXlJJoH5hYUu/z/XFNLKrne1Hpp42xe/2 20 | wzuCmvn0VTgpr8DnR6PeMrznMkEY6Oxxx46ZQIPbsnaCWVIGBsxYg4KYsqPObO+K 21 | YPAcCI3oNL4ldk/e4h0gYQKBgHm+4FxClfeKrEhs3DxqptUVJ9B8CC2t+3bdn1EX 22 | 4YKs6DyFJkX7HetOq7ZXZf8P3583cOn1ovIquAyGy1KYQ8JKf+pMG9QJDip9QDGI 23 | lEvR4dn4ThuPp1qN7NPitl7+kIhvcKoI8TXkieOJYZ4ROAcCzJZErQYkUd7MqdD8 24 | +RVhAoGAcWC9HRDhxjs4shaBlYi8Lfp3dV4f/4UgYosdFAZ26atwHz+sCLHwwg1j 25 | 6t5Zxy9oEB89S5v5hkgO8//JmopvISSokdvocASMdKE+OmS3JfBmhQK9qVBW/vv/ 26 | ut2bhPjEzIJyNFKX3xnGI8PREcR2eY+WLhIZ5KiR61tGpktJ4bg= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /dist/changes-5.14.0: -------------------------------------------------------------------------------- 1 | Qt 5.14 introduces many new features and improvements as well as bugfixes 2 | over the 5.13.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 8 | Applications compiled for 5.13 will continue to run with 5.14. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebSocket * 20 | **************************************************************************** 21 | 22 | - [QTBUG-74464] QWebSocket no longer marks the connection as timed out 23 | if it cannot read a whole message within 5 seconds. It will also no 24 | longer block for up to 5 seconds when receiving a message. 25 | 26 | **************************************************************************** 27 | * QWebSocketServer * 28 | **************************************************************************** 29 | 30 | - [QTBUG-57026] [QTBUG-63312] Handshake timeout 31 | * Added a timeout to the websocket handshake, 10 seconds by default. 32 | * Call setHandshakeTimeout() to change the maximum duration. 33 | Negative values mean it will not time out. 34 | * handshakeTimeout() and handshakeTimeoutMS() can be used to query the 35 | current timeout duration. 36 | -------------------------------------------------------------------------------- /dist/changes-5.7.0: -------------------------------------------------------------------------------- 1 | Qt 5.7 introduces many new features and improvements as well as bugfixes 2 | over the 5.6.x series. Also, there is a change in the licensing terms. 3 | For more details, refer to the online documentation included in this 4 | distribution. The documentation is also available online: 5 | 6 | http://doc.qt.io/qt-5.7 7 | 8 | The Qt version 5.7 series is binary compatible with the 5.6.x series. 9 | Applications compiled for 5.6 will continue to run with 5.7. 10 | 11 | Some of the changes listed in this file include issue tracking numbers 12 | corresponding to tasks in the Qt Bug Tracker: 13 | 14 | http://bugreports.qt.io/ 15 | 16 | Each of these identifiers can be entered in the bug tracker to obtain more 17 | information about a particular change. 18 | 19 | **************************************************************************** 20 | * Important License Changes * 21 | **************************************************************************** 22 | 23 | This module is no longer available under LGPLv2.1. The libraries are 24 | now available under the following licenses: 25 | * Commercial License 26 | * GNU General Public License v2.0 (LICENSE.GPL2) and later 27 | * GNU Lesser General Public License v3.0 (LICENSE.LGPL3) 28 | 29 | The tools are now available under the following licenses: 30 | * Commercial License 31 | * GNU General Public License 3.0 (LICENSE.GPL3) with exceptions 32 | described in The Qt Company GPL Exception 1.0 (LICENSE.GPL3-EXCEPT) 33 | 34 | **************************************************************************** 35 | * General * 36 | **************************************************************************** 37 | - This release contains only minor improvements. 38 | -------------------------------------------------------------------------------- /dist/changes-5.12.0: -------------------------------------------------------------------------------- 1 | Qt 5.12 introduces many new features and improvements as well as bugfixes 2 | over the 5.11.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 8 | Applications compiled for 5.11 will continue to run with 5.12. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebSocket * 20 | **************************************************************************** 21 | 22 | - Added the bytesToWrite function to QWebSocket. Call this function to see 23 | how many bytes are left to write. 24 | 25 | **************************************************************************** 26 | * QWebSocketServer * 27 | **************************************************************************** 28 | 29 | - Introduced nativeDescriptor and setNativeDescriptor. These functions are 30 | replacing socketDescriptor and setSocketDescriptor which are now 31 | deprecated. 32 | 33 | **************************************************************************** 34 | * Platform Specific Changes * 35 | **************************************************************************** 36 | 37 | Wasm 38 | ----- 39 | - [QTBUG-70339] Add support for WebSockets on Qt for WASM 40 | -------------------------------------------------------------------------------- /dist/changes-5.9.0: -------------------------------------------------------------------------------- 1 | Qt 5.9 introduces many new features and improvements as well as bugfixes 2 | over the 5.8.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 8 | Applications compiled for 5.8 will continue to run with 5.9. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Library * 20 | **************************************************************************** 21 | 22 | - QWebSocketServer 23 | * [QTBUG-56129] SslMode::NonSecure enumerator now always has the same 24 | value (1) regardless of SSL being enabled or disabled. 25 | * [QTBUG-54276] Added a member function to handle external QTcpSocket, 26 | upgrading it to a QWebSocket. 27 | * [QTBUG-56414] Server now deletes a websocket when a 'disconnected' 28 | signal is received. 29 | - QWebSocketHandshakeRequest 30 | [QTBUG-57357] Fixed the parsing of port in handshake requests. 31 | - QWebSocketDataProcessor 32 | [QTBUG-55506] Call clear() before emitting textMessageReceived or 33 | binaryMessageReceived to avoid data corruption in case a slot blocks 34 | (for example, entering a nested modal loop while showing this message) 35 | while socket receives more data. 36 | - QQmlWebSocket 37 | * [QTBUG-58278] Fix setUrl: only call open() if the 'active' property is 38 | true. 39 | 40 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/sslechoclient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "sslechoclient.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | QT_USE_NAMESPACE 10 | 11 | //! [constructor] 12 | SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) : 13 | QObject(parent) 14 | { 15 | connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected); 16 | connect(&m_webSocket, QOverload&>::of(&QWebSocket::sslErrors), 17 | this, &SslEchoClient::onSslErrors); 18 | 19 | QSslConfiguration sslConfiguration; 20 | QFile certFile(QStringLiteral(":/localhost.cert")); 21 | certFile.open(QIODevice::ReadOnly); 22 | QSslCertificate certificate(&certFile, QSsl::Pem); 23 | certFile.close(); 24 | sslConfiguration.addCaCertificate(certificate); 25 | m_webSocket.setSslConfiguration(sslConfiguration); 26 | 27 | m_webSocket.open(url); 28 | } 29 | //! [constructor] 30 | 31 | //! [onConnected] 32 | void SslEchoClient::onConnected() 33 | { 34 | qDebug() << "WebSocket connected"; 35 | connect(&m_webSocket, &QWebSocket::textMessageReceived, 36 | this, &SslEchoClient::onTextMessageReceived); 37 | m_webSocket.sendTextMessage(QStringLiteral("Hello, world!")); 38 | } 39 | //! [onConnected] 40 | 41 | //! [onTextMessageReceived] 42 | void SslEchoClient::onTextMessageReceived(QString message) 43 | { 44 | qDebug() << "Message received:" << message; 45 | qApp->quit(); 46 | } 47 | 48 | void SslEchoClient::onSslErrors(const QList &errors) 49 | { 50 | qWarning() << "SSL errors:" << errors; 51 | 52 | qApp->quit(); 53 | } 54 | //! [onTextMessageReceived] 55 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include 5 | #include 6 | #include "echoclient.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | using namespace Qt::Literals::StringLiterals; 11 | QCoreApplication a(argc, argv); 12 | 13 | QCommandLineParser parser; 14 | parser.setApplicationDescription("QtWebSockets example: echoclient"); 15 | parser.addHelpOption(); 16 | 17 | QCommandLineOption dbgOption( 18 | QStringList{ u"d"_s, u"debug"_s }, 19 | QCoreApplication::translate("main", "Debug output [default: off].")); 20 | parser.addOption(dbgOption); 21 | QCommandLineOption hostnameOption( 22 | QStringList{ u"n"_s, u"hostname"_s }, 23 | QCoreApplication::translate("main", "Hostname [default: localhost]."), "hostname", 24 | "localhost"); 25 | parser.addOption(hostnameOption); 26 | QCommandLineOption portOption(QStringList{ u"p"_s, u"port"_s }, 27 | QCoreApplication::translate("main", "Port [default: 1234]."), 28 | "port", "1234"); 29 | parser.addOption(portOption); 30 | 31 | parser.process(a); 32 | bool debug = parser.isSet(dbgOption); 33 | bool ok = true; 34 | int port = parser.value(portOption).toInt(&ok); 35 | if (!ok || port < 1 || port > 65535) { 36 | qWarning("Port invalid, must be a number between 1 and 65535\n%s", 37 | qPrintable(parser.helpText())); 38 | return 1; 39 | } 40 | QUrl url; 41 | url.setScheme(u"ws"_s); 42 | url.setHost(parser.value(hostnameOption)); 43 | url.setPort(port); 44 | EchoClient client(url, debug); 45 | QObject::connect(&client, &EchoClient::closed, &a, &QCoreApplication::quit); 46 | 47 | return a.exec(); 48 | } 49 | -------------------------------------------------------------------------------- /src/websockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websockets.pro. 5 | 6 | ##################################################################### 7 | ## WebSockets Module: 8 | ##################################################################### 9 | 10 | qt_internal_add_module(WebSockets 11 | SOURCES 12 | qdefaultmaskgenerator_p.cpp qdefaultmaskgenerator_p.h 13 | qmaskgenerator.cpp qmaskgenerator.h 14 | qwebsocket.cpp qwebsocket.h qwebsocket_p.cpp qwebsocket_p.h 15 | qwebsocketcorsauthenticator.cpp qwebsocketcorsauthenticator.h qwebsocketcorsauthenticator_p.h 16 | qwebsocketdataprocessor.cpp qwebsocketdataprocessor_p.h 17 | qwebsocketframe.cpp qwebsocketframe_p.h 18 | qwebsockethandshakeoptions.cpp qwebsockethandshakeoptions.h qwebsockethandshakeoptions_p.h 19 | qwebsockethandshakerequest.cpp qwebsockethandshakerequest_p.h 20 | qwebsockethandshakeresponse.cpp qwebsockethandshakeresponse_p.h 21 | qwebsocketprotocol.cpp qwebsocketprotocol.h qwebsocketprotocol_p.h 22 | qwebsockets_global.h 23 | qwebsocketserver.cpp qwebsocketserver.h qwebsocketserver_p.cpp qwebsocketserver_p.h 24 | DEFINES 25 | QT_NO_CONTEXTLESS_CONNECT 26 | LIBRARIES 27 | Qt::CorePrivate 28 | Qt::NetworkPrivate 29 | PUBLIC_LIBRARIES 30 | Qt::Core 31 | Qt::Network 32 | PRIVATE_MODULE_INTERFACE 33 | Qt::CorePrivate 34 | ) 35 | 36 | #### Keys ignored in scope 1:.:.:websockets.pro:: 37 | # OTHER_FILES = "doc/src/*.qdoc" "doc/snippets/*.cpp" "doc/qtwebsockets.qdocconf" 38 | 39 | ## Scopes: 40 | ##################################################################### 41 | 42 | qt_internal_extend_target(WebSockets CONDITION WASM 43 | SOURCES 44 | qwebsocket_wasm_p.cpp 45 | LIBRARIES 46 | websocket.js 47 | ) 48 | 49 | qt_internal_add_docs(WebSockets 50 | doc/qtwebsockets.qdocconf 51 | ) 52 | 53 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeoptions.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETHANDSHAKEOPTIONS_H 6 | #define QWEBSOCKETHANDSHAKEOPTIONS_H 7 | 8 | #include 9 | #include 10 | 11 | #include "QtWebSockets/qwebsockets_global.h" 12 | 13 | QT_BEGIN_NAMESPACE 14 | 15 | class QWebSocketHandshakeOptionsPrivate; 16 | 17 | QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(QWebSocketHandshakeOptionsPrivate, Q_WEBSOCKETS_EXPORT) 18 | 19 | class Q_WEBSOCKETS_EXPORT QWebSocketHandshakeOptions 20 | { 21 | public: 22 | QWebSocketHandshakeOptions(); 23 | QWebSocketHandshakeOptions(const QWebSocketHandshakeOptions &other); 24 | QWebSocketHandshakeOptions(QWebSocketHandshakeOptions &&other) noexcept = default; 25 | ~QWebSocketHandshakeOptions(); 26 | 27 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QWebSocketHandshakeOptions) 28 | QWebSocketHandshakeOptions &operator=(const QWebSocketHandshakeOptions &other); 29 | 30 | void swap(QWebSocketHandshakeOptions &other) noexcept { d.swap(other.d); } 31 | 32 | QStringList subprotocols() const; 33 | void setSubprotocols(const QStringList &protocols); 34 | 35 | private: 36 | bool equals(const QWebSocketHandshakeOptions &other) const; 37 | 38 | friend bool operator==(const QWebSocketHandshakeOptions &lhs, 39 | const QWebSocketHandshakeOptions &rhs) { return lhs.equals(rhs); } 40 | friend bool operator!=(const QWebSocketHandshakeOptions &lhs, 41 | const QWebSocketHandshakeOptions &rhs) { return !lhs.equals(rhs); } 42 | 43 | QSharedDataPointer d; 44 | friend class QWebSocketHandshakeOptionsPrivate; 45 | }; 46 | 47 | QT_END_NAMESPACE 48 | 49 | #endif // QWEBSOCKETHANDSHAKEOPTIONS_H 50 | -------------------------------------------------------------------------------- /tests/auto/websockets/shared/selfsigned.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFbTCCA1WgAwIBAgIUdy/GEmVgsYMDPqnEamjlX6pqbcswDQYJKoZIhvcNAQEL 3 | BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM 4 | GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAgFw0yNTA3MTYxNzM4NTZaGA8yMTI1 5 | MDYyMjE3Mzg1NlowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx 6 | ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCAiIwDQYJKoZIhvcN 7 | AQEBBQADggIPADCCAgoCggIBANcdolTc+jNqDl0434fyx7bjZ9AUd/WnNy3j6Qbn 8 | qkKcmDTJcvdmT2nGpNgEKiDFerDSTR2jRis4BKxzeS0EUlxZSVB3gsdVlBZH8g/i 9 | kIPSaQZbXdu7E5O03nmeqBtKYJU69SwASqVcZWYKXXabil2Qd25e/b2xGR6bu9c6 10 | 1HbJTwnNjTf7WXPIbkNIAfRiCzQ447mQu2+5nNnMpgAbV5VlBYsGpLv7cBrEoVqx 11 | sfhLLcP1oXLtYjQ1AWgxJ/h1yNuOuZK4f4zLqbWymLj1nJJ6oaOAYNGIhH5yXmeq 12 | BJOfV4d3/aWD5BP28edYp8GOU5Ux7eYa9zjcPORjEPTMaxF4IDw7etNqd64c9Zax 13 | J+BnTQbb+cjNZyu3Zsgdx2E/CkgTNed4TeLluLL4jHQIS6KmFdMDb1ToAH/BP3rT 14 | 1aA5nWicZ0OpAL4FlqefwB9lByoA9ba+8OBGgXaZ22wolJWXKE3Wbwu2dwHjOIbN 15 | Zr9xRQEVWi9oWiRquuI8yEHg0ZfZJ68CidoXO+O1QI8VRYQ1cGJwYfgimV5qaHcW 16 | mRg5aM+PpHrtD+6Cs10Df2Ju6vdBGl7CiPWYANTso1FEe+TlYKdW96pFVEAIN+qE 17 | s5dP9ACBtmCCcRfu0r6dnoiptDfLoNtMaZG/3jrH2zNCSIEaNnomSoFu5fEwqW5J 18 | wEa9AgMBAAGjUzBRMB0GA1UdDgQWBBQLLuKycgD553jfUXNiqo32G437QTAfBgNV 19 | HSMEGDAWgBQLLuKycgD553jfUXNiqo32G437QTAPBgNVHRMBAf8EBTADAQH/MA0G 20 | CSqGSIb3DQEBCwUAA4ICAQAhSmPqWevoi29EFbfZTGItbTU5YBBmU4+G8FVNarbc 21 | xTmziotBd569Q1einiuBoltfdH0kcmgrMVKazdwvXh+NyiOVugQKLL2Al46LsjwH 22 | cU4QTOVNLv8be7LUUs0/FFBRTtEbbIs5yPQ+pZ/MI5nr93qMRTLXVomt8O0ARd49 23 | nxlY4AgP/xzAOgR7hJZoCIEkNAtBqZU8g/OFHglC3SDQIwbJudx2QApdVxqzVNVt 24 | kAPmTce6kS0RsdwypE9P4TJ5qgXi0uVR1cLEanYc1nB28N+/ehtwklZMb/9PSv7q 25 | opGVnH+HFjMC5NQt6abMcT+gPH6+x+0QUc32cfvb5VqXBA8DBruwYIbBrVXUMJkI 26 | XeqwE3jd5MaUP/xt+ozBruam7Ys5LswgfF4sn1qqKlQvzf4ZifiRWDXToQezs7PM 27 | oSFUlWJaBOeULdoLzicxlGAfJlDkUF3HRZGJPCuZq+AwX7376OeJITbdSACJ4BkR 28 | PJxYWt/K4Y1i8Psvs0IRpxIUPIsA2JnyXphHEWICYZH1G8chNufHHzUOMHnKwcsp 29 | aDVfNume2yDA5/67KMylky4v0bYVsNnYDwb9mzctAGWqtQ428QeUhooS6CNgV/AD 30 | bVefV4V64x8ORfdB60C4/MEEwnpUDPUBbbOSw1Y3FnSBz7R2tabGMzLjqsy2BhJv 31 | ow== 32 | -----END CERTIFICATE----- 33 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | import QtQuick 5 | import QtWebSockets 6 | 7 | Rectangle { 8 | width: 360 9 | height: 360 10 | 11 | function appendMessage(message) { 12 | messageBox.text += "\n" + message 13 | } 14 | 15 | WebSocketServer { 16 | id: server 17 | listen: true 18 | onClientConnected: function(webSocket) { 19 | webSocket.onTextMessageReceived.connect(function(message) { 20 | appendMessage(qsTr("Server received message: %1").arg(message)); 21 | webSocket.sendTextMessage(qsTr("Hello Client!")); 22 | }); 23 | } 24 | onErrorStringChanged: { 25 | appendMessage(qsTr("Server error: %1").arg(errorString)); 26 | } 27 | } 28 | 29 | WebSocket { 30 | id: socket 31 | url: server.url 32 | onTextMessageReceived: function(message) { 33 | appendMessage(qsTr("Client received message: %1").arg(message)); 34 | } 35 | onStatusChanged: { 36 | if (socket.status == WebSocket.Error) { 37 | appendMessage(qsTr("Client error: %1").arg(socket.errorString)); 38 | } else if (socket.status == WebSocket.Closed) { 39 | appendMessage(qsTr("Client socket closed.")); 40 | } 41 | } 42 | } 43 | 44 | Timer { 45 | interval: 100 46 | running: true 47 | onTriggered: { 48 | socket.active = true; 49 | } 50 | } 51 | 52 | Text { 53 | id: messageBox 54 | text: qsTr("Click to send a message!") 55 | anchors.fill: parent 56 | 57 | MouseArea { 58 | anchors.fill: parent 59 | onClicked: { 60 | socket.sendTextMessage(qsTr("Hello Server!")); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/websockets/qmaskgenerator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | /*! 6 | \class QMaskGenerator 7 | 8 | \inmodule QtWebSockets 9 | \since 5.3 10 | 11 | \brief The QMaskGenerator class provides an abstract base for custom 32-bit mask generators. 12 | 13 | The WebSockets specification as outlined in \l {RFC 6455} 14 | requires that all communication from client to server be masked. This is to prevent 15 | malicious scripts from attacking badly behaving proxies. 16 | For more information about the importance of good masking, 17 | see \l {"Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al}. 18 | By default QWebSocket uses the reasonably secure QRandomGenerator::global()->generate() function. 19 | The best measure against attacks mentioned in the document above, 20 | is to use QWebSocket over a secure connection (\e wss://). 21 | In general, always be careful to not have 3rd party script access to 22 | a QWebSocket in your application. 23 | */ 24 | 25 | /*! 26 | \fn bool QMaskGenerator::seed() 27 | 28 | Initializes the QMaskGenerator by seeding the randomizer. 29 | When seed() is not called, it depends on the specific implementation of a subclass if 30 | a default seed is used or no seed is used at all. 31 | Returns \e true if seeding succeeds, otherwise false. 32 | */ 33 | 34 | /*! 35 | \fn quint32 QMaskGenerator::nextMask() 36 | 37 | Returns a new random 32-bit mask. The randomness depends on the RNG used to created the 38 | mask. 39 | */ 40 | 41 | #include "qmaskgenerator.h" 42 | 43 | QT_BEGIN_NAMESPACE 44 | 45 | /*! 46 | Creates a new QMaskGenerator object with the given optional QObject \a parent. 47 | */ 48 | QMaskGenerator::QMaskGenerator(QObject *parent) : 49 | QObject(parent) 50 | { 51 | } 52 | 53 | /*! 54 | Destroys the QMaskGenerator object. 55 | */ 56 | QMaskGenerator::~QMaskGenerator() 57 | {} 58 | 59 | QT_END_NAMESPACE 60 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/localhost.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFuzCCA6OgAwIBAgIUMrxsW65722LF1Monsslw8osKQPowDQYJKoZIhvcNAQEN 3 | BQAwbTELMAkGA1UEBhMCTk8xDTALBgNVBAgMBE9zbG8xDTALBgNVBAcMBE9zbG8x 4 | FzAVBgNVBAoMDlRoZSBRdCBQcm9qZWN0MRMwEQYDVQQLDApXZWJTb2NrZXRzMRIw 5 | EAYDVQQDDAlsb2NhbGhvc3QwHhcNMjQwMzE4MTExNDU0WhcNMjUwMzE4MTExNDU0 6 | WjBtMQswCQYDVQQGEwJOTzENMAsGA1UECAwET3NsbzENMAsGA1UEBwwET3NsbzEX 7 | MBUGA1UECgwOVGhlIFF0IFByb2plY3QxEzARBgNVBAsMCldlYlNvY2tldHMxEjAQ 8 | BgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIB 9 | ALWkKxZ2Gfv6YKz/jvl8uu8BSb7JVqhP3A1xGysHYL1K4ctYSFQsCrf6gQawkO1B 10 | mZegqPHlMy3zWFXb5XLCrFwMJo69/9iYNidXj7jHHbBI/WW53wy7ZEW0m8qhVkU6 11 | ah6wa3iAP1/4U+ovC82T+7rXvqFUjbmrXUYfJftkznTYo79uUWUI7hRTYfPqzIE0 12 | 8KsiwTKnKEEetsv6fsm30h4hJA2XvDIxiShlOFgl6BWRTOE522k+Ykxf2NqVflnn 13 | +fF7u5VOL1sAELEW4P4p6lIbzDlAKOjr9JjgMPVS5o6bH/VO0W2IRRQ28gAHBdBl 14 | Z4ftOhsDb2kbpEb+ay72u2rcpB+/zDyrZ/KeU6hsbZX2ki5tBkPZj8/rRkylm6FH 15 | 3rkG1qfGfFZrhbh5lM3g4sVu6odlD8tAxToJTUjDotilcV0L1MzU3W1ATemILekA 16 | 4O7QTnTc1+EoaqoDQJiTWqWLFJLr6vHRkicfbSGSLJskJ+n9ahwC+kMSVAbD160v 17 | dEmgpXq2FiApXpy1YfqOFGKxAbUjELf/Qad5K+xaVbnM9McUzHrZFIM7UhvBSofN 18 | 3nkiG/ckWqsUKD+EyZLZARb0oF9p0qwlUb/SOXcXRFe4FyXehUzsEdxL4BOIJ5GU 19 | T/oezLmvhvUpDPqLRADDxkF2TXd3+h9O4zxN/nwK8ISvAgMBAAGjUzBRMB0GA1Ud 20 | DgQWBBTZA6a9VA+TrBU/vt6n78GAWW0XAjAfBgNVHSMEGDAWgBTZA6a9VA+TrBU/ 21 | vt6n78GAWW0XAjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDQUAA4ICAQCU 22 | +mA/ow0IHjFs0VYCHg/4YaSIzfiQPeyjlNCrcpQU3knUgJu63RUVz6+0+7VfadYL 23 | /Y2A8e7YNuxw0vabzxxdx2+PO9Jh0U1ho7JUjbN7j4zuw0Rq1AlaMJ1OrNgMGB5M 24 | 0+HN/u6RyzV1Na/Ov8Ahj44a/S3oIO/fM8n2951BdsB2iTLitubU+vqfIGWIj6Zk 25 | MH3dgKWRd8mo8ZGmNfVZZ3RfNIY8oHv04yIhL/NDEdg2uKlNKuQ8OIeEGmd1PAJK 26 | xcjy+1Go1alNV2SNj7eNnyGyhWbe20EKkg3BaitJYZ6ZD15Wyx+dlnqPQOgo4xY5 27 | G3oSYH0eu2cq8+ZM1UCoB+DV5wSm6I3ema0ASShQkBCqLpu9LNHbABRIi5VXKowV 28 | Mwt6o2ZaaMHtkCydjalrW/BxswLNpX+CTjcMs2lbeloGt6oAaPYOuFVvkjsoMV9e 29 | zlDgrv9EJqT5/X3OauL57V4cptl9j3StS7v0Lfst/xY7E2TeQIcRZaA7Yz969VpF 30 | ulh5s0YClyWcrBu3kvcEexLrGGd294GBt+Sd+FxrE5xlkm5FFadUJO1fFwwtxE3L 31 | BTNQ9USZ64jWAu+ix1ZzWsii9bbuJEHnksHfDLJWaUlwRrp7Tdz6n0haYk0hkbVP 32 | YEIZHQymVHs7iFU7vfoFmlCv9xftgCMRzjI8BbVCQQ== 33 | -----END CERTIFICATE----- 34 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakerequest_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETHANDSHAKEREQUEST_P_H 6 | #define QWEBSOCKETHANDSHAKEREQUEST_P_H 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "qwebsocketprotocol.h" 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class QTextStream; 30 | 31 | class Q_AUTOTEST_EXPORT QWebSocketHandshakeRequest 32 | { 33 | Q_DISABLE_COPY(QWebSocketHandshakeRequest) 34 | 35 | public: 36 | QWebSocketHandshakeRequest(int port, bool isSecure); 37 | virtual ~QWebSocketHandshakeRequest(); 38 | 39 | void clear(); 40 | 41 | int port() const; 42 | bool isSecure() const; 43 | bool isValid() const; 44 | QHttpHeaders headers() const; 45 | bool hasHeader(const QByteArray &name) const; 46 | QList versions() const; 47 | QString key() const; 48 | QString origin() const; 49 | QList protocols() const; 50 | QList extensions() const; 51 | QUrl requestUrl() const; 52 | QString resourceName() const; 53 | QString host() const; 54 | 55 | void readHandshake(QByteArrayView header, int maxHeaderLineLength); 56 | 57 | private: 58 | 59 | int m_port; 60 | bool m_isSecure; 61 | bool m_isValid; 62 | QHttpHeaderParser m_parser; 63 | QList m_versions; 64 | QString m_key; 65 | QString m_origin; 66 | QList m_protocols; 67 | QList m_extensions; 68 | QUrl m_requestUrl; 69 | }; 70 | 71 | QT_END_NAMESPACE 72 | 73 | #endif // QWEBSOCKETHANDSHAKEREQUEST_P_H 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Qt WebSockets 2 | 3 | ### Package Brief 4 | 5 | `QtWebSockets` is a pure Qt implementation of WebSockets - both client and server. 6 | It is implemented as a Qt add-on module that can easily be embedded into existing Qt projects. 7 | Its only dependency is Qt. 8 | 9 | ### Documentation 10 | 11 | The documentation can be found in the following places: 12 | * The online Qt documentation: 13 | * [Qt WebSockets documentation](https://doc.qt.io/qt-6/qtwebsockets-index.html) 14 | * Build from source: 15 | * [Building Qt Documentation](https://wiki.qt.io/Building_Qt_Documentation) 16 | 17 | *Note that the documentation links in this document will always be for the 18 | latest Qt 6 version. If you need to browse the documentation for a specific 19 | version, you can [browse the archives](https://doc.qt.io/archives/).* 20 | 21 | ### Features 22 | 23 | * Client and server capable 24 | * Text and binary sockets 25 | * Frame-based and message-based signals 26 | * Strict Unicode checking 27 | * WSS and proxy support 28 | 29 | ### Compliance 30 | 31 | `QtWebSockets` is compliant with [RFC6455](http://datatracker.ietf.org/doc/rfc6455/?include_text=1) and has been tested with the [Autobahn Testsuite](http://autobahn.ws/testsuite). 32 | 33 | ### Missing Features 34 | 35 | * Extensions 36 | 37 | ### Build Process 38 | 39 | Building the package/repository does depend on the Qt packages listed in dependencies.yaml. 40 | Further dependencies to system packages are listed in the configure output. 41 | 42 | See the [documentation](https://doc.qt.io/qt-6/build-sources.html) for general 43 | advice on building the Qt framework and its modules from sources. Further 44 | information on how to build from source is also available in the 45 | [wiki](https://wiki.qt.io/Building_Qt_6_from_Git). 46 | 47 | ### Report an Issue 48 | 49 | If you spot a bug, follow [these](https://doc.qt.io/qt-6/bughowto.html) 50 | steps to report it. 51 | 52 | ### Contribute to Qt 53 | 54 | We welcome contributions to Qt! If you'd like to contribute, read the 55 | [Qt Contribution Guidelines](https://wiki.qt.io/Qt_Contribution_Guidelines). 56 | 57 | ### Licensing 58 | 59 | Qt is available under various licenses. For details, check out the 60 | [license documentation](https://doc.qt.io/qt-6/licensing.html). 61 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | import QtQuick 4 | import QtWebSockets 5 | 6 | Rectangle { 7 | width: 640 8 | height: 360 9 | 10 | WebSocket { 11 | id: socket 12 | url: "ws://ws.ifelse.io" 13 | onTextMessageReceived: function(message) { 14 | messageBox.text = messageBox.text + "\nReceived message: " + message 15 | } 16 | onStatusChanged: if (socket.status == WebSocket.Error) { 17 | console.log("Error: " + socket.errorString) 18 | } else if (socket.status == WebSocket.Open) { 19 | socket.sendTextMessage("Hello World") 20 | } else if (socket.status == WebSocket.Closed) { 21 | messageBox.text += "\nSocket closed" 22 | } 23 | active: false 24 | } 25 | 26 | WebSocket { 27 | id: secureWebSocket 28 | url: "wss://ws.ifelse.io" 29 | onTextMessageReceived: function(message) { 30 | messageBox.text = messageBox.text + "\nReceived secure message: " + message 31 | } 32 | onStatusChanged: if (secureWebSocket.status == WebSocket.Error) { 33 | console.log("Error: " + secureWebSocket.errorString) 34 | } else if (secureWebSocket.status == WebSocket.Open) { 35 | secureWebSocket.sendTextMessage("Hello Secure World") 36 | } else if (secureWebSocket.status == WebSocket.Closed) { 37 | messageBox.text += "\nSecure socket closed" 38 | } 39 | active: false 40 | } 41 | Text { 42 | id: messageBox 43 | text: socket.status == WebSocket.Open ? qsTr("Sending...") : qsTr("Welcome!") 44 | anchors.centerIn: parent 45 | } 46 | 47 | MouseArea { 48 | anchors.fill: parent 49 | onClicked: { 50 | socket.active = !socket.active 51 | secureWebSocket.active = !secureWebSocket.active; 52 | //Qt.quit(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/websockets/qdefaultmaskgenerator_p.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | /*! 5 | \class QDefaultMaskGenerator 6 | 7 | \inmodule QtWebSockets 8 | 9 | \brief The QDefaultMaskGenerator class provides the default mask generator for QtWebSockets. 10 | 11 | The WebSockets specification as outlined in \l {RFC 6455} 12 | requires that all communication from client to server must be masked. This is to prevent 13 | malicious scripts to attack bad behaving proxies. 14 | For more information about the importance of good masking, 15 | see \l {"Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al}. 16 | The default mask generator uses the reasonably secure QRandomGenerator::global()->generate() function. 17 | The best measure against attacks mentioned in the document above, 18 | is to use QWebSocket over a secure connection (\e wss://). 19 | In general, always be careful to not have 3rd party script access to 20 | a QWebSocket in your application. 21 | 22 | \internal 23 | */ 24 | 25 | #include "qdefaultmaskgenerator_p.h" 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | /*! 31 | Constructs a new QDefaultMaskGenerator with the given \a parent. 32 | 33 | \internal 34 | */ 35 | QDefaultMaskGenerator::QDefaultMaskGenerator(QObject *parent) : 36 | QMaskGenerator(parent) 37 | { 38 | } 39 | 40 | /*! 41 | Destroys the QDefaultMaskGenerator object. 42 | 43 | \internal 44 | */ 45 | QDefaultMaskGenerator::~QDefaultMaskGenerator() 46 | { 47 | } 48 | 49 | /*! 50 | \internal 51 | */ 52 | bool QDefaultMaskGenerator::seed() noexcept 53 | { 54 | return true; 55 | } 56 | 57 | /*! 58 | Generates a new random mask using the insecure QRandomGenerator::global()->generate() method. 59 | 60 | \internal 61 | */ 62 | quint32 QDefaultMaskGenerator::nextMask() noexcept 63 | { 64 | quint32 value = QRandomGenerator::global()->generate(); 65 | while (Q_UNLIKELY(value == 0)) { 66 | // a mask of zero has a special meaning 67 | value = QRandomGenerator::global()->generate(); 68 | } 69 | return value; 70 | } 71 | 72 | QT_END_NAMESPACE 73 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["src/imports/qmlwebsockets/plugins.qmltypes"] 5 | precedence = "closest" 6 | comment = "source and plugins" 7 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only" 9 | 10 | [[annotations]] 11 | path = ["tests/**.txt", "tests/**.cert", "tests/**.key"] 12 | precedence = "closest" 13 | comment = "test" 14 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 15 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GPL-3.0-only" 16 | 17 | [[annotations]] 18 | path = ["**.pro", ".cmake.conf", "**.yaml", "**.json", "**.cfg", "**BLACKLIST", ".tag"] 19 | precedence = "closest" 20 | comment = "build system" 21 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 22 | SPDX-License-Identifier = "BSD-3-Clause" 23 | 24 | [[annotations]] 25 | path = ["**/.gitattributes", "**.gitignore", "**.gitreview"] 26 | precedence = "closest" 27 | comment = "version control system. Infrastructure" 28 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 29 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 30 | 31 | [[annotations]] 32 | path = ["examples/**"] 33 | comment = "this must be after the build system table because example and snippets take precedence over build system" 34 | precedence = "closest" 35 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 36 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 37 | 38 | [[annotations]] 39 | path = ["**/doc/images/**", "**/README*", "**.qdocconf"] 40 | comment = "documentation" 41 | precedence = "closest" 42 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 43 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 44 | 45 | [[annotations]] 46 | path = ["**.toml", "licenseRule.json"] 47 | precedence = "override" 48 | comment = "infrastructure" 49 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 50 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 51 | 52 | [[annotations]] 53 | path = ["**/qt_attribution.json"] 54 | precedence = "override" 55 | comment = "documentation" 56 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 57 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 58 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketprotocol_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETPROTOCOL_P_H 6 | #define QWEBSOCKETPROTOCOL_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include "QtWebSockets/qwebsocketprotocol.h" 21 | 22 | #include 23 | 24 | QT_BEGIN_NAMESPACE 25 | 26 | class QByteArray; 27 | 28 | namespace QWebSocketProtocol 29 | { 30 | enum OpCode 31 | { 32 | OpCodeContinue = 0x0, 33 | OpCodeText = 0x1, 34 | OpCodeBinary = 0x2, 35 | OpCodeReserved3 = 0x3, 36 | OpCodeReserved4 = 0x4, 37 | OpCodeReserved5 = 0x5, 38 | OpCodeReserved6 = 0x6, 39 | OpCodeReserved7 = 0x7, 40 | OpCodeClose = 0x8, 41 | OpCodePing = 0x9, 42 | OpCodePong = 0xA, 43 | OpCodeReservedB = 0xB, 44 | OpCodeReservedC = 0xC, 45 | OpCodeReservedD = 0xD, 46 | OpCodeReservedE = 0xE, 47 | OpCodeReservedF = 0xF 48 | }; 49 | 50 | inline bool isOpCodeReserved(OpCode code) 51 | { 52 | return ((code > OpCodeBinary) && (code < OpCodeClose)) || (code > OpCodePong); 53 | } 54 | 55 | inline bool isCloseCodeValid(int closeCode) 56 | { 57 | return (closeCode > 999) && (closeCode < 5000) && 58 | (closeCode != CloseCodeReserved1004) && //see RFC6455 7.4.1 59 | (closeCode != CloseCodeMissingStatusCode) && 60 | (closeCode != CloseCodeAbnormalDisconnection) && 61 | ((closeCode >= 3000) || (closeCode < 1012)); 62 | } 63 | 64 | inline Version currentVersion() { return VersionLatest; } 65 | Version Q_AUTOTEST_EXPORT versionFromString(QStringView versionString); 66 | 67 | void Q_AUTOTEST_EXPORT mask(QByteArray *payload, quint32 maskingKey); 68 | void Q_AUTOTEST_EXPORT mask(char *payload, quint64 size, quint32 maskingKey); 69 | } //end namespace QWebSocketProtocol 70 | 71 | QT_END_NAMESPACE 72 | 73 | #endif // QWEBSOCKETPROTOCOL_P_H 74 | -------------------------------------------------------------------------------- /dist/changes-5.5.0: -------------------------------------------------------------------------------- 1 | Qt 5.5 introduces many new features and improvements as well as bugfixes 2 | over the 5.4.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.5 series is binary compatible with the 5.4.x series. 8 | Applications compiled for 5.4 will continue to run with 5.5. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QML * 20 | **************************************************************************** 21 | 22 | - The import statement has changed from "import Qt.WebSockets 1.0" to 23 | "import QtWebSockets 1.0". The old statement is still supported, but it 24 | cannot be mixed with the new statement within the same project. 25 | 26 | **************************************************************************** 27 | * QtWebSockets * 28 | **************************************************************************** 29 | 30 | - QWebSocket: 31 | * [QTBUG-41285] Fixed QWebSocket's handling of query parameters with 32 | encoded characters 33 | * [QTBUG-42298] Added masking of ping from client side based on RFC 6455, 34 | Section 5.1. 35 | * [QTBUG-44893] Fixed spurious error signals on first connection 36 | * [QTBUG-44889] Fixed handling of url paths with encoded characters 37 | * [QTBUG-46055] Corrected the default port of secure hand shake request 38 | 39 | - QWebSocketServer: 40 | * [QTBUG-44866] Avoid hanging after an invalid SSL request 41 | * [QTBUG-45331] Fixed a crash when destroying the QWebSocketServer 42 | 43 | **************************************************************************** 44 | * Platform Specific Changes * 45 | **************************************************************************** 46 | 47 | WinRT 48 | ----- 49 | - [QTBUG-44491] Fixed the build for WinRT/ARM 50 | -------------------------------------------------------------------------------- /src/websockets/doc/src/external-resources.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \externalpage https://www.ieee-security.org/TC/W2SP/2011/papers/websocket.pdf 6 | \title "Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al 7 | */ 8 | 9 | /*! 10 | \externalpage https://datatracker.ietf.org/doc/html/rfc6454 11 | \title RFC 6454 12 | */ 13 | 14 | /*! 15 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455 16 | \title RFC 6455 17 | */ 18 | 19 | /*! 20 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-10 21 | \title WebSocket Security Considerations 22 | */ 23 | 24 | /*! 25 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-9 26 | \title WebSocket Extensions 27 | */ 28 | 29 | /*! 30 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-1.9 31 | \title WebSocket Subprotocols 32 | */ 33 | 34 | /*! 35 | \externalpage https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76 36 | \title hixie76 37 | */ 38 | 39 | /*! 40 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-00 41 | \title hybi-00 42 | */ 43 | 44 | /*! 45 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-04 46 | \title hybi-04 47 | */ 48 | 49 | /*! 50 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-05 51 | \title hybi-05 52 | */ 53 | 54 | /*! 55 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-07 56 | \title hybi-07 57 | */ 58 | 59 | /*! 60 | \externalpage https://github.com/google/pywebsocket/wiki/WebSocketProtocolSpec 61 | \title pywebsocket's WebSocketProtocolSpec 62 | */ 63 | 64 | /*! 65 | \externalpage https://github.com/crossbario/autobahn-testsuite 66 | \title Autobahn|Testsuite 67 | */ 68 | 69 | /*! 70 | \externalpage https://github.com/crossbario/autobahn-testsuite/blob/master/README.md#installation 71 | \title Autobahn|Testsuite installation documentation 72 | */ 73 | 74 | /*! 75 | \externalpage https://www.mozilla.org/firefox 76 | \title Firefox 77 | */ 78 | 79 | /*! 80 | \externalpage https://bugzilla.mozilla.org/show_bug.cgi?id=594502 81 | \title Firefox bug 594502 82 | */ 83 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "QtWebSockets/qwebsocketcorsauthenticator.h" 10 | 11 | QT_USE_NAMESPACE 12 | 13 | class tst_QWebSocketCorsAuthenticator : public QObject 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | tst_QWebSocketCorsAuthenticator(); 19 | 20 | private Q_SLOTS: 21 | void initTestCase(); 22 | void cleanupTestCase(); 23 | void init(); 24 | void cleanup(); 25 | 26 | void tst_initialization(); 27 | }; 28 | 29 | tst_QWebSocketCorsAuthenticator::tst_QWebSocketCorsAuthenticator() 30 | {} 31 | 32 | void tst_QWebSocketCorsAuthenticator::initTestCase() 33 | { 34 | } 35 | 36 | void tst_QWebSocketCorsAuthenticator::cleanupTestCase() 37 | {} 38 | 39 | void tst_QWebSocketCorsAuthenticator::init() 40 | { 41 | } 42 | 43 | void tst_QWebSocketCorsAuthenticator::cleanup() 44 | { 45 | } 46 | 47 | void tst_QWebSocketCorsAuthenticator::tst_initialization() 48 | { 49 | { 50 | QWebSocketCorsAuthenticator authenticator((QString())); 51 | 52 | QCOMPARE(authenticator.allowed(), true); 53 | QCOMPARE(authenticator.origin(), QString()); 54 | } 55 | { 56 | QWebSocketCorsAuthenticator authenticator(QStringLiteral("com.somesite")); 57 | 58 | QCOMPARE(authenticator.allowed(), true); 59 | QCOMPARE(authenticator.origin(), QStringLiteral("com.somesite")); 60 | 61 | QWebSocketCorsAuthenticator other(authenticator); 62 | QCOMPARE(other.origin(), authenticator.origin()); 63 | QCOMPARE(other.allowed(), authenticator.allowed()); 64 | 65 | authenticator.setAllowed(false); 66 | QVERIFY(!authenticator.allowed()); 67 | QCOMPARE(other.allowed(), true); //make sure other is a real copy 68 | 69 | authenticator.setAllowed(true); 70 | QVERIFY(authenticator.allowed()); 71 | 72 | authenticator.setAllowed(false); 73 | other = authenticator; 74 | QCOMPARE(other.origin(), authenticator.origin()); 75 | QCOMPARE(other.allowed(), authenticator.allowed()); 76 | } 77 | } 78 | 79 | QTEST_MAIN(tst_QWebSocketCorsAuthenticator) 80 | 81 | #include "tst_qwebsocketcorsauthenticator.moc" 82 | 83 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/chatserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "chatserver.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | using namespace std; 10 | 11 | QT_USE_NAMESPACE 12 | 13 | static QString getIdentifier(QWebSocket *peer) 14 | { 15 | return QStringLiteral("%1:%2").arg(peer->peerAddress().toString(), 16 | QString::number(peer->peerPort())); 17 | } 18 | 19 | //! [constructor] 20 | ChatServer::ChatServer(quint16 port, QObject *parent) : 21 | QObject(parent), 22 | m_pWebSocketServer(new QWebSocketServer(QStringLiteral("Chat Server"), 23 | QWebSocketServer::NonSecureMode, 24 | this)) 25 | { 26 | if (m_pWebSocketServer->listen(QHostAddress::Any, port)) 27 | { 28 | QTextStream(stdout) << "Chat Server listening on port " << port << '\n'; 29 | connect(m_pWebSocketServer, &QWebSocketServer::newConnection, 30 | this, &ChatServer::onNewConnection); 31 | } 32 | } 33 | 34 | ChatServer::~ChatServer() 35 | { 36 | m_pWebSocketServer->close(); 37 | } 38 | //! [constructor] 39 | 40 | //! [onNewConnection] 41 | void ChatServer::onNewConnection() 42 | { 43 | auto pSocket = m_pWebSocketServer->nextPendingConnection(); 44 | QTextStream(stdout) << getIdentifier(pSocket) << " connected!\n"; 45 | pSocket->setParent(this); 46 | 47 | connect(pSocket, &QWebSocket::textMessageReceived, 48 | this, &ChatServer::processMessage); 49 | connect(pSocket, &QWebSocket::disconnected, 50 | this, &ChatServer::socketDisconnected); 51 | 52 | m_clients << pSocket; 53 | } 54 | //! [onNewConnection] 55 | 56 | //! [processMessage] 57 | void ChatServer::processMessage(const QString &message) 58 | { 59 | QWebSocket *pSender = qobject_cast(sender()); 60 | for (QWebSocket *pClient : std::as_const(m_clients)) { 61 | if (pClient != pSender) //don't echo message back to sender 62 | pClient->sendTextMessage(message); 63 | } 64 | } 65 | //! [processMessage] 66 | 67 | //! [socketDisconnected] 68 | void ChatServer::socketDisconnected() 69 | { 70 | QWebSocket *pClient = qobject_cast(sender()); 71 | QTextStream(stdout) << getIdentifier(pClient) << " disconnected!\n"; 72 | if (pClient) 73 | { 74 | m_clients.removeAll(pClient); 75 | pClient->deleteLater(); 76 | } 77 | } 78 | //! [socketDisconnected] 79 | -------------------------------------------------------------------------------- /src/websockets/doc/src/index.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Kurt Pattyn 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebsockets-index.html 6 | \since 5.3 7 | \title Qt WebSockets 8 | \brief Provides an implementation of the WebSocket protocol. 9 | 10 | WebSocket is a web-based protocol designed to enable a two-way interactive 11 | communication session between a client application and a remote host. It 12 | enables the two entities to send data back and forth if the initial 13 | handshake succeeds. 14 | 15 | The Qt WebSockets module provides C++ and QML interfaces that enable 16 | Qt applications to act as a server that can process WebSocket requests, 17 | or a client that can consume data received from the server, or both. 18 | 19 | \section1 Using the Module 20 | 21 | \section2 QML API 22 | 23 | \include {module-use.qdocinc} {using the qml api} {QtWebSockets} 24 | 25 | \section2 C++ API 26 | 27 | \include {module-use.qdocinc} {using the c++ api} 28 | 29 | \section3 Building with CMake 30 | 31 | \include {module-use.qdocinc} {building with cmake} {WebSockets} 32 | 33 | \section3 Building with qmake 34 | 35 | \include {module-use.qdocinc} {building_with_qmake} {websockets} 36 | 37 | \section1 Examples 38 | 39 | \list 40 | \li \l {Qt WebSockets Examples} 41 | \endlist 42 | 43 | \section1 Reference 44 | 45 | \list 46 | \li \l {Qt WebSockets Overview} {Overview} 47 | \li \l {Qt WebSockets C++ Classes} {C++ Classes} 48 | \li \l {Qt WebSockets QML Types} {QML Types} 49 | \endlist 50 | 51 | \section1 Conformance 52 | 53 | \list 54 | \li \l {Testing Qt WebSockets} 55 | \endlist 56 | 57 | \section1 Licenses 58 | 59 | Qt WebSockets is available under commercial licenses from \l{The Qt Company}. 60 | In addition, it is available under free software licenses. Since Qt 5.4, 61 | these free software licenses are 62 | \l{GNU Lesser General Public License, version 3}, or 63 | the \l{GNU General Public License, version 2}. 64 | See \l{Qt Licensing} for further details. 65 | */ 66 | 67 | /*! 68 | \page qtwebsockets-testing.html 69 | \title Testing Qt WebSockets 70 | 71 | \l {Autobahn|Testsuite}, a standard test 72 | suite for WebSocket Protocol (\l{RFC 6455}), can be used for testing the 73 | conformance of Qt WebSockets. Refer to 74 | \l {Autobahn|Testsuite installation documentation} 75 | to set up the test suite. 76 | 77 | \include README.qdocinc testsuite 78 | */ 79 | -------------------------------------------------------------------------------- /tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "private/qwebsockethandshakerequest_p.h" 11 | #include "private/qwebsockethandshakeresponse_p.h" 12 | #include "private/qwebsocketprotocol_p.h" 13 | #include "QtWebSockets/qwebsocketprotocol.h" 14 | 15 | QT_USE_NAMESPACE 16 | 17 | Q_DECLARE_METATYPE(QWebSocketProtocol::CloseCode) 18 | Q_DECLARE_METATYPE(QWebSocketProtocol::OpCode) 19 | 20 | class tst_HandshakeResponse : public QObject 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | tst_HandshakeResponse(); 26 | 27 | private Q_SLOTS: 28 | void initTestCase(); 29 | void cleanupTestCase(); 30 | void init(); 31 | void cleanup(); 32 | 33 | void tst_date_response(); 34 | }; 35 | 36 | tst_HandshakeResponse::tst_HandshakeResponse() 37 | {} 38 | 39 | void tst_HandshakeResponse::initTestCase() 40 | { 41 | } 42 | 43 | void tst_HandshakeResponse::cleanupTestCase() 44 | {} 45 | 46 | void tst_HandshakeResponse::init() 47 | { 48 | qRegisterMetaType("QWebSocketProtocol::OpCode"); 49 | qRegisterMetaType("QWebSocketProtocol::CloseCode"); 50 | } 51 | 52 | void tst_HandshakeResponse::cleanup() 53 | { 54 | } 55 | 56 | void tst_HandshakeResponse::tst_date_response() 57 | { 58 | QWebSocketHandshakeRequest request(80, false); 59 | QByteArray bytes = "GET / HTTP/1.1\r\nHost: example.com\r\nSec-WebSocket-Version: 13\r\n" 60 | "Sec-WebSocket-Key: AVDFBDDFF\r\n" 61 | "Upgrade: websocket\r\n" 62 | "Connection: Upgrade\r\n\r\n"; 63 | request.readHandshake(bytes, 8 * 1024); 64 | 65 | QWebSocketHandshakeResponse response(request, "example.com", true, 66 | QList() << QWebSocketProtocol::Version13, 67 | QList(), 68 | QList()); 69 | QString data; 70 | QTextStream output(&data); 71 | output << response; 72 | 73 | QStringList list = data.split("\r\n"); 74 | int index = list.indexOf(QRegularExpression("Date:.*")); 75 | QVERIFY(index > -1); 76 | QVERIFY(QLocale::c().toDateTime(list[index], "'Date:' ddd, dd MMM yyyy hh:mm:ss 'GMT'").isValid()); 77 | } 78 | 79 | QTEST_MAIN(tst_HandshakeResponse) 80 | 81 | #include "tst_handshakeresponse.moc" 82 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "echoserver.h" 4 | #include "QtWebSockets/qwebsocketserver.h" 5 | #include "QtWebSockets/qwebsocket.h" 6 | #include 7 | 8 | QT_USE_NAMESPACE 9 | 10 | //! [constructor] 11 | EchoServer::EchoServer(quint16 port, bool debug, QObject *parent) : 12 | QObject(parent), 13 | m_pWebSocketServer(new QWebSocketServer(QStringLiteral("Echo Server"), 14 | QWebSocketServer::NonSecureMode, this)), 15 | m_debug(debug) 16 | { 17 | if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { 18 | if (m_debug) 19 | qDebug() << "Echoserver listening on port" << port; 20 | connect(m_pWebSocketServer, &QWebSocketServer::newConnection, 21 | this, &EchoServer::onNewConnection); 22 | connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &EchoServer::closed); 23 | } 24 | } 25 | //! [constructor] 26 | 27 | EchoServer::~EchoServer() 28 | { 29 | m_pWebSocketServer->close(); 30 | qDeleteAll(m_clients.begin(), m_clients.end()); 31 | } 32 | 33 | //! [onNewConnection] 34 | void EchoServer::onNewConnection() 35 | { 36 | QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); 37 | 38 | connect(pSocket, &QWebSocket::textMessageReceived, this, &EchoServer::processTextMessage); 39 | connect(pSocket, &QWebSocket::binaryMessageReceived, this, &EchoServer::processBinaryMessage); 40 | connect(pSocket, &QWebSocket::disconnected, this, &EchoServer::socketDisconnected); 41 | 42 | m_clients << pSocket; 43 | } 44 | //! [onNewConnection] 45 | 46 | //! [processTextMessage] 47 | void EchoServer::processTextMessage(QString message) 48 | { 49 | QWebSocket *pClient = qobject_cast(sender()); 50 | if (m_debug) 51 | qDebug() << "Message received:" << message; 52 | if (pClient) { 53 | pClient->sendTextMessage(message); 54 | } 55 | } 56 | //! [processTextMessage] 57 | 58 | //! [processBinaryMessage] 59 | void EchoServer::processBinaryMessage(QByteArray message) 60 | { 61 | QWebSocket *pClient = qobject_cast(sender()); 62 | if (m_debug) 63 | qDebug() << "Binary Message received:" << message; 64 | if (pClient) { 65 | pClient->sendBinaryMessage(message); 66 | } 67 | } 68 | //! [processBinaryMessage] 69 | 70 | //! [socketDisconnected] 71 | void EchoServer::socketDisconnected() 72 | { 73 | QWebSocket *pClient = qobject_cast(sender()); 74 | if (m_debug) 75 | qDebug() << "socketDisconnected:" << pClient; 76 | if (pClient) { 77 | m_clients.removeAll(pClient); 78 | pClient->deleteLater(); 79 | } 80 | } 81 | //! [socketDisconnected] 82 | -------------------------------------------------------------------------------- /tests/manual/compliance/tst_compliance.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class tst_ComplianceTest : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | private Q_SLOTS: 16 | void cleanupTestCase(); 17 | 18 | void autobahnTest_data(); 19 | void autobahnTest(); 20 | }; 21 | 22 | static const QUrl baseUrl { "ws://localhost:9001" }; 23 | static const auto agent = QStringLiteral("QtWebSockets/" QT_VERSION_STR); 24 | 25 | void tst_ComplianceTest::cleanupTestCase() 26 | { 27 | QWebSocket webSocket; 28 | QSignalSpy spy(&webSocket, &QWebSocket::disconnected); 29 | auto url = baseUrl; 30 | url.setPath(QStringLiteral("/updateReports")); 31 | QUrlQuery query; 32 | query.addQueryItem(QStringLiteral("agent"), agent); 33 | url.setQuery(query); 34 | webSocket.open(url); 35 | QVERIFY(spy.wait()); 36 | } 37 | 38 | void tst_ComplianceTest::autobahnTest_data() 39 | { 40 | QTest::addColumn("testCase"); 41 | 42 | // Ask /getCaseCount how many tests we have 43 | QWebSocket webSocket; 44 | QSignalSpy spy(&webSocket, &QWebSocket::disconnected); 45 | 46 | connect(&webSocket, &QWebSocket::textMessageReceived, [](QString message) { 47 | bool ok; 48 | const auto numberOfTestCases = message.toInt(&ok); 49 | if (!ok) 50 | QSKIP("Unable to parse /getCaseCount result"); 51 | for (auto i = 1; i <= numberOfTestCases; ++i) 52 | QTest::addRow("%d", i) << i; 53 | }); 54 | 55 | auto url = baseUrl; 56 | url.setPath(QStringLiteral("/getCaseCount")); 57 | webSocket.open(url); 58 | if (!spy.wait()) 59 | QSKIP("AutoBahn test server didn't deliver case-count"); 60 | } 61 | 62 | void tst_ComplianceTest::autobahnTest() 63 | { 64 | QFETCH(int, testCase); 65 | QWebSocket webSocket; 66 | QSignalSpy spy(&webSocket, &QWebSocket::disconnected); 67 | connect(&webSocket, &QWebSocket::textMessageReceived, 68 | &webSocket, &QWebSocket::sendTextMessage); 69 | connect(&webSocket, &QWebSocket::binaryMessageReceived, 70 | &webSocket, &QWebSocket::sendBinaryMessage); 71 | 72 | // Ask /runCase?case=&agent= to run the test-case. 73 | auto url = baseUrl; 74 | url.setPath(QStringLiteral("/runCase")); 75 | QUrlQuery query; 76 | query.addQueryItem(QStringLiteral("case"), QString::number(testCase)); 77 | query.addQueryItem(QStringLiteral("agent"), agent); 78 | url.setQuery(query); 79 | webSocket.open(url); 80 | QVERIFY(spy.wait()); 81 | } 82 | 83 | QTEST_MAIN(tst_ComplianceTest) 84 | 85 | #include "tst_compliance.moc" 86 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeresponse_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETHANDSHAKERESPONSE_P_H 6 | #define QWEBSOCKETHANDSHAKERESPONSE_P_H 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include 20 | #include "qwebsocketprotocol.h" 21 | #include "private/qglobal_p.h" 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | class QWebSocketHandshakeRequest; 26 | class QString; 27 | class QTextStream; 28 | 29 | class Q_AUTOTEST_EXPORT QWebSocketHandshakeResponse : public QObject 30 | { 31 | Q_OBJECT 32 | Q_DISABLE_COPY(QWebSocketHandshakeResponse) 33 | 34 | public: 35 | QWebSocketHandshakeResponse(const QWebSocketHandshakeRequest &request, 36 | const QString &serverName, 37 | bool isOriginAllowed, 38 | const QList &supportedVersions, 39 | const QList &supportedProtocols, 40 | const QList &supportedExtensions); 41 | 42 | ~QWebSocketHandshakeResponse() override; 43 | 44 | bool isValid() const; 45 | bool canUpgrade() const; 46 | QString acceptedProtocol() const; 47 | QString acceptedExtension() const; 48 | QWebSocketProtocol::Version acceptedVersion() const; 49 | 50 | QWebSocketProtocol::CloseCode error() const; 51 | QString errorString() const; 52 | 53 | private: 54 | bool m_isValid; 55 | bool m_canUpgrade; 56 | QString m_response; 57 | QString m_acceptedProtocol; 58 | QString m_acceptedExtension; 59 | QWebSocketProtocol::Version m_acceptedVersion; 60 | QWebSocketProtocol::CloseCode m_error; 61 | QString m_errorString; 62 | 63 | QString calculateAcceptKey(const QString &key) const; 64 | QString getHandshakeResponse(const QWebSocketHandshakeRequest &request, 65 | const QString &serverName, 66 | bool isOriginAllowed, 67 | const QList &supportedVersions, 68 | const QList &supportedProtocols, 69 | const QList &supportedExtensions); 70 | 71 | QTextStream &writeToStream(QTextStream &textStream) const; 72 | Q_AUTOTEST_EXPORT friend QTextStream & operator <<(QTextStream &stream, 73 | const QWebSocketHandshakeResponse &response); 74 | }; 75 | 76 | Q_AUTOTEST_EXPORT QTextStream & operator <<(QTextStream &stream, 77 | const QWebSocketHandshakeResponse &response); 78 | 79 | QT_END_NAMESPACE 80 | 81 | #endif // QWEBSOCKETHANDSHAKERESPONSE_P_H 82 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/qqmlwebsocketserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QQMLWEBSOCKETSERVER_H 6 | #define QQMLWEBSOCKETSERVER_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | QT_BEGIN_NAMESPACE 14 | 15 | class QQmlWebSocket; 16 | class QQmlWebSocketServer : public QObject, public QQmlParserStatus 17 | { 18 | Q_OBJECT 19 | Q_DISABLE_COPY(QQmlWebSocketServer) 20 | Q_INTERFACES(QQmlParserStatus) 21 | 22 | Q_PROPERTY(QUrl url READ url NOTIFY urlChanged) 23 | Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged) 24 | Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged) 25 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 26 | Q_PROPERTY(QStringList supportedSubprotocols READ supportedSubprotocols 27 | WRITE setSupportedSubprotocols NOTIFY supportedSubprotocolsChanged) 28 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) 29 | Q_PROPERTY(bool listen READ listen WRITE setListen NOTIFY listenChanged) 30 | Q_PROPERTY(bool accept READ accept WRITE setAccept NOTIFY acceptChanged) 31 | 32 | QML_NAMED_ELEMENT(WebSocketServer) 33 | QML_ADDED_IN_VERSION(1, 0) 34 | 35 | public: 36 | explicit QQmlWebSocketServer(QObject *parent = nullptr); 37 | ~QQmlWebSocketServer() override; 38 | 39 | void classBegin() override; 40 | void componentComplete() override; 41 | 42 | QUrl url() const; 43 | 44 | QString host() const; 45 | void setHost(const QString &host); 46 | 47 | int port() const; 48 | void setPort(int port); 49 | 50 | QString name() const; 51 | void setName(const QString &name); 52 | 53 | QStringList supportedSubprotocols() const; 54 | void setSupportedSubprotocols(const QStringList &supportedSubprotocols); 55 | 56 | QString errorString() const; 57 | 58 | bool listen() const; 59 | void setListen(bool listen); 60 | 61 | bool accept() const; 62 | void setAccept(bool accept); 63 | 64 | Q_SIGNALS: 65 | void clientConnected(QQmlWebSocket *webSocket); 66 | 67 | void errorStringChanged(const QString &errorString); 68 | void urlChanged(const QUrl &url); 69 | void portChanged(int port); 70 | void nameChanged(const QString &name); 71 | void supportedSubprotocolsChanged(const QStringList &supportedProtocols); 72 | void hostChanged(const QString &host); 73 | void listenChanged(bool listen); 74 | void acceptChanged(bool accept); 75 | 76 | private: 77 | void init(); 78 | void updateListening(); 79 | void newConnection(); 80 | void serverError(); 81 | void closed(); 82 | 83 | QScopedPointer m_server; 84 | QString m_host; 85 | QString m_name; 86 | QStringList m_supportedSubprotocols; 87 | int m_port; 88 | bool m_listen; 89 | bool m_accept; 90 | bool m_componentCompleted; 91 | 92 | }; 93 | 94 | QT_END_NAMESPACE 95 | 96 | #endif // QQMLWEBSOCKETSERVER_H 97 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketframe_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:critical reason:network-protocol 4 | 5 | #ifndef QWEBSOCKETFRAME_P_H 6 | #define QWEBSOCKETFRAME_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "qwebsockets_global.h" 25 | #include "qwebsocketprotocol.h" 26 | #include "qwebsocketprotocol_p.h" 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QIODevice; 31 | 32 | const quint64 MAX_FRAME_SIZE_IN_BYTES = std::numeric_limits::max() - 1; 33 | 34 | class Q_AUTOTEST_EXPORT QWebSocketFrame 35 | { 36 | Q_DECLARE_TR_FUNCTIONS(QWebSocketFrame) 37 | 38 | public: 39 | QWebSocketFrame() = default; 40 | 41 | void setMaxAllowedFrameSize(quint64 maxAllowedFrameSize); 42 | quint64 maxAllowedFrameSize() const; 43 | static quint64 maxFrameSize(); 44 | 45 | QWebSocketProtocol::CloseCode closeCode() const; 46 | QString closeReason() const; 47 | bool isFinalFrame() const; 48 | bool isControlFrame() const; 49 | bool isDataFrame() const; 50 | bool isContinuationFrame() const; 51 | bool hasMask() const; 52 | quint32 mask() const; //returns 0 if no mask 53 | inline bool rsv1() const { return m_rsv1; } 54 | inline bool rsv2() const { return m_rsv2; } 55 | inline bool rsv3() const { return m_rsv3; } 56 | QWebSocketProtocol::OpCode opCode() const; 57 | QByteArray payload() const; 58 | 59 | void clear(); 60 | 61 | bool isValid() const; 62 | bool isDone() const; 63 | 64 | void readFrame(QIODevice *pIoDevice); 65 | 66 | private: 67 | QString m_closeReason; 68 | QByteArray m_payload; 69 | quint64 m_length = 0; 70 | quint32 m_mask = 0; 71 | QWebSocketProtocol::CloseCode m_closeCode = QWebSocketProtocol::CloseCodeNormal; 72 | QWebSocketProtocol::OpCode m_opCode = QWebSocketProtocol::OpCodeReservedC; 73 | 74 | enum ProcessingState 75 | { 76 | PS_READ_HEADER, 77 | PS_READ_PAYLOAD_LENGTH, 78 | PS_READ_MASK, 79 | PS_READ_PAYLOAD, 80 | PS_DISPATCH_RESULT, 81 | PS_WAIT_FOR_MORE_DATA 82 | } m_processingState = PS_READ_HEADER; 83 | 84 | bool m_isFinalFrame = true; 85 | bool m_rsv1 = false; 86 | bool m_rsv2 = false; 87 | bool m_rsv3 = false; 88 | bool m_isValid = false; 89 | quint64 m_maxAllowedFrameSize = MAX_FRAME_SIZE_IN_BYTES; 90 | 91 | ProcessingState readFrameHeader(QIODevice *pIoDevice); 92 | ProcessingState readFramePayloadLength(QIODevice *pIoDevice); 93 | ProcessingState readFrameMask(QIODevice *pIoDevice); 94 | ProcessingState readFramePayload(QIODevice *pIoDevice); 95 | 96 | void setError(QWebSocketProtocol::CloseCode code, const QString &closeReason); 97 | bool checkValidity(); 98 | }; 99 | 100 | QT_END_NAMESPACE 101 | 102 | #endif // QWEBSOCKETFRAME_P_H 103 | -------------------------------------------------------------------------------- /tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "private/qdefaultmaskgenerator_p.h" 11 | 12 | QT_USE_NAMESPACE 13 | 14 | class tst_QDefaultMaskGenerator : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | tst_QDefaultMaskGenerator(); 20 | 21 | private Q_SLOTS: 22 | void initTestCase(); 23 | void cleanupTestCase(); 24 | void init(); 25 | void cleanup(); 26 | 27 | void tst_randomnessWithoutSeed(); 28 | void tst_randomnessWithSeed(); 29 | 30 | private: 31 | }; 32 | 33 | 34 | 35 | tst_QDefaultMaskGenerator::tst_QDefaultMaskGenerator() 36 | { 37 | } 38 | 39 | void tst_QDefaultMaskGenerator::initTestCase() 40 | { 41 | } 42 | 43 | void tst_QDefaultMaskGenerator::cleanupTestCase() 44 | { 45 | } 46 | 47 | void tst_QDefaultMaskGenerator::init() 48 | { 49 | } 50 | 51 | void tst_QDefaultMaskGenerator::cleanup() 52 | { 53 | } 54 | 55 | void tst_QDefaultMaskGenerator::tst_randomnessWithoutSeed() 56 | { 57 | //generate two series of data, and see if they differ 58 | { 59 | QDefaultMaskGenerator generator; 60 | 61 | QList series1, series2; 62 | for (int i = 0; i < 1000; ++i) 63 | series1 << generator.nextMask(); 64 | for (int i = 0; i < 1000; ++i) 65 | series2 << generator.nextMask(); 66 | 67 | QVERIFY(series1 != series2); 68 | } 69 | } 70 | 71 | void tst_QDefaultMaskGenerator::tst_randomnessWithSeed() 72 | { 73 | //generate two series of data, and see if they differ 74 | //the generator is seeded 75 | { 76 | QDefaultMaskGenerator generator; 77 | generator.seed(); 78 | 79 | QList series1, series2; 80 | for (int i = 0; i < 1000; ++i) 81 | series1 << generator.nextMask(); 82 | for (int i = 0; i < 1000; ++i) 83 | series2 << generator.nextMask(); 84 | 85 | QVERIFY(series1 != series2); 86 | } 87 | //generates two series of data with 2 distinct generators 88 | //both generators are seeded 89 | { 90 | QDefaultMaskGenerator generator1, generator2; 91 | generator1.seed(); 92 | generator2.seed(); 93 | 94 | QList series1, series2; 95 | for (int i = 0; i < 1000; ++i) { 96 | series1 << generator1.nextMask(); 97 | series2 << generator2.nextMask(); 98 | } 99 | 100 | QVERIFY(series1 != series2); 101 | } 102 | //generates two series of data with 2 distinct generators 103 | //only one of the two is seeded 104 | { 105 | QDefaultMaskGenerator generator1, generator2; 106 | generator1.seed(); 107 | 108 | QList series1, series2; 109 | for (int i = 0; i < 1000; ++i) { 110 | series1 << generator1.nextMask(); 111 | series2 << generator2.nextMask(); 112 | } 113 | 114 | QVERIFY(series1 != series2); 115 | } 116 | } 117 | 118 | QTEST_MAIN(tst_QDefaultMaskGenerator) 119 | 120 | #include "tst_defaultmaskgenerator.moc" 121 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketdataprocessor_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETDATAPROCESSOR_P_H 6 | #define QWEBSOCKETDATAPROCESSOR_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "qwebsocketframe_p.h" 25 | #include "qwebsocketprotocol.h" 26 | #include "qwebsocketprotocol_p.h" 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QIODevice; 31 | class QWebSocketFrame; 32 | 33 | const quint64 MAX_MESSAGE_SIZE_IN_BYTES = std::numeric_limits::max() - 1; 34 | 35 | class Q_AUTOTEST_EXPORT QWebSocketDataProcessor : public QObject 36 | { 37 | Q_OBJECT 38 | Q_DISABLE_COPY(QWebSocketDataProcessor) 39 | 40 | public: 41 | explicit QWebSocketDataProcessor(QObject *parent = nullptr); 42 | ~QWebSocketDataProcessor() override; 43 | 44 | void setMaxAllowedFrameSize(quint64 maxAllowedFrameSize); 45 | quint64 maxAllowedFrameSize() const; 46 | void setMaxAllowedMessageSize(quint64 maxAllowedMessageSize); 47 | quint64 maxAllowedMessageSize() const; 48 | static quint64 maxMessageSize(); 49 | static quint64 maxFrameSize(); 50 | 51 | void setIdleTimeout(std::chrono::milliseconds timeout); 52 | std::chrono::milliseconds idleTimeout() const; 53 | 54 | Q_SIGNALS: 55 | void pingReceived(const QByteArray &data); 56 | void pongReceived(const QByteArray &data); 57 | void closeReceived(QWebSocketProtocol::CloseCode closeCode, const QString &closeReason); 58 | void textFrameReceived(const QString &frame, bool lastFrame); 59 | void binaryFrameReceived(const QByteArray &frame, bool lastFrame); 60 | void textMessageReceived(const QString &message); 61 | void binaryMessageReceived(const QByteArray &message); 62 | void errorEncountered(QWebSocketProtocol::CloseCode code, const QString &description); 63 | 64 | public Q_SLOTS: 65 | bool process(QIODevice *pIoDevice); 66 | void clear(); 67 | 68 | private: 69 | enum 70 | { 71 | PS_READ_HEADER, 72 | PS_READ_PAYLOAD_LENGTH, 73 | PS_READ_BIG_PAYLOAD_LENGTH, 74 | PS_READ_MASK, 75 | PS_READ_PAYLOAD, 76 | PS_DISPATCH_RESULT 77 | } m_processingState; 78 | 79 | bool m_isFinalFrame; 80 | bool m_isFragmented; 81 | QWebSocketProtocol::OpCode m_opCode; 82 | bool m_isControlFrame; 83 | bool m_hasMask; 84 | quint32 m_mask; 85 | QByteArray m_binaryMessage; 86 | QString m_textMessage; 87 | quint64 m_payloadLength; 88 | QStringDecoder m_decoder; 89 | QWebSocketFrame frame; 90 | QChronoTimer *m_waitTimer; 91 | quint64 m_maxAllowedMessageSize = MAX_MESSAGE_SIZE_IN_BYTES; 92 | 93 | bool processControlFrame(const QWebSocketFrame &frame); 94 | void timeout(); 95 | }; 96 | 97 | QT_END_NAMESPACE 98 | 99 | #endif // QWEBSOCKETDATAPROCESSOR_P_H 100 | -------------------------------------------------------------------------------- /tests/auto/websockets/shared/selfsigned.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDXHaJU3Pozag5d 3 | ON+H8se242fQFHf1pzct4+kG56pCnJg0yXL3Zk9pxqTYBCogxXqw0k0do0YrOASs 4 | c3ktBFJcWUlQd4LHVZQWR/IP4pCD0mkGW13buxOTtN55nqgbSmCVOvUsAEqlXGVm 5 | Cl12m4pdkHduXv29sRkem7vXOtR2yU8JzY03+1lzyG5DSAH0Ygs0OOO5kLtvuZzZ 6 | zKYAG1eVZQWLBqS7+3AaxKFasbH4Sy3D9aFy7WI0NQFoMSf4dcjbjrmSuH+My6m1 7 | spi49ZySeqGjgGDRiIR+cl5nqgSTn1eHd/2lg+QT9vHnWKfBjlOVMe3mGvc43Dzk 8 | YxD0zGsReCA8O3rTaneuHPWWsSfgZ00G2/nIzWcrt2bIHcdhPwpIEzXneE3i5biy 9 | +Ix0CEuiphXTA29U6AB/wT9609WgOZ1onGdDqQC+BZann8AfZQcqAPW2vvDgRoF2 10 | mdtsKJSVlyhN1m8LtncB4ziGzWa/cUUBFVovaFokarriPMhB4NGX2SevAonaFzvj 11 | tUCPFUWENXBicGH4Ipleamh3FpkYOWjPj6R67Q/ugrNdA39ibur3QRpewoj1mADU 12 | 7KNRRHvk5WCnVveqRVRACDfqhLOXT/QAgbZggnEX7tK+nZ6IqbQ3y6DbTGmRv946 13 | x9szQkiBGjZ6JkqBbuXxMKluScBGvQIDAQABAoICAExB4JiF55pPV/07Gp7GdX8D 14 | eXs9rlLirsBxYVvFx0kq2xgna76BQdilBy3euBJ6/yXsv1Ko3UiX6Kw7mTLYq9u5 15 | +S/x1eYVE9ScN5bjAckBT6Llw82PsX50qUNi94QJJ1jvmBc7mTqqmPWF6iEQPYoy 16 | muwA96GFxPphScMgQ05CyeaXPB8i1tChNllajvrTwNYH7s6LHK8cFRrundA+4RsA 17 | P2lL9xz+ovySRQLyKD11ZSlpC41C0sPgIHoPpvRAyO3wWB/HkMvYLPbQ86vpwdH5 18 | cBCWg3v0EcgDgizsjAfK/kvzQPMqYLGlIpcZCgsnCcFDfGrMl2RMSrfJ2Kp3RuK5 19 | KkVX1zm8UnYNEokVn21sfkrqR4bhZy1yubD+w+LlWIuCp/gDrcrXBdk+yVin5WIA 20 | kULdL2BKj8OlZi3AHNx/oO0y6OcEAq4wMF5+QXUG1zSDTkXF+uwsNd6FVfPNDJXi 21 | qDOv1PCH8+BLlI69gkfInVY4lkMo2cZmP55HDbniUKe9xZ+bnmrvPw/LvoVtoKeC 22 | 6s5MEvIZ/SrgIJxc1e+qwOLyMhZqs322tJmkDpaI2IpbapsJ9dwGt/nRBZy7qmud 23 | P2BoEP17WF9opuM7zz86RZQBQgt95A3Egq/G85e4V/5yc+k1GeyNm+3VTojf6Ggr 24 | +4Emc3FlaVkwLklkMuwvAoIBAQD8TGOFJzrgAoTFYgnRXvR4Td3MPti4Pe9wIbS8 25 | ULDfgeswi2enGC80zrfY5gIyTkwZu2WdiBmONR7bx1F1x1eV/ttukMQaGIfpl/Kd 26 | 3xkXn8KGgwCWHC6iDDpaFhO0S56ZTgvsLVkLAIbSmz/VMDlV18KElxExQKKNib5k 27 | OEfH29cjR3dB5klududmUSaCR1p/66aMBIRJ8qz6giw7QIlIQGSjCWEh5JQJW+a4 28 | uyBKFpY7t1P7M7E9AWyC9PtpfiF7hDQ1N0pSBx5DHa6IE1zi1XER6zJRMZyH1PSj 29 | sN6qHC7r5tH5mdW5ySMmdx32+wLGr9M2Z10NAV39y6RfKHIXAoIBAQDaRZcuQznq 30 | DR2UMlrlQXP0HNjCZMic+zBB99c9Ps3YuIXt3JFlgC9ZThM0Sxjv47KoMgmrt5/S 31 | t4Oug4l/9zbSSpUuQWfoJIWc+7gJRI/jbmLqkyPGMRIGSNqE2BT3033RaAIaeBV9 32 | YdbddF2QO0UUUtme7s+0CjGNK+OgAzs5oYoB17fJH5E8ZxeBZ4lG7tV6ioLWNVov 33 | A/W2oB+MC0ghrJVbkTn4uR1IdpThEy5o08rxLakr0/EuzkdwN1Da8KL16GXv6dgu 34 | V8upTFQC/Va5E2fuAVpTCZHR4dMxM4uCaN60YoV5lgapMSiQaXxsCu6Zvi/HD4i2 35 | YPON7v0ZmjZLAoIBAAuqJHfFho1Q0H6nt7h8YWUmhHiq9y4dfvJ6PHbwbB0JTqxh 36 | 5ZruHVCdthZLHBLjV9VguqP75OKURib3IicF3mDK9a449zgVpkMAiXEPHYPgGQhL 37 | Cj3mc6l+UzxTBPoy/NQtrZNvzUwa7CDUmLDsl9oGLbIfoeXbDSjqE2liyL7OxTWW 38 | WkcrtH1s9enfGp6vWdnMNVkH5G3e0GyMlCrxIue6QmzfRCRjAw0juJkV3bpPLQb5 39 | xOI6U5l0dWXgmbcY48doJ1nGgqMkPRvxRV55NrQuFhoz+5GRb6FAEUd4J/NJdknl 40 | 1BNsL1t1lzByFWqT1F8HRgaf5MdzJrtTLPhRUGUCggEBAM+e8H5V/gnPLfqgp2t5 41 | BhYHNnw6p8UC/lVRrdCZI+7pHqQyca9N7jwRkxzj7jWJrpBlAGPxx7oFS+G9RxaN 42 | Df2caijUmETuMJYxrk5KhF/+yWJ+UcIdPRrzQ8CnVdKivwRo3c9VuINKhLqkDLe8 43 | WSpK4KxYVwPXymiRffTf/f8E1KSKEEzklR8SpP43gRIS7segZ3Hg0Ab2ykxMJZXt 44 | yVAWvP+btbwMQXmDKnyp5TRbeahOGaQR91Hhb3yjcWrBCRHGXOiH1FXIt3Yzn5o0 45 | ZsCnX+26JbPk32r4Vw5vDF4g6O5G5NXRykY393Deljajc3CUwxejhBSPRj0VPnWT 46 | Bd8CggEAPpt4YRNLcGRUAZ0Z/ToUjuu35y+nr76qocy1Q8VstKKEm+hf5hxkSRO2 47 | dVc+3dAsSKnQfV+pRL+q7ckboxALeleVVfCUq86vLFY3X0EtmqzBDUWc7xFEaJBG 48 | 7+BY/0IskTnqRNZfiDgad+b4LZHkttpx8kCFG532aKjZHO7R99wzHdlzlaJh48OO 49 | dKLuxuVUbfuVeH3Y3J36vYWtQwfkjBslx4wkucymLdwjUvmlqf3yzPgarRksKfnl 50 | VR+2yd2OK1pAbQFN3RwY6B17NZ159KS7zgYVq3tbAOaxILRpKHyHpFPiAytK9rCo 51 | W8cXgya12j6i34ag5Iq/G5OO2d5Hgw== 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC1pCsWdhn7+mCs 3 | /475fLrvAUm+yVaoT9wNcRsrB2C9SuHLWEhULAq3+oEGsJDtQZmXoKjx5TMt81hV 4 | 2+VywqxcDCaOvf/YmDYnV4+4xx2wSP1lud8Mu2RFtJvKoVZFOmoesGt4gD9f+FPq 5 | LwvNk/u6176hVI25q11GHyX7ZM502KO/blFlCO4UU2Hz6syBNPCrIsEypyhBHrbL 6 | +n7Jt9IeISQNl7wyMYkoZThYJegVkUzhOdtpPmJMX9jalX5Z5/nxe7uVTi9bABCx 7 | FuD+KepSG8w5QCjo6/SY4DD1UuaOmx/1TtFtiEUUNvIABwXQZWeH7TobA29pG6RG 8 | /msu9rtq3KQfv8w8q2fynlOobG2V9pIubQZD2Y/P60ZMpZuhR965BtanxnxWa4W4 9 | eZTN4OLFbuqHZQ/LQMU6CU1Iw6LYpXFdC9TM1N1tQE3piC3pAODu0E503NfhKGqq 10 | A0CYk1qlixSS6+rx0ZInH20hkiybJCfp/WocAvpDElQGw9etL3RJoKV6thYgKV6c 11 | tWH6jhRisQG1IxC3/0GneSvsWlW5zPTHFMx62RSDO1IbwUqHzd55Ihv3JFqrFCg/ 12 | hMmS2QEW9KBfadKsJVG/0jl3F0RXuBcl3oVM7BHcS+ATiCeRlE/6Hsy5r4b1KQz6 13 | i0QAw8ZBdk13d/ofTuM8Tf58CvCErwIDAQABAoICAE/GRUI9JlZbdYAlUTbTiAoW 14 | J7xKEuwi/sNMjKEOQXeBXr9/C20kVqTMuUQl4dDBweItJmXuwtaIjKBQzmnjg+19 15 | TKXeXnJTD12iADYoBSr6M4gs5QBjgLt4gf+xcgE/kYHe+6RVtv/AQaKVfPqR5rn9 16 | rPSP/RqxX2q/nV/WuzHoP6qAmfDkxiNZJ6kH0z9f799JiU5kybIn+iKF5o9TU032 17 | Qi5SGM52oQWDxwY3x8FJKlm0nl+PjX57jfMaOv7jeguLyyvcxcGSusH8CV63K/lZ 18 | ygzO1+jMUIWf2QC1oxq4mIWVUzdm5Ofm5cwLSYtoLdst3holHRYtlK21aX+bz112 19 | zNUdF/uiOC1coDYnDD+lwggvcy7UDMuRYCvMzN4ksn6wuqb2TTJza8iPYTR3R5NM 20 | I62BOIcD8Zc3ZIASoy/0RgE/d09zeEKw4x8lJtc4RWMj72Ei1noxTSbMO8wHg5NE 21 | q5+kqBDwgciq/wynPEsZrcMUtXDRnMtDhv3vEN5NEiZB/D/wa0aILx5BolDUivGj 22 | hUSCXB05xPy4hvxZdivNNwttqrpdYls37CrAzOO+ARquZc9k7VqxS4sB5VxjT8W9 23 | eycNmg2KdklYRr1PKuFqTNZj7VYKmr76+PdVIq7bBNH9jF7bknBVgSVWEGFjaNye 24 | Zejc62QaAjgqmEkJoe7ZAoIBAQDjzfVG04H1eVmAgxcP3yLcmyvZVufy5B14hu+i 25 | Jpjkq64ZZMx3Qj+rC6/L/GzIOxeh8+FccPO9zxrt+xBVpN5epYyB2dljLCUMn5yy 26 | 1HjEzIfexwVqwKLOBz/3oISx4AS2skHN9IWPl++sGFd1ibGGuWddMPNMuRUpndu7 27 | eAiL7e3LSv4r8gGLcWIKztDKS+XkSlcIFlvzf0sibVtnSqrkp+T+m6ifDMH8Dpro 28 | 0TaPtZt58IRRBwicGrkpwiz7EO9ip4McAyetbL6dVsw/B0zcz/gvAf8ZZmJ9e+XV 29 | JQhX0KxKAaqPWyfxjbIwGTl7pW+LqyHw+p8dGwMzGEFZPUfTAoIBAQDMH4RCcNaV 30 | RkDqQBNbITt38XXrsrfvfz0Y8hpTVFjo9iiq4wmPNb3pZYPp8a2E8x0mHliljGJo 31 | OqiHu/6JVtn8mgL9wlu4kEZC+v529wM33gvfntpcNKyLZp/HxoiYhh8UafaJYTNb 32 | WJBnGrIzrnsYvcJZIv16H/FqyT3up0zIcwUa/7s6e7fphWUjVZpJKWM1BMgr2n7b 33 | zxxL5Wq6L+5VajyqyucpmK30CJv0ib+3xUNf7Vn8i1wcTH4dnthEKnkVLe1Y6NjA 34 | 5jB5Uzes4LmW1dxpvaZbEDbqeHjjr/jMU8jwzDGk8vXEAu0b+g1lZ83Jj55WFkB0 35 | nB2Pw6k46wI1AoIBAQDOz0bygsgD+6PmiJwiO5fhoTnAuSYgGzoqFo5srg+14apP 36 | wXPifRFiDl0Nml+DtCnzTH32t1CArAmtrXUZ23BJio+xvv2dDBGikTDoJP5y46Ah 37 | /pqLXNEwq+JFw8NT3KVK2y/kcy3hu7TJjtuviE7TmXQeZXcr2wc8XeSDICjaKCnu 38 | mml/qdf/KPMyDqn8TcUqaNb0L6BQweqLGa6WanIU3duFzfjaU/G0C+pUnMKk2uGI 39 | ZXMqQHFvjs80+uRtFeXNsXfUsYSO7B9spcUNH2qHOIL+4hgejhWyCA4SX+lgF8Ch 40 | +ztFpCLyJ4pyIiROfVVz/ev1YwGaodBYzZdeFcUjAoIBAQCiRAOd1ZmfvONp1FoO 41 | vZJKvRZisgXqS5nENOGckJbFSrn1btpwj+ZSnbKJzOeFosXvQXxyzfCEruy+SkID 42 | 55kOZ1gtZc4IIBjasjCLXb2fMdL6h4tKdU0c3A30f+yiYyxdzAaCG1T6LqNMczpq 43 | Py/38RGITnp2FOKTYzrqdvBhAJ50YgryaNtAthw6RJiLxGzq/swpoF3sWu5BnzSC 44 | oguytutXUkkFFixirF1dvgs8CYKPxV0dl6M3k89FuLpvJdxva70cSq3UWqj6KZ8+ 45 | vL6MG6JGJM8T4QXmyrI/Pepoc8pvMcPdPo8ErNbUwKjZjfVXX+YcxT+j817EpGPn 46 | rVppAoIBAASyawrxBTul1RmEyXCMjXJL3lGdhjvbYlLfeJEO5Znu7YFfX+KKZp1n 47 | Rxw3LUjXJUOUfHWuIkPOrHYsPOkja9Vew08I4QDagSqAfB13WQ356XAiUoEOitdC 48 | OWvznnwmzWwwNUHm6crFCXnRYuqgQbW+/oj+OSt0CTerU2VefcTAgkUCdrz06AhG 49 | IRyrVCLuVi4j7yr3kYfq19/leWPWekR18vldDE/TG/N7X4KS51MI4FiVi74ByQCj 50 | Md/fkV7PLPh8vOCxWsUQ6L7MTYWzrOAOYTn8nGRambaIiDGC/IsDtI4GRuMEldGY 51 | IW4Wy2xIPf0/fQSqFWTIQxVUJr1Owfs= 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeoptions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebsockethandshakeoptions_p.h" 6 | 7 | QT_BEGIN_NAMESPACE 8 | 9 | /*! 10 | \class QWebSocketHandshakeOptions 11 | 12 | \inmodule QtWebSockets 13 | \since 6.4 14 | \brief Collects options for the WebSocket handshake. 15 | 16 | QWebSocketHandshakeOptions collects options that are passed along to the 17 | WebSocket handshake, such as WebSocket subprotocols and WebSocket 18 | Extensions. 19 | 20 | At the moment, only WebSocket subprotocols are supported. 21 | 22 | \sa QWebSocket::open() 23 | */ 24 | 25 | /*! 26 | \brief Constructs an empty QWebSocketHandshakeOptions object. 27 | */ 28 | QWebSocketHandshakeOptions::QWebSocketHandshakeOptions() 29 | : d(new QWebSocketHandshakeOptionsPrivate) 30 | { 31 | } 32 | 33 | /*! 34 | \brief Constructs a QWebSocketHandshakeOptions that is a copy of \a other. 35 | */ 36 | QWebSocketHandshakeOptions::QWebSocketHandshakeOptions(const QWebSocketHandshakeOptions &other) 37 | : d(other.d) 38 | { 39 | } 40 | 41 | /*! 42 | \fn QWebSocketHandshakeOptions::QWebSocketHandshakeOptions(QWebSocketHandshakeOptions &&other) noexcept 43 | \brief Constructs a QWebSocketHandshakeOptions that is moved from \a other. 44 | */ 45 | 46 | /*! 47 | \brief Destroys this object. 48 | */ 49 | QWebSocketHandshakeOptions::~QWebSocketHandshakeOptions() 50 | { 51 | } 52 | 53 | /*! 54 | \fn QWebSocketHandshakeOptions &QWebSocketHandshakeOptions::operator=(QWebSocketHandshakeOptions &&other) noexcept 55 | \brief Moves \a other to this object. 56 | */ 57 | 58 | /*! 59 | \brief Assigns \a other to this object. 60 | */ 61 | QWebSocketHandshakeOptions &QWebSocketHandshakeOptions::operator=( 62 | const QWebSocketHandshakeOptions &other) 63 | { 64 | d = other.d; 65 | return *this; 66 | } 67 | 68 | /*! 69 | \fn void swap(QWebSocketHandshakeOptions &other) noexcept 70 | \brief Swaps this object with \a other. 71 | */ 72 | 73 | /*! 74 | \brief Returns the list of WebSocket subprotocols to send along with the 75 | websocket handshake. 76 | */ 77 | QStringList QWebSocketHandshakeOptions::subprotocols() const 78 | { 79 | return d->subprotocols; 80 | } 81 | 82 | /*! 83 | \brief Sets the list of WebSocket subprotocols \a protocols to send along 84 | with the websocket handshake. 85 | 86 | WebSocket subprotocol names may only consist of those US-ASCII characters 87 | that are in the unreserved group. Invalid protocol names will not be 88 | included in the handshake. 89 | */ 90 | void QWebSocketHandshakeOptions::setSubprotocols(const QStringList &protocols) 91 | { 92 | d->subprotocols = protocols; 93 | } 94 | 95 | bool QWebSocketHandshakeOptions::equals(const QWebSocketHandshakeOptions &other) const 96 | { 97 | return *d == *other.d; 98 | } 99 | 100 | /*! 101 | //! friend 102 | \fn QWebSocketHandshakeOptions::operator==(const QWebSocketHandshakeOptions &lhs, const QWebSocketHandshakeOptions &rhs) 103 | \fn QWebSocketHandshakeOptions::operator!=(const QWebSocketHandshakeOptions &lhs, const QWebSocketHandshakeOptions &rhs) 104 | \brief Compares \a lhs for equality with \a rhs. 105 | */ 106 | 107 | QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QWebSocketHandshakeOptionsPrivate) 108 | 109 | QT_END_NAMESPACE 110 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/qqmlwebsocket.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QQMLWEBSOCKET_H 6 | #define QQMLWEBSOCKET_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | QT_BEGIN_NAMESPACE 15 | 16 | class QQmlWebSocket : public QObject, public QQmlParserStatus 17 | { 18 | Q_OBJECT 19 | Q_DISABLE_COPY(QQmlWebSocket) 20 | Q_INTERFACES(QQmlParserStatus) 21 | 22 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) 23 | Q_PROPERTY(QStringList requestedSubprotocols READ requestedSubprotocols 24 | WRITE setRequestedSubprotocols NOTIFY requestedSubprotocolsChanged) 25 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) 26 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) 27 | Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) 28 | Q_PROPERTY(QString negotiatedSubprotocol READ negotiatedSubprotocol NOTIFY 29 | negotiatedSubprotocolChanged) 30 | 31 | QML_NAMED_ELEMENT(WebSocket) 32 | QML_ADDED_IN_VERSION(1, 0) 33 | 34 | public: 35 | explicit QQmlWebSocket(QObject *parent = 0); 36 | explicit QQmlWebSocket(QWebSocket *socket, QObject *parent = 0); 37 | ~QQmlWebSocket() override; 38 | 39 | enum Status 40 | { 41 | Connecting = 0, 42 | Open = 1, 43 | Closing = 2, 44 | Closed = 3, 45 | Error = 4 46 | }; 47 | Q_ENUM(Status) 48 | 49 | QUrl url() const; 50 | void setUrl(const QUrl &url); 51 | QStringList requestedSubprotocols() const; 52 | void setRequestedSubprotocols(const QStringList &subprotocols); 53 | 54 | QString negotiatedSubprotocol() const; 55 | Status status() const; 56 | QString errorString() const; 57 | 58 | void setActive(bool active); 59 | bool isActive() const; 60 | 61 | Q_INVOKABLE qint64 sendTextMessage(const QString &message); 62 | Q_REVISION(1) Q_INVOKABLE qint64 sendBinaryMessage(const QByteArray &message); 63 | Q_REVISION(6, 10) Q_INVOKABLE void ping(); 64 | Q_REVISION(6, 10) Q_INVOKABLE void ping(const QByteArray &payload); 65 | 66 | Q_SIGNALS: 67 | void textMessageReceived(QString message); 68 | Q_REVISION(1) void binaryMessageReceived(QByteArray message); 69 | void statusChanged(QQmlWebSocket::Status status); 70 | void activeChanged(bool isActive); 71 | void errorStringChanged(QString errorString); 72 | void urlChanged(); 73 | void requestedSubprotocolsChanged(); 74 | void negotiatedSubprotocolChanged(); 75 | Q_REVISION(6, 10) void pong(quint64 elapsedTime, const QByteArray &payload); 76 | 77 | public: 78 | void classBegin() override; 79 | void componentComplete() override; 80 | 81 | private Q_SLOTS: 82 | void onError(QAbstractSocket::SocketError error); 83 | void onStateChanged(QAbstractSocket::SocketState state); 84 | 85 | private: 86 | QScopedPointer m_webSocket; 87 | QString m_negotiatedProtocol; 88 | Status m_status; 89 | QUrl m_url; 90 | QStringList m_requestedProtocols; 91 | bool m_isActive; 92 | bool m_componentCompleted; 93 | QString m_errorString; 94 | 95 | // takes ownership of the socket 96 | void setSocket(QWebSocket *socket); 97 | void setStatus(Status status); 98 | void open(); 99 | void close(); 100 | void setErrorString(QString errorString = QString()); 101 | }; 102 | 103 | QT_END_NAMESPACE 104 | 105 | #endif // QQMLWEBSOCKET_H 106 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "sslechoserver.h" 4 | #include "QtWebSockets/QWebSocketServer" 5 | #include "QtWebSockets/QWebSocket" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | QT_USE_NAMESPACE 12 | 13 | //! [constructor] 14 | SslEchoServer::SslEchoServer(quint16 port, QObject *parent) : 15 | QObject(parent), 16 | m_pWebSocketServer(nullptr) 17 | { 18 | m_pWebSocketServer = new QWebSocketServer(QStringLiteral("SSL Echo Server"), 19 | QWebSocketServer::SecureMode, 20 | this); 21 | QSslConfiguration sslConfiguration; 22 | QFile certFile(QStringLiteral(":/localhost.cert")); 23 | QFile keyFile(QStringLiteral(":/localhost.key")); 24 | certFile.open(QIODevice::ReadOnly); 25 | keyFile.open(QIODevice::ReadOnly); 26 | QSslCertificate certificate(&certFile, QSsl::Pem); 27 | QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem); 28 | certFile.close(); 29 | keyFile.close(); 30 | sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone); 31 | sslConfiguration.setLocalCertificate(certificate); 32 | sslConfiguration.setPrivateKey(sslKey); 33 | m_pWebSocketServer->setSslConfiguration(sslConfiguration); 34 | 35 | if (m_pWebSocketServer->listen(QHostAddress::Any, port)) 36 | { 37 | qDebug() << "SSL Echo Server listening on port" << port; 38 | connect(m_pWebSocketServer, &QWebSocketServer::newConnection, 39 | this, &SslEchoServer::onNewConnection); 40 | connect(m_pWebSocketServer, &QWebSocketServer::sslErrors, 41 | this, &SslEchoServer::onSslErrors); 42 | } 43 | } 44 | //! [constructor] 45 | 46 | SslEchoServer::~SslEchoServer() 47 | { 48 | m_pWebSocketServer->close(); 49 | qDeleteAll(m_clients.begin(), m_clients.end()); 50 | } 51 | 52 | //! [onNewConnection] 53 | void SslEchoServer::onNewConnection() 54 | { 55 | QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); 56 | 57 | qDebug() << "Client connected:" << pSocket->peerName() << pSocket->origin(); 58 | 59 | connect(pSocket, &QWebSocket::textMessageReceived, this, &SslEchoServer::processTextMessage); 60 | connect(pSocket, &QWebSocket::binaryMessageReceived, 61 | this, &SslEchoServer::processBinaryMessage); 62 | connect(pSocket, &QWebSocket::disconnected, this, &SslEchoServer::socketDisconnected); 63 | 64 | m_clients << pSocket; 65 | } 66 | //! [onNewConnection] 67 | 68 | //! [processTextMessage] 69 | void SslEchoServer::processTextMessage(QString message) 70 | { 71 | QWebSocket *pClient = qobject_cast(sender()); 72 | if (pClient) 73 | { 74 | pClient->sendTextMessage(message); 75 | } 76 | } 77 | //! [processTextMessage] 78 | 79 | //! [processBinaryMessage] 80 | void SslEchoServer::processBinaryMessage(QByteArray message) 81 | { 82 | QWebSocket *pClient = qobject_cast(sender()); 83 | if (pClient) 84 | { 85 | pClient->sendBinaryMessage(message); 86 | } 87 | } 88 | //! [processBinaryMessage] 89 | 90 | //! [socketDisconnected] 91 | void SslEchoServer::socketDisconnected() 92 | { 93 | qDebug() << "Client disconnected"; 94 | QWebSocket *pClient = qobject_cast(sender()); 95 | if (pClient) 96 | { 97 | m_clients.removeAll(pClient); 98 | pClient->deleteLater(); 99 | } 100 | } 101 | 102 | void SslEchoServer::onSslErrors(const QList &) 103 | { 104 | qDebug() << "Ssl errors occurred"; 105 | } 106 | //! [socketDisconnected] 107 | -------------------------------------------------------------------------------- /src/websockets/doc/qtwebsockets.qdocconf: -------------------------------------------------------------------------------- 1 | include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) 2 | include($QT_INSTALL_DOCS/config/exampleurl-qtwebsockets.qdocconf) 3 | 4 | project = QtWebSockets 5 | description = Qt WebSockets Reference Documentation 6 | version = $QT_VERSION 7 | 8 | examplesinstallpath = websockets 9 | 10 | # Path to the root of qtwebsockets (for automatic linking to source code) 11 | url.sources.rootdir = ../../.. 12 | 13 | qhp.projects = QtWebSockets 14 | 15 | qhp.QtWebSockets.file = qtwebsockets.qhp 16 | qhp.QtWebSockets.namespace = org.qt-project.qtwebsockets.$QT_VERSION_TAG 17 | qhp.QtWebSockets.virtualFolder = qtwebsockets 18 | qhp.QtWebSockets.indexTitle = Qt WebSockets 19 | qhp.QtWebSockets.indexRoot = 20 | 21 | qhp.QtWebSockets.subprojects = manual examples classes qml 22 | 23 | qhp.QtWebSockets.subprojects.classes.title = C++ Classes 24 | qhp.QtWebSockets.subprojects.classes.indexTitle = Qt WebSockets C++ Classes 25 | qhp.QtWebSockets.subprojects.classes.selectors = class headerfile 26 | qhp.QtWebSockets.subprojects.classes.sortPages = true 27 | 28 | qhp.QtWebSockets.subprojects.qml.title = QML Types 29 | qhp.QtWebSockets.subprojects.qml.indexTitle = Qt WebSockets QML Types 30 | qhp.QtWebSockets.subprojects.qml.selectors = qmltype 31 | qhp.QtWebSockets.subprojects.qml.sortPages = true 32 | 33 | qhp.QtWebSockets.subprojects.examples.title = Examples 34 | qhp.QtWebSockets.subprojects.examples.indexTitle = Qt WebSockets Examples 35 | qhp.QtWebSockets.subprojects.examples.selectors = example 36 | qhp.QtWebSockets.subprojects.examples.sortPages = true 37 | 38 | qhp.QtWebSockets.subprojects.manual.title = Qt WebSockets 39 | qhp.QtWebSockets.subprojects.manual.indexTitle = Qt WebSockets module topics 40 | qhp.QtWebSockets.subprojects.manual.type = manual 41 | 42 | tagfile = ../../../doc/qtwebsockets/qtwebsockets.tags 43 | 44 | depends += qtcore qtnetwork qtdoc qmake qtcmake 45 | 46 | headerdirs += .. \ 47 | ../../imports 48 | 49 | sourcedirs += .. \ 50 | src \ 51 | ../../imports \ 52 | ../../../tests/doc 53 | 54 | 55 | exampledirs += ../../../examples/websockets \ 56 | snippets 57 | 58 | examples.fileextensions += "*.html" 59 | 60 | imagedirs += ../../../examples/websockets/doc/images \ 61 | images 62 | 63 | #add generic thumbnail images for example documentation that does not have an image. 64 | manifestmeta.thumbnail.names += "QtWebSockets/Echo Client*" \ 65 | "QtWebSockets/QML*" \ 66 | "QtWebSockets/SSL*" \ 67 | "QtWebSockets/Simple*" 68 | 69 | manifestmeta.highlighted.names = "QtWebSockets/Simple WebSocket Chat" 70 | 71 | navigation.landingpage = "Qt WebSockets" 72 | navigation.cppclassespage = "Qt WebSockets C++ Classes" 73 | navigation.qmltypespage = "Qt WebSockets QML Types" 74 | # Auto-generate navigation linking based on "Qt WebSockets module topics": 75 | navigation.toctitles = "Qt WebSockets module topics" 76 | navigation.toctitles.inclusive = false 77 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketserver_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBSOCKETSERVER_P_H 6 | #define QWEBSOCKETSERVER_P_H 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "qwebsocketserver.h" 24 | #include "qwebsocket.h" 25 | 26 | #ifndef QT_NO_SSL 27 | #include 28 | #include 29 | #endif 30 | 31 | QT_BEGIN_NAMESPACE 32 | 33 | class QTcpServer; 34 | class QTcpSocket; 35 | 36 | class QWebSocketServerPrivate : public QObjectPrivate 37 | { 38 | Q_DISABLE_COPY(QWebSocketServerPrivate) 39 | 40 | public: 41 | Q_DECLARE_PUBLIC(QWebSocketServer) 42 | enum SslMode 43 | { 44 | SecureMode = true, 45 | NonSecureMode 46 | }; 47 | 48 | explicit QWebSocketServerPrivate(const QString &serverName, SslMode secureMode); 49 | ~QWebSocketServerPrivate() override; 50 | 51 | void init(); 52 | void close(bool aboutToDestroy = false); 53 | QString errorString() const; 54 | bool hasPendingConnections() const; 55 | bool isListening() const; 56 | bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0); 57 | int maxPendingConnections() const; 58 | int handshakeTimeout() const { 59 | return m_handshakeTimeout; 60 | } 61 | virtual QWebSocket *nextPendingConnection(); 62 | void pauseAccepting(); 63 | #ifndef QT_NO_NETWORKPROXY 64 | QNetworkProxy proxy() const; 65 | void setProxy(const QNetworkProxy &networkProxy); 66 | #endif 67 | void resumeAccepting(); 68 | QHostAddress serverAddress() const; 69 | QWebSocketProtocol::CloseCode serverError() const; 70 | quint16 serverPort() const; 71 | void setMaxPendingConnections(int numConnections); 72 | void setHandshakeTimeout(int msec); 73 | bool setSocketDescriptor(qintptr socketDescriptor); 74 | qintptr socketDescriptor() const; 75 | 76 | QList supportedVersions() const; 77 | void setSupportedSubprotocols(const QStringList &protocols); 78 | QStringList supportedSubprotocols() const; 79 | QStringList supportedExtensions() const; 80 | 81 | void setServerName(const QString &serverName); 82 | QString serverName() const; 83 | 84 | SslMode secureMode() const; 85 | 86 | #ifndef QT_NO_SSL 87 | void setSslConfiguration(const QSslConfiguration &sslConfiguration); 88 | QSslConfiguration sslConfiguration() const; 89 | #endif 90 | 91 | void setError(QWebSocketProtocol::CloseCode code, const QString &errorString); 92 | 93 | void handleConnection(QTcpSocket *pTcpSocket) const; 94 | 95 | private slots: 96 | void startHandshakeTimeout(QTcpSocket *pTcpSocket); 97 | 98 | private: 99 | QTcpServer *m_pTcpServer; 100 | QString m_serverName; 101 | SslMode m_secureMode; 102 | QStringList m_supportedSubprotocols; 103 | QQueue m_pendingConnections; 104 | QWebSocketProtocol::CloseCode m_error; 105 | QString m_errorString; 106 | int m_maxPendingConnections; 107 | int m_handshakeTimeout; 108 | 109 | void addPendingConnection(QWebSocket *pWebSocket); 110 | void setErrorFromSocketError(QAbstractSocket::SocketError error, 111 | const QString &errorDescription); 112 | 113 | void onNewConnection(); 114 | void onSocketDisconnected(); 115 | void handshakeReceived(); 116 | void finishHandshakeTimeout(QTcpSocket *pTcpSocket); 117 | }; 118 | 119 | QT_END_NAMESPACE 120 | 121 | #endif // QWEBSOCKETSERVER_P_H 122 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoclient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | WebSocket Echo Client 4 | 5 | 6 |

WebSocket Echo Client

7 |

8 | 9 | 10 | 11 |

12 |

13 | 14 |

15 |

16 | 17 | 18 |

19 | 20 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoclient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WebSocket Echo Client 5 | 6 | 7 | 8 |

WebSocket Echo Client

9 |

10 | 11 | 12 | 13 |

14 |

15 | 16 |

17 |

18 | 19 | 20 |

21 | 22 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/websockets/doc/src/overview.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page websockets-overview.html 6 | \title Qt WebSockets Overview 7 | \brief Provides insight into the WebSocket protocol and the Qt WebSockets module. 8 | \ingroup explanations-webtechnologies 9 | 10 | Qt WebSockets enables you to build WebSocket-aware applications. It 11 | provides an implementation for the WebSocket protocol, which is offered by IETF 12 | (Internet Engineering Task Force) as a better alternative for bidirectional 13 | communication using the existing web infrastructure. 14 | 15 | Historically, web applications that needed bidirectional communication or 16 | push notifications had to use one of the HTTP-based solutions available. These 17 | solutions employed different techniques such as polling, long-polling, and 18 | streaming, to overcome the limitations of HTTP protocol, which is not designed 19 | for such use cases. This resulted in high network latency, unnecessary data 20 | exchange, and stale or old data. The WebSocket offering by IETF helps to 21 | overcome these problems to a large extent. 22 | 23 | \section1 How does it Work? 24 | 25 | \image websockets-pictorial-representation.jpg WebSocket protocal flow diagram 26 | 27 | As you can see in the pictorial representation, WebSocket-based solution 28 | consists of a client-side and server-side. The native client-side support for 29 | WebSocket is available on most of the popular web browsers such as Google 30 | Chrome, Internet Explorer, Safari, and so on. The server-side support for 31 | WebSocket makes it a complete solution, enabling bidirectional communication. 32 | Any browser with native WebSocket support should let you run a simple HTML and 33 | JavaScript-based client application using the HTML5 WebSocket API. 34 | 35 | A WebSocket connection begins with a initial HTTP-compatible handshake, 36 | which ensures backwards compatibility so that the WebSocket connections can 37 | share the default HTTP (80) and HTTPS (443) ports. On successful handshake, 38 | the connection is open for data exchange, until one of the two entities end 39 | the connection. 40 | 41 | The WebSocket protocol uses \c ws: and \c wss: URL schemes to represent 42 | unsecure and secure WebSocket requests, respectively. During the initial 43 | handshake, if a proxy server is detected, the protocol tries to set up a tunnel 44 | by issuing an \c{HTTP CONNECT} statement to the proxy. The tunnel approach to 45 | handle proxies is used irrespective of the request type, although it is proved 46 | to work better with TLS (Transport Layer Security) in secure connections. 47 | 48 | \section1 Typical Use Cases 49 | 50 | WebSocket suits best for scenarios where, 51 | \list 52 | \li data presented must be up-to-date, 53 | \li low network latency and minimal data exchange is crucial. 54 | \endlist 55 | 56 | A few example applications where we struggle to achieve these using the 57 | traditional approach are, instant messaging, online gaming, online stock 58 | trading, and so on. 59 | 60 | \section1 Role of Qt WebSockets 61 | 62 | The Qt WebSockets module provides APIs to develop WebSocket-based server and 63 | client applications. An example of where these APIs can be used is a server 64 | application that provides stock data, and a client application that registers 65 | for push notification when there is a change in price of a few stocks. 66 | 67 | The module provides both C++ and QML versions of the API, so you can choose 68 | the alternative that suits your need. 69 | 70 | \section2 Qt WebSockets with Cloud Services 71 | 72 | The client application usually depends on an external service for data. Most of 73 | these service providers do not support WebSocket yet, so you end up developing 74 | a WebSocket-aware server application to bridge the gap. You can run the server 75 | on an enterprise WebSocket gateway service such as a cloud service, avoiding 76 | the hassle of maintaining the necessary infrastructure required to host such 77 | a service. 78 | 79 | Most of the cloud Services provide a Platform as a service (PaaS) backend, 80 | which enables deploying and running an instance of your server application on 81 | the cloud. The client applications can connect to the running server using a 82 | WebSocket URL and receive data. 83 | 84 | \section2 Related Information 85 | \list 86 | \li \l{RFC 6455} 87 | \endlist 88 | */ 89 | --------------------------------------------------------------------------------